-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.bas
422 lines (357 loc) · 15.3 KB
/
main.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
Attribute VB_Name = "mMain"
Option Explicit
Public glbConnection As New ADODB.Connection
Public glbRecordset As New ADODB.Recordset
Public glbSQL As String
Public gbInicio As Boolean
Public glbCambio As Boolean
Public glbPaginaInicio As String
Private gsBlackKeywords As String
Private gsBlueKeyWords As String
Public glbLinea As String
Public Type eLibreria
Id As Integer
Descripcion As String
End Type
Public Arr_Categorias() As eLibreria
Public Function LoadAttach(RSfield As DAO.Field, FileName As String) As Boolean
'=======================================================================
' This will load a file into an OLE data field within an open recordset
' Required Variables:
' -RSfield: actual field to store data to, not the field name but the field itself
' -FileName: full path & name of the file to load
'=======================================================================
Dim ChunkSize As Long
Dim FileNum As Integer
Dim Buffer() As Byte
Dim BytesNeeded As Long
Dim Buffers As Long
Dim Remainder As Long
Dim i As Long
' Inserted by LaVolpe
On Error GoTo Function_LoadAttach_General_ErrTrap_by_LaVolpe
If Dir(FileName) = "" Then ' ensure the file can be found
MsgBox "Failed to load attachment. File not found", vbExclamation + vbOKOnly
Exit Function
End If
On Error GoTo LoadError
ChunkSize = 65536 ' size of file to read/write at a time (lower if needed)
FileNum = FreeFile
Open FileName For Binary As #FileNum
BytesNeeded = LOF(FileNum)
Buffers = BytesNeeded \ ChunkSize
Remainder = BytesNeeded Mod ChunkSize
For i = 0 To Buffers - 1
ReDim Buffer(ChunkSize)
Get #FileNum, , Buffer
RSfield.AppendChunk Buffer
Next
ReDim Buffer(Remainder)
Get #FileNum, , Buffer
RSfield.AppendChunk Buffer
LoadAttach = True
ReleaseFile:
On Error Resume Next
Close #FileNum
Exit Function
LoadError:
MsgBox "Following error prevent requested action." & vbCrLf & Err.Description, vbExclamation + vbOKOnly
Resume ReleaseFile
Exit Function
Function_LoadAttach_General_ErrTrap_by_LaVolpe: ' Inserted by Lavolpe
If MsgBox("Error " & Err.Number & " - Procedure [Function LoadAttach]" & vbCrLf & Err.Description, vbExclamation + vbRetryCancel) = vbRetry Then Resume
End Function
'abrir base de datos
Public Function AbrirBaseDatos() As Boolean
On Local Error GoTo ErrorAbrirBaseDatos
Dim ret As Boolean
Dim Conexion As String
ret = True
Conexion = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Persist Security Info=False;Data Source=" & App.Path & "\plibrary.mdb"
glbConnection.Open Conexion
GoTo SalirAbrirBaseDatos
ErrorAbrirBaseDatos:
ret = False
MsgBox "AbrirBaseDatos : " & Err & " " & Error$, vbCritical
Resume SalirAbrirBaseDatos
SalirAbrirBaseDatos:
AbrirBaseDatos = ret
Err = 0
End Function
'cargar las secciones definidas en archivo
Public Function CargarLibreria() As Boolean
On Local Error GoTo ErrorCargarSecciones
Dim ret As Boolean
Dim k As Integer
Dim i As Integer
Dim c As Integer
ret = True
'cargar categorias
glbSQL = "SELECT id, descripcion FROM categorias order by id asc"
glbRecordset.Open glbSQL, glbConnection, adOpenForwardOnly, adLockReadOnly, adCmdText
ReDim Arr_Categorias(0)
'espera
Call Wait("Cargando libreria. Espere ...", 1, 14)
k = 1
With glbRecordset
Do While Not .EOF
ReDim Preserve Arr_Categorias(k)
Arr_Categorias(k).Id = !Id
Arr_Categorias(k).Descripcion = Trim$(!Descripcion)
FRMWait.lblGlosa.Caption = Arr_Categorias(k).Descripcion
FRMWait.pgb.Value = k
frmMain.lvwCat.ListItems.Add , "k" & Arr_Categorias(k).Id, Arr_Categorias(k).Descripcion, k, k
CreaDirectorio App.Path & "\" & Arr_Categorias(k).Descripcion
k = k + 1
.MoveNext
Loop
.Close
End With
GoTo SalirCargarSecciones
ErrorCargarSecciones:
ret = False
MsgBox "CargarLibreria : " & Err & " " & Error$, vbCritical
Resume SalirCargarSecciones
SalirCargarSecciones:
Unload FRMWait
CargarLibreria = ret
Err = 0
End Function
'muestra/oculta progress bar principal
Public Sub ShowProgress(ByVal Mode As Boolean)
frmMain.stbMain.Panels(3).Visible = Mode
If Mode Then
With frmMain.pgbStatus
.Left = frmMain.stbMain.Panels(3).Left
.Top = frmMain.stbMain.Top + 2
.Width = frmMain.stbMain.Panels(3).Width
.Height = frmMain.stbMain.Height - 2
.Visible = True
.Max = 100
.Value = 1
.ZOrder 0
End With
Else
frmMain.pgbStatus.Visible = False
End If
End Sub
Public Sub InitColorize()
' **********************************************************************
' * Comments : Initialize the VB keywords
' *
' *
' **********************************************************************
gsBlackKeywords = "*Abs*Add*AddItem*AppActivate*Array*Asc*Atn*Beep*Begin*BeginProperty*ChDir*ChDrive*Choose*Chr*Clear*Collection*Command*Cos*CreateObject*CurDir*DateAdd*DateDiff*DatePart*DateSerial*DateValue*Day*DDB*DeleteSetting*Dir*DoEvents*EndProperty*Environ*EOF*Err*Exp*FileAttr*FileCopy*FileDateTime*FileLen*Fix*Format*FV*GetAllSettings*GetAttr*GetObject*GetSetting*Hex*Hide*Hour*InputBox*InStr*Int*Int*IPmt*IRR*IsArray*IsDate*IsEmpty*IsError*IsMissing*IsNull*IsNumeric*IsObject*Item*Kill*LCase*Left*Len*Load*Loc*LOF*Log*LTrim*Me*Mid*Minute*MIRR*MkDir*Month*Now*NPer*NPV*Oct*Pmt*PPmt*PV*QBColor*Raise*Randomize*Rate*Remove*RemoveItem*Reset*RGB*Right*RmDir*Rnd*RTrim*SaveSetting*Second*SendKeys*SetAttr*Sgn*Shell*Sin*Sin*SLN*Space*Sqr*Str*StrComp*StrConv*Switch*SYD*Tan*Text*Time*Time*Timer*TimeSerial*TimeValue*Trim*TypeName*UCase*Unload*Val*VarType*WeekDay*Width*Year*"
gsBlueKeyWords = "*#Const*#Else*#ElseIf*#End If*#If*Alias*Alias*And*As*Base*Binary*Boolean*Byte*ByVal*Call*Case*CBool*CByte*CCur*CDate*CDbl*CDec*CInt*CLng*Close*Compare*Const*CSng*CStr*Currency*CVar*CVErr*Decimal*Declare*DefBool*DefByte*DefCur*DefDate*DefDbl*DefDec*DefInt*DefLng*DefObj*DefSng*DefStr*DefVar*Dim*Do*Double*Each*Else*ElseIf*End*Enum*Eqv*Erase*Error*Exit*Explicit*False*For*Function*Get*Global*GoSub*GoTo*If*Imp*In*Input*Input*Integer*Is*LBound*Let*Lib*Like*Line*Lock*Long*Loop*LSet*Name*New*Next*Not*Object*On*Open*Option*Or*Output*Print*Private*Property*Public*Put*Random*Read*ReDim*Resume*Return*RSet*Seek*Select*Set*Single*Spc*Static*String*Stop*Sub*Tab*Then*Then*True*Type*UBound*Unlock*Variant*Wend*While*With*Xor*Nothing*To*Friend*"
End Sub
Public Sub ColorizeVB2(RTF As RichTextBox)
' #VBIDEUtils#************************************************************
' * Programmer Name : Waty Thierry
' * Web Site : http://www.vbdiamond.com
' * E-Mail :
' * Date : 30/10/98
' * Time : 14:47
' * Module Name : Colorize_Module
' * Module Filename : Colorize.bas
' * Procedure Name : ColorizeVB
' * Parameters :
' * rtf As RichTextBox
' **********************************************************************
' * Comments : Colorize in black, blue, green the VB keywords
' *
' *
' **********************************************************************
On Local Error Resume Next
Dim sBuffer As String
Dim nI As Long
Dim nJ As Long
Dim sTmpWord As String
Dim nStartPos As Long
Dim nSelLen As Long
Dim nWordPos As Long
If Not glbColorizarCodigo Then
Exit Sub
End If
sBuffer = RTF.Text
sTmpWord = ""
With RTF
.Visible = False
For nI = 1 To Len(sBuffer)
'DoEvents
Select Case Mid$(sBuffer, nI, 1)
Case "A" To "Z", "a" To "z" ', "_"
If sTmpWord = "" Then nStartPos = nI
sTmpWord = sTmpWord & Mid$(sBuffer, nI, 1)
Case Chr$(34)
nSelLen = 1
For nJ = 1 To 9999999
If Mid$(sBuffer, nI + 1, 1) = Chr$(34) Then
nI = nI + 2
Exit For
Else
nSelLen = nSelLen + 1
nI = nI + 1
End If
Next
Case Chr$(39)
.SelStart = nI - 1
nSelLen = 0
For nJ = 1 To 9999999
'Do
If Mid$(sBuffer, nI, 2) = "" Then
Exit For
ElseIf Mid$(sBuffer, nJ, 2) = vbCrLf Then
Exit For
'ElseIf Mid$(sBuffer, nJ, 2) = vbNewLine Then
' Exit For
' Exit Do
Else
nSelLen = nSelLen + 1
nI = nI + 1
End If
'Loop
Next nJ
.SelLength = nSelLen
.SelColor = RGB(0, 127, 0)
Case Else
If Not (Len(sTmpWord) = 0) Then
.SelStart = nStartPos - 1
.SelLength = Len(sTmpWord)
nWordPos = InStr(1, gsBlackKeywords, "*" & sTmpWord & "*", 1)
If nWordPos <> 0 Then
.SelColor = RGB(0, 0, 0)
.SelText = Mid$(gsBlackKeywords, nWordPos + 1, Len(sTmpWord))
End If
nWordPos = InStr(1, gsBlueKeyWords, "*" & sTmpWord & "*", 1)
If nWordPos <> 0 Then
.SelColor = RGB(0, 0, 127)
.SelText = Mid$(gsBlueKeyWords, nWordPos + 1, Len(sTmpWord))
End If
If nWordPos = 0 Then
.SelColor = RGB(0, 0, 0)
End If
If UCase$(sTmpWord) = "REM" Then
.SelStart = nI - 4
.SelLength = 3
For nJ = 1 To 9999999
If Mid$(sBuffer, nI, 2) = vbCrLf Then
Exit For
Else
.SelLength = .SelLength + 1
nI = nI + 1
End If
Next
.SelColor = RGB(0, 127, 0)
.SelText = LCase$(.SelText)
End If
End If
sTmpWord = ""
End Select
Next
.SelStart = 0
.Visible = True
.SetFocus
End With
Err = 0
End Sub
Public Sub ColorizeVB(RTF As RichTextBox)
' #VBIDEUtils#************************************************************
' * Programmer Name : Waty Thierry
' * Web Site : http://www.vbdiamond.com
' * E-Mail :
' * Date : 30/10/98
' * Time : 14:47
' * Module Name : Colorize_Module
' * Module Filename : Colorize.bas
' * Procedure Name : ColorizeVB
' * Parameters :
' * rtf As RichTextBox
' **********************************************************************
' * Comments : Colorize in black, blue, green the VB keywords
' *
' *
' **********************************************************************
Dim sBuffer As String
Dim nI As Long
Dim nJ As Long
Dim sTmpWord As String
Dim nStartPos As Long
Dim nSelLen As Long
Dim nWordPos As Long
sBuffer = RTF.Text
sTmpWord = ""
With RTF
For nI = 1 To Len(sBuffer)
Select Case Mid$(sBuffer, nI, 1)
Case "A" To "Z", "a" To "z", "_"
If sTmpWord = "" Then nStartPos = nI
sTmpWord = sTmpWord & Mid$(sBuffer, nI, 1)
Case Chr$(34)
nSelLen = 1
For nJ = 1 To 10000 '9999999
If Mid$(sBuffer, nI + 1, 1) = Chr$(34) Then
nI = nI + 2
Exit For
Else
nSelLen = nSelLen + 1
nI = nI + 1
End If
Next
Case Chr$(39)
.SelStart = nI - 1
nSelLen = 0
For nJ = 1 To 10000
If Mid$(sBuffer, nI, 2) = vbCrLf Then
Exit For
Else
nSelLen = nSelLen + 1
nI = nI + 1
End If
Next
.SelLength = nSelLen
.SelColor = RGB(0, 127, 0)
Case Else
If Not (Len(sTmpWord) = 0) Then
.SelStart = nStartPos - 1
.SelLength = Len(sTmpWord)
nWordPos = InStr(1, gsBlackKeywords, "*" & sTmpWord & "*", 1)
If nWordPos <> 0 Then
.SelColor = RGB(0, 0, 0)
.SelText = Mid$(gsBlackKeywords, nWordPos + 1, Len(sTmpWord))
End If
nWordPos = InStr(1, gsBlueKeyWords, "*" & sTmpWord & "*", 1)
If nWordPos <> 0 Then
.SelColor = RGB(0, 0, 127)
.SelText = Mid$(gsBlueKeyWords, nWordPos + 1, Len(sTmpWord))
End If
If UCase$(sTmpWord) = "REM" Then
.SelStart = nI - 4
.SelLength = 3
For nJ = 1 To 10000 '9999999
If Mid$(sBuffer, nI, 2) = vbCrLf Then
Exit For
Else
.SelLength = .SelLength + 1
nI = nI + 1
End If
Next
.SelColor = RGB(0, 127, 0)
.SelText = LCase$(.SelText)
End If
End If
sTmpWord = ""
End Select
Next
.SelStart = 0
End With
End Sub
'espera ...
Public Sub Wait(ByVal Caption As String, ByVal Minimo As Integer, ByVal Maximo As Integer)
Load FRMWait
FRMWait.lblGlosa.Caption = Caption
FRMWait.pgb.Min = Minimo
FRMWait.pgb.Max = Maximo
FRMWait.Show
DoEvents
End Sub