-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodSyntaxsFunc.bas
1250 lines (1005 loc) · 37.7 KB
/
modSyntaxsFunc.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "modSyntaxsFunc"
Option Explicit
Option Base 0
Global Const STATE_SYSTEM_FOCUSABLE = &H100000
Global Const STATE_SYSTEM_INVISIBLE = &H8000
Global Const STATE_SYSTEM_OFFSCREEN = &H10000
Global Const STATE_SYSTEM_UNAVAILABLE = &H1
Global Const STATE_SYSTEM_PRESSED = &H8
Global Const CCHILDREN_TITLEBAR = 5
Global Const LB_GETITEMRECT = &H198
Global Const CB_GETDROPPEDCONTROLRECT = &H15F
'Global Const CB_GETITEMHEIGHT = &H154
Global Const MF_BYPOSITION = &H400&
Global Const MF_DISABLED = &H2&
Global TITLEBAR_OFFSET As Integer
Global Const LongOffset = 4294967296#
Global Const MaxLong = 2147483647
Global Const IntOffset = 65536
Global Const MaxInt = 32767
Public Const CB_FINDSTRING = &H14C
Public Type ResizeCons
LeftGap As Long
TopGap As Long
RightGap As Long
BottomGap As Long
End Type
Public Enum ListDataType
ldtstring = 0
ldtnumber = 1
ldtDateTime = 2
End Enum
Type TITLEBARINFO
cbSize As Long
rcTitleBar As RECT
rgstate(CCHILDREN_TITLEBAR) As Long
End Type
Public bSuppressErrors As Boolean
'Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
'Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
'Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Public Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetTitleBarInfo Lib "user32" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
'Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Const GWL_EXSTYLE = -20
Const GWL_HINSTANCE = -6
Const GWL_HWNDPARENT = -8
Const GWL_ID = -12
Const GWL_STYLE = -16
Const GWL_USERDATA = -21
Const GWL_WNDPROC = -4
Const DWL_DLGPROC = 4
Const DWL_MSGRESULT = 0
Const DWL_USER = 8
'Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
' (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetParent Lib "user32" _
(ByVal FormHwnd As Long, Optional ByVal NewHwnd As Long) As Long
Public Function GetOwner(ByVal HwndofForm) As Long
GetOwner = GetWindowLong(HwndofForm, GWL_HWNDPARENT)
End Function
Public Function SetOwner(ByVal HwndtoUse, ByVal HwndofOwner) As Long
SetOwner = SetWindowLong(HwndtoUse, GWL_HWNDPARENT, HwndofOwner)
' If HwndofOwner = 0 Then
' SetOwner = SetParent(HwndtoUse, Null)
' Else
' SetOwner = SetParent(HwndtoUse, HwndofOwner)
' End If
End Function
Public Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
As Long
If Topmost = True Then 'Make the window topmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
0, 0, FLAGS)
SetTopMostWindow = False
End If
End Function
Public Function in_long_arr(ByVal nSearch As Long, arrLong() As Long) As Boolean
Dim nIndex As Long
On Error GoTo error:
For nIndex = LBound(arrLong) To UBound(arrLong)
If arrLong(nIndex) = nSearch Then
in_long_arr = True
Exit For
End If
Next
out:
On Error Resume Next
Exit Function
error:
Call HandleError("in_long_arr")
Resume out:
End Function
Public Function in_str_arr(ByVal sSearch As String, arrString() As String) As Boolean
Dim nIndex As Integer
On Error GoTo error:
For nIndex = LBound(arrString) To UBound(arrString)
If arrString(nIndex) = sSearch Then
in_str_arr = True
Exit For
End If
Next
out:
On Error Resume Next
Exit Function
error:
Call HandleError("in_str_arr")
Resume out:
End Function
Public Sub ClearListViewSelections(ByRef LV As ListView)
Dim oLI As ListItem
On Error GoTo error:
For Each oLI In LV.ListItems
oLI.Selected = False
Set oLI = Nothing
Next
out:
Set oLI = Nothing
Exit Sub
error:
Call HandleError("ClearListViewSelections")
Resume out:
End Sub
'Public Function ClipNull(ByVal DataToClip As String, Optional ByVal length As Integer) As String
'On Error GoTo Error:
'Dim i As Long
'
'If length = 0 Then length = Len(DataToClip)
'
'For i = 1 To length
' If Mid(DataToClip, i, 1) = Chr(0) Then
' ClipNull = Mid(DataToClip, 1, i - 1)
' Exit Function
' End If
'Next i
'
'ClipNull = DataToClip
'
'Exit Function
'Error:
'Call HandleError("ClipNull")
'ClipNull = "error"
'End Function
Public Function ExtractNumbersFromString(ByVal sString As String) As Variant
Dim x As Integer, sNewString As String, bIgnoreDecimal As Boolean
On Error GoTo error:
ExtractNumbersFromString = 0
sNewString = ""
bIgnoreDecimal = False
For x = 1 To Len(sString)
Select Case Mid(sString, x, 1)
Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0":
sNewString = sNewString & Mid(sString, x, 1)
Case ".":
If Not sNewString = "" And Not bIgnoreDecimal Then
sNewString = sNewString & Mid(sString, x, 1)
bIgnoreDecimal = True
End If
Case "-":
If sNewString = "" Then
sNewString = sNewString & Mid(sString, x, 1)
End If
Case Else:
If sNewString = "-" Then
sNewString = ""
ElseIf Not sNewString = "" Then
GoTo out:
End If
End Select
Next
out:
ExtractNumbersFromString = Val(sNewString)
Exit Function
error:
Call HandleError("ExtractNumbersFromString")
End Function
Public Function ExtractValueFromString(ByVal sWholeString As String, ByVal sSearchText As String) As Long
Dim x As Long, y As Long, sChar As String * 1
On Error GoTo error:
x = InStr(1, sWholeString, sSearchText, vbTextCompare)
If x > 0 Then
x = x + Len(sSearchText) 'position x just after the search text
y = x
Do Until y > Len(sWholeString)
sChar = Mid(sWholeString, y, 1)
Select Case sChar
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
Case " ":
If y > x Then
Exit Do
Else
x = x + 1
End If
Case Else: Exit Do
End Select
y = y + 1
Loop
If y > x Then ExtractValueFromString = Val(Mid(sWholeString, x, y - x))
'If ExtractValueFromString = "0" Then ExtractValueFromString = ""
End If
out:
Exit Function
error:
Call HandleError("ExtractValueFromString")
Resume out:
End Function
Public Function FileExists(ByVal FileName As String) As Boolean
Dim fso As FileSystemObject
On Error GoTo error:
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FileName) Then FileExists = True
out:
Set fso = Nothing
Exit Function
error:
Call HandleError("FileExists")
Resume out:
End Function
Public Function FolderExists(ByVal FolderPath As String) As Boolean
Dim fso As FileSystemObject
On Error GoTo error:
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(FolderPath) Then FolderExists = True
out:
Set fso = Nothing
Exit Function
error:
Call HandleError("FileExists")
Resume out:
End Function
Public Sub GetTitleBarOffset()
Dim TitleInfo As TITLEBARINFO, OSVer As cnWin32Ver
On Error GoTo error:
OSVer = Win32Ver
If OSVer <= win95 Then GoTo win95:
TitleInfo.cbSize = Len(TitleInfo)
GetTitleBarInfo frmMain.hwnd, TitleInfo
TITLEBAR_OFFSET = (TitleInfo.rcTitleBar.Bottom * Screen.TwipsPerPixelY) - (TitleInfo.rcTitleBar.Top * Screen.TwipsPerPixelY)
If TITLEBAR_OFFSET > 285 Then '285 is the standard height
TITLEBAR_OFFSET = TITLEBAR_OFFSET - 285
Else
TITLEBAR_OFFSET = 0
End If
Exit Sub
win95:
TITLEBAR_OFFSET = 0
Exit Sub
error:
Call HandleError("GetTitleBarOffset")
End Sub
Public Sub HandleError(Optional ByVal ErrorSource As String)
Dim nYesNo As Integer
If bSuppressErrors Then
Err.clear
Exit Sub
End If
Select Case Err.Number
Case 70:
nYesNo = MsgBox("Error 70: File is locked by another process!" _
& vbCrLf & "Terminate Application?", vbExclamation + vbYesNo + vbDefaultButton2)
Case Else:
If Len(ErrorSource) > 1 Then
nYesNo = MsgBox("Error " & Err.Number & " in [" & ErrorSource & "]" & vbCrLf _
& Err.Description & vbCrLf _
& "Terminate Application?", vbCritical + vbYesNo + vbDefaultButton2)
Else
nYesNo = MsgBox("Error " & Err.Number & ": " & Err.Description _
& vbCrLf & "Terminate Application?", vbYesNo + vbCritical + vbDefaultButton2)
End If
End Select
If nYesNo = vbYes Then
frmMain.bDontCallTerminate = True
frmMain.bDontSaveSettings = True
Call AppTerminate
End
End If
Err.clear
End Sub
Private Function InvNumber(ByVal Number As String) As String
'*******************************************************************************
' Modifies a numeric string to allow it to be sorted alphabetically
'-------------------------------------------------------------------------------
Static i As Integer
For i = 1 To Len(Number)
Select Case Mid$(Number, i, 1)
Case "-": Mid$(Number, i, 1) = " "
Case "0": Mid$(Number, i, 1) = "9"
Case "1": Mid$(Number, i, 1) = "8"
Case "2": Mid$(Number, i, 1) = "7"
Case "3": Mid$(Number, i, 1) = "6"
Case "4": Mid$(Number, i, 1) = "5"
Case "5": Mid$(Number, i, 1) = "4"
Case "6": Mid$(Number, i, 1) = "3"
Case "7": Mid$(Number, i, 1) = "2"
Case "8": Mid$(Number, i, 1) = "1"
Case "9": Mid$(Number, i, 1) = "0"
End Select
Next
InvNumber = Number
'*******************************************************************************
'
'-------------------------------------------------------------------------------
End Function
Public Function NumberKeysOnly(ByVal KeyAscii As Integer) As Integer
NumberKeysOnly = KeyAscii
If KeyAscii = 3 Or KeyAscii = 22 Then Exit Function 'control+v, control+c
If KeyAscii < 48 Or KeyAscii > 57 Then NumberKeysOnly = 0
If KeyAscii = 8 Then NumberKeysOnly = KeyAscii
If KeyAscii = 45 Then NumberKeysOnly = KeyAscii
End Function
Public Function PutCommas(ByVal sNumber As String) As String
On Error GoTo error:
Dim x As Integer, y As Integer, z As Integer
If Len(sNumber) < 4 Then
PutCommas = sNumber
Exit Function
End If
z = 1
y = Len(sNumber)
For x = 1 To y
PutCommas = Mid(sNumber, y - x + 1, 1) & PutCommas
If z > 2 And Not z = y Then
If z Mod 3 = 0 Then PutCommas = "," & PutCommas
End If
z = z + 1
Next
Exit Function
error:
Call HandleError("PutCommas")
End Function
Public Function AutoPrepend(ByVal sStringToPrepend As String, ByVal sPrepend As String, Optional ByVal sGlue As String = ", ") As String
On Error GoTo error:
If Len(sStringToPrepend) > 0 Then
If Len(Trim(sPrepend)) > 0 Then
AutoPrepend = sPrepend & sGlue & sStringToPrepend
Else
AutoPrepend = sStringToPrepend
End If
Else
AutoPrepend = sPrepend
End If
out:
On Error Resume Next
Exit Function
error:
Call HandleError("AutoAppend")
Resume out:
End Function
Public Function AutoAppend(ByVal sStringToAppend As String, ByVal sAppend As String, Optional ByVal sGlue As String = ", ") As String
On Error GoTo error:
If Len(sStringToAppend) > 0 Then
If Len(Trim(sAppend)) > 0 Then
AutoAppend = sStringToAppend & sGlue & sAppend
Else
AutoAppend = sStringToAppend
End If
Else
AutoAppend = sAppend
End If
out:
On Error Resume Next
Exit Function
error:
Call HandleError("AutoAppend")
Resume out:
End Function
Public Function RemoveCharacter(ByVal DataToTest As String, ByVal sChar As String) As String
On Error GoTo error:
Dim i As Long
For i = 1 To Len(DataToTest)
If Not Mid(DataToTest, i, 1) = sChar Then
RemoveCharacter = RemoveCharacter & Mid(DataToTest, i, 1)
End If
Next i
Exit Function
error:
Call HandleError("RemoveCharacter")
RemoveCharacter = "error"
End Function
Public Function RemoveVowles(ByVal sStr As String)
On Error GoTo error:
Dim x As Long, sChar As String
If Len(sStr) = 0 Then Exit Function
RemoveVowles = Mid(sStr, 1, 1)
'2 because commonly you want the first vowel
For x = 2 To Len(sStr)
sChar = Mid(sStr, x, 1)
Select Case sChar
Case "a", "e", "i", "o", "u":
Case Else:
RemoveVowles = RemoveVowles & sChar
End Select
Next
Exit Function
error:
Call HandleError("HandleError")
End Function
Public Function RoundUp(ByVal nNumber As Double) As Double
On Error GoTo error:
If 0 < nNumber - Int(nNumber) Then
RoundUp = Int(nNumber) + 1
Else
RoundUp = Int(nNumber)
End If
out:
Exit Function
error:
Call HandleError("RoundUp")
Resume out:
End Function
Public Sub SortListView(ListView As ListView, ByVal Index As Integer, ByVal DataType As ListDataType, ByVal Ascending As Boolean)
'*******************************************************************************
' Sort a ListView by String, Number, or DateTime
'
' Parameters:
'
' ListView Reference to the ListView control to be sorted.
' Index Index of the column in the ListView to be sorted. The first
' column in a ListView has an index value of 1.
' DataType Sets whether the data in the column is to be sorted
' alphabetically, numerically, or by date.
' Ascending Sets the direction of the sort. True sorts A-Z (Ascending),
' and False sorts Z-A (descending)
'-------------------------------------------------------------------------------
On Error Resume Next
Dim i As Integer
Dim l As Long
Dim strFormat As String
' Display the hourglass cursor whilst sorting
Dim lngCursor As Long
lngCursor = ListView.MousePointer
ListView.MousePointer = vbHourglass
' Prevent the ListView control from updating on screen - this is to hide
' the changes being made to the listitems, and also to speed up the sort
If ListView.ListItems.Count > 75 Then LockWindowUpdate frmMain.hwnd 'ListView.hWnd
Dim blnRestoreFromTag As Boolean
Select Case DataType
Case ldtstring
' Sort alphabetically. This is the only sort provided by the
' MS ListView control (at this time), and as such we don't really
' need to do much here
blnRestoreFromTag = False
Case ldtnumber
' Sort Numerically
strFormat = String$(20, "0") & "." & String$(10, "0")
' Loop through the values in this column. Re-format the values so
' as they can be sorted alphabetically, having already stored their
' text values in the tag, along with the tag's original value
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
.Tag = .Text & Chr$(0) & .Tag
' If IsNumeric(.Text) Then
If CDbl(Val(.Text)) >= 0 Then
.Text = Format(CDbl(Val(.Text)), strFormat)
Else
.Text = "&" & InvNumber(Format(0 - CDbl(Val(.Text)), strFormat))
End If
' Else
' .Text = ""
' End If
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
.Tag = .Text & Chr$(0) & .Tag
' If IsNumeric(.Text) Then
If CDbl(Val(.Text)) >= 0 Then
.Text = Format(CDbl(Val(.Text)), strFormat)
Else
.Text = "&" & InvNumber(Format(0 - CDbl(Val(.Text)), strFormat))
End If
' Else
' .Text = ""
' End If
End With
Next l
End If
End With
blnRestoreFromTag = True
Case ldtDateTime
' Sort by date.
strFormat = "YYYYMMDDHhNnSs"
Dim dte As Date
' Loop through the values in this column. Re-format the dates so as they
' can be sorted alphabetically, having already stored their visible
' values in the tag, along with the tag's original value
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
.Tag = .Text & Chr$(0) & .Tag
dte = CDate(.Text)
.Text = Format$(dte, strFormat)
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
.Tag = .Text & Chr$(0) & .Tag
dte = CDate(.Text)
.Text = Format$(dte, strFormat)
End With
Next l
End If
End With
blnRestoreFromTag = True
End Select
' Sort the ListView Alphabetically
ListView.SortOrder = IIf(Ascending, lvwAscending, lvwDescending)
ListView.SortKey = Index - 1
ListView.Sorted = True
' Restore the Text Values if required
If blnRestoreFromTag Then
' Restore the previous values to the 'cells' in this column of the list
' from the tags, and also restore the tags to their original values
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
i = InStr(.Tag, Chr$(0))
.Text = Left$(.Tag, i - 1)
.Tag = Mid$(.Tag, i + 1)
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
i = InStr(.Tag, Chr$(0))
.Text = Left$(.Tag, i - 1)
.Tag = Mid$(.Tag, i + 1)
End With
Next l
End If
End With
End If
' Unlock the list window so that the OCX can update it
LockWindowUpdate 0&
' Restore the previous cursor
ListView.MousePointer = lngCursor
End Sub
Public Sub SortListViewByTag(ListView As ListView, ByVal Index As Integer, ByVal DataType As ListDataType, ByVal Ascending As Boolean)
'*******************************************************************************
' Sort a ListView by String, Number, or DateTime
'
' Parameters:
'
' ListView Reference to the ListView control to be sorted.
' Index Index of the column in the ListView to be sorted. The first
' column in a ListView has an index value of 1.
' DataType Sets whether the data in the column is to be sorted
' alphabetically, numerically, or by date.
' Ascending Sets the direction of the sort. True sorts A-Z (Ascending),
' and False sorts Z-A (descending)
'-------------------------------------------------------------------------------
On Error Resume Next
Dim i As Integer
Dim l As Long
Dim strFormat As String
' Display the hourglass cursor whilst sorting
Dim lngCursor As Long
lngCursor = ListView.MousePointer
ListView.MousePointer = vbHourglass
' Prevent the ListView control from updating on screen - this is to hide
' the changes being made to the listitems, and also to speed up the sort
If ListView.ListItems.Count > 75 Then LockWindowUpdate frmMain.hwnd 'ListView.hWnd
Dim blnRestoreFromTag As Boolean
Select Case DataType
Case ldtstring
' Sort alphabetically. This is the only sort provided by the
' MS ListView control (at this time), and as such we don't really
' need to do much here
blnRestoreFromTag = False
Case ldtnumber
' Sort Numerically
strFormat = String$(20, "0") & "." & String$(10, "0")
' Loop through the values in this column. Re-format the values so
' as they can be sorted alphabetically, having already stored their
' text values in the tag, along with the tag's original value
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
'.Tag = .Text & Chr$(0) & .Tag
.Tag = .Tag & Chr$(0) & .Text
' If IsNumeric(.Text) Then
If CDbl(Val(Replace(.Text, "%", ""))) >= 0 Then
.Text = Format(CDbl(Val(.Tag)), strFormat)
Else
.Text = "&" & InvNumber(Format(0 - CDbl(Val(.Tag)), strFormat))
End If
' Else
' .Text = ""
' End If
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
'.Tag = .Text & Chr$(0) & .Tag
.Tag = .Tag & Chr$(0) & .Text
' If IsNumeric(.Text) Then
If CDbl(Val(Replace(.Text, "%", ""))) >= 0 Then
.Text = Format(CDbl(Val(.Tag)), strFormat)
Else
.Text = "&" & InvNumber(Format(0 - CDbl(Val(.Tag)), strFormat))
End If
' Else
' .Text = ""
' End If
End With
Next l
End If
End With
blnRestoreFromTag = True
Case ldtDateTime
' Sort by date.
strFormat = "YYYYMMDDHhNnSs"
Dim dte As Date
' Loop through the values in this column. Re-format the dates so as they
' can be sorted alphabetically, having already stored their visible
' values in the tag, along with the tag's original value
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
.Tag = .Text & Chr$(0) & .Tag
dte = CDate(.Text)
.Text = Format$(dte, strFormat)
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
.Tag = .Text & Chr$(0) & .Tag
dte = CDate(.Text)
.Text = Format$(dte, strFormat)
End With
Next l
End If
End With
blnRestoreFromTag = True
End Select
' Sort the ListView Alphabetically
ListView.SortOrder = IIf(Ascending, lvwAscending, lvwDescending)
ListView.SortKey = Index - 1
ListView.Sorted = True
' Restore the Text Values if required
If blnRestoreFromTag Then
' Restore the previous values to the 'cells' in this column of the list
' from the tags, and also restore the tags to their original values
With ListView.ListItems
If (Index = 1) Then
For l = 1 To .Count
With .item(l)
i = InStr(.Tag, Chr$(0))
.Text = Mid$(.Tag, i + 1)
.Tag = Left$(.Tag, i - 1)
End With
Next l
Else
For l = 1 To .Count
With .item(l).ListSubItems(Index - 1)
i = InStr(.Tag, Chr$(0))
.Text = Mid$(.Tag, i + 1)
.Tag = Left$(.Tag, i - 1)
End With
Next l
End If
End With
End If
' Unlock the list window so that the OCX can update it
LockWindowUpdate 0&
' Restore the previous cursor
ListView.MousePointer = lngCursor
End Sub
Public Sub UnloadForms(ByVal sDontUnload As String)
On Error GoTo error:
Dim objFrm As Form
For Each objFrm In Forms
If Not objFrm.name = sDontUnload And Not objFrm.name = "frmMain" Then Unload objFrm
Next
If Not sDontUnload = "frmMain" Then
Unload frmMain
End If
Set objFrm = Nothing
Exit Sub
error:
Call HandleError("HandleError")
Set objFrm = Nothing
End Sub
Public Function FormIsLoaded(ByVal sFormName As String) As Boolean
On Error GoTo error:
Dim objFrm As Form
For Each objFrm In Forms
If objFrm.name = sFormName Then
FormIsLoaded = True
Exit For
End If
Next objFrm
Set objFrm = Nothing
Exit Function
error:
Call HandleError("FormIsLoaded")
Set objFrm = Nothing
End Function
Public Function PutCrLF(ByVal sString As String) As String
Dim x As Integer, y As Integer
On Error GoTo error:
y = InStr(1, sString, Chr(10))
If y = 0 Then
PutCrLF = sString
Exit Function
End If
x = 1
Do While x < Len(sString)
y = InStr(x, sString, Chr(10))
If y = 0 Then
PutCrLF = PutCrLF & Mid(sString, x)
Exit Do
End If
PutCrLF = PutCrLF & Mid(sString, x, y - x) & vbCrLf
x = y + 1
Loop
Exit Function
error:
Call HandleError("PutCrLF")
End Function
'**************************************
' Name: a AutoComplete Very Simple!
' Description:VERY SIMPLE cut and paste
' funtion for the Keypress event of a comb
' obox. Just paste this code into a module
' or form and call the function from the K
' eyPress event. KeyAscii = AutoComplete(c
' boCombobox, KeyAscii,Optional UpperCase)
'
' By: James Berard
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:None
'
'Side Effects:None
'This code is copyrighted and has limite
' d warranties.
'Please see http://www.Planet-Source-Cod
' e.com/xq/ASP/txtCodeId.43911/lngWId.1/qx
' /vb/scripts/ShowCode.htm
'for details.
'**************************************
Public Function AutoComplete(cbCombo As ComboBox, sKeyAscii As Integer, Optional bMatchCase As Boolean) As Integer
Dim lngFind As Long, intPos As Integer, intLength As Integer
Dim tStr As String, intCurrent As Integer
With cbCombo
intCurrent = IIf(.ListIndex >= 0, .ListIndex, 0)
If sKeyAscii = 8 Then
If .SelStart <= 1 Then
.ListIndex = 0
AutoComplete = 0
Exit Function
End If
.SelStart = .SelStart - 1
.SelLength = 32000
.SelText = ""
Else
intPos = .SelStart '// save intial cursor position
tStr = .Text '// save string
If bMatchCase = True Then
.SelText = Chr(sKeyAscii) '// change string. (leave case alone)
Else
.SelText = LCase(Chr(sKeyAscii)) '// change string. (lowercase only)
End If
End If
lngFind = SendMessage(.hwnd, CB_FINDSTRING, 0, ByVal .Text) '// Find string in combobox
If lngFind = -1 Then '// if string not found
.ListIndex = intCurrent