blob: 01a1a4c07c3815cb0ccdcd75545769a10abe74ba [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.
15 ID As Integer ' Define elements of data type.
16 Name As String * 20
17 Address As String * 30
18 Phone As Long
19 HireDate As Date
20End Type
21
22Public Enum InterfaceColors
23 icMistyRose = &HE1E4FF&
24 icSlateGray = &H908070&
25 icDodgerBlue = &HFF901E&
26 icDeepSkyBlue = &HFFBF00&
27 icSpringGreen = &H7FFF00&
28 icForestGreen = &H228B22&
29 icGoldenrod = &H20A5DA&
30 icFirebrick = &H2222B2&
31End Enum
32
33Enum SecurityLevel
34 IllegalEntry = -1
35 SecurityLevel1 = 0
36 SecurityLevel2 = 1
37End Enum
38
39Public Function TestConditional (number As Integer, ext As String) As Boolean
40 Dim inRange As Boolean
41
42 Select Case number
43 Case <= 0
44 inRange = False
45 Case > 10
46 inRange = False
47 Case Else
48 inRange = True
49 End Select
50
51 ' This is a special case identified in the indent script.
52 Select Case number
53 End Select
54
55 If ext = ".xlm" Then
56 If inRange Then
57 TestConditional = True
58 Else
59 TestConditional = False
60 End If
61 ElseIf ext = ".xlsx" Then
62 If inRange Then
63 TestConditional = False
64 Else
65 TestConditional = True
66 End If
67 Else
68 TestConditional = False
69 End If
70End Function
71
72Private Sub TestIterators (lLimit As Integer, uLimit As Integer)
73 Dim a() As Variant
74 Dim elmt As Variant
75 Dim found As Boolean
76 Dim indx As Integer
77 Const specialValue As Integer = 5
78
79 If uLimit < lLimit Then
80 Exit Sub
81 End If
82
83 ReDim a(lLimit To uLimit)
84 For indx=lLimit To Ulimit
85 a(indx) = 2 * indx
86 Next indx
87
88 found = False
89 For Each elmt in a
90 If elmt = specialValue Then
91 found = True
92 End If
93 Next elmt
94
95 If found then
96 indx = uLimit
97 Do While indx >= lLimit
98 indx = indx - 1
99 Loop
100 End If
101
102End Sub
103
104Public Sub TestMultiline (cellAddr As String, rowNbr As Long)
105 Dim rng As Range
106
107 Set 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 +0000111 With rng
112 .Cells(1,1).Value = _
113 "Line 1 of multiline string; " & _
114 "Line 2 of multiline string; " & _
115 "Line 3 of multiline string"
116 End 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.
120 With rng
121 .Cells(1,1).Value =_
122 "Line 1 of multiline string; " &_
123 "Line 2 of multiline string; " &_
124 "Line 3 of multiline string"
125 End 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.
131 With rng
132 rng.Cells(1,1).Value = _
133 "Line 1 of multiline string; " & _
134 "Line 2 of multiline string; " & _
135 "Line 3 of multiline string"
136 End With
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000137
138End Sub
139
140Private Sub TestStmtLabel()
141 GoTo 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)
149 Dim Integer accumulator
150 accumulator = accumulator + addend
151 TestStatic = accumulator
152End Function
153
154Friend Function TestFriend(addend As Integer)
155 Static Integer accumulator
156 accumulator = accumulator + addend
157 TestFriend = accumulator
158End Function
159
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000160Sub TestTypeKeyword()
161 Type EmployeeRecord ' Create user-defined type.
162 ID As Integer ' Define elements of data type.
163 Name As String * 20
164 Address As String * 30
165 Phone As Long
166 HireDate As Date
167 End Type
168 Dim varType As EmployeeRecord
169End Sub
Michael Soykaaf2254d2024-05-20 14:37:50 +0200170
171Sub TestDateLiteralAfterLineContinuation
172 Dim birthday as Date
173 birthday = _
174 #January 1, 1901#
175End Sub
Bram Moolenaarf1dcd142022-12-31 15:30:45 +0000176' END_INDENT