blob: cb964f792c6eccefebfb863aebd17632afcbcd6e [file] [log] [blame]
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00001' vim: filetype=vb shiftwidth=4 expandtab
2'
3' START_INDENT
Michael Soykaaf2254d2024-05-20 14:37:50 +02004#Const Debug = False
5
6#If Win64 Then
7' Win64=true, Win32=true, Win16=false
8#ElseIf Win32 Then
9' Win32=true, Win16=false
10#Else
11' Win16=true
12#End If
13
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000014Public Type GEmployeeRecord ' Create user-defined type.
15ID As Integer ' Define elements of data type.
16Name As String * 20
17Address As String * 30
18Phone As Long
19HireDate As Date
20End Type
21
22Public Enum InterfaceColors
23icMistyRose = &HE1E4FF&
24icSlateGray = &H908070&
25icDodgerBlue = &HFF901E&
26icDeepSkyBlue = &HFFBF00&
27icSpringGreen = &H7FFF00&
28icForestGreen = &H228B22&
29icGoldenrod = &H20A5DA&
30icFirebrick = &H2222B2&
31End Enum
32
33Enum SecurityLevel
34IllegalEntry = -1
35SecurityLevel1 = 0
36SecurityLevel2 = 1
37End Enum
38
39Public Function TestConditional (number As Integer, ext As String) As Boolean
40Dim inRange As Boolean
41
42Select Case number
43Case <= 0
44inRange = False
45Case > 10
46inRange = False
47Case Else
48inRange = True
49End Select
50
51' This is a special case identified in the indent script.
52Select Case number
53End Select
54
55If ext = ".xlm" Then
56If inRange Then
57TestConditional = True
58Else
59TestConditional = False
60End If
61ElseIf ext = ".xlsx" Then
62If inRange Then
63TestConditional = False
64Else
65TestConditional = True
66End If
67Else
68TestConditional = False
69End If
70End Function
71
72Private Sub TestIterators (lLimit As Integer, uLimit As Integer)
73Dim a() As Variant
74Dim elmt As Variant
75Dim found As Boolean
76Dim indx As Integer
77Const specialValue As Integer = 5
78
79If uLimit < lLimit Then
80Exit Sub
81End If
82
83ReDim a(lLimit To uLimit)
84For indx=lLimit To Ulimit
85a(indx) = 2 * indx
86Next indx
87
88found = False
89For Each elmt in a
90If elmt = specialValue Then
91found = True
92End If
93Next elmt
94
95If found then
96indx = uLimit
97Do While indx >= lLimit
98indx = indx - 1
99Loop
100End If
101
102End Sub
103
104Public Sub TestMultiline (cellAddr As String, rowNbr As Long)
105Dim rng As Range
106
107Set rng = Range(cellAddr)
Michael Soykaaf2254d2024-05-20 14:37:50 +0200108
109' Line continuation is implemented as a two-character sequence-
110' whitespace followed by underscore.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000111With rng
112.Cells(1,1).Value = _
113"Line 1 of multiline string; " & _
114"Line 2 of multiline string; " & _
115"Line 3 of multiline string"
116End With
117
Michael Soykaaf2254d2024-05-20 14:37:50 +0200118' This code block omits the leading whitespace character and so
119' the trailing underscore will not be treated as line continuation.
120With rng
121.Cells(1,1).Value =_
122"Line 1 of multiline string; " &_
123"Line 2 of multiline string; " &_
124"Line 3 of multiline string"
125End With
126
127' The following lines have whitespace after the underscore character.
128' This is contrary to Microsoft documentation but it is reported that
129' some Microsoft editors allow it and will still treat the statement
130' as line-continued.
131With rng
132rng.Cells(1,1).Value = _
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000133"Line 1 of multiline string; " & _
134"Line 2 of multiline string; " & _
135"Line 3 of multiline string"
Michael Soykaaf2254d2024-05-20 14:37:50 +0200136End With
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000137
138End Sub
139
140Private Sub TestStmtLabel()
141GoTo stmtLabel
142
143' Statement labels are never indented
144stmtLabel:
145
146End Sub
147
Michael Soykaaf2254d2024-05-20 14:37:50 +0200148Public Static Function TestStatic(addend As Integer)
149Dim Integer accumulator
150accumulator = accumulator + addend
151TestStatic = accumulator
152End Function
153
154Friend Function TestFriend(addend As Integer)
155Static Integer accumulator
156accumulator = accumulator + addend
157TestFriend = accumulator
158End Function
159
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000160Sub TestTypeKeyword()
161Type EmployeeRecord ' Create user-defined type.
162ID As Integer ' Define elements of data type.
163Name As String * 20
164Address As String * 30
165Phone As Long
166HireDate As Date
167End Type
168Dim varType As EmployeeRecord
169End Sub
Michael Soykaaf2254d2024-05-20 14:37:50 +0200170
171Sub TestDateLiteralAfterLineContinuation
172Dim birthday as Date
173birthday = _
174#January 1, 1901#
175End Sub
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000176' END_INDENT