|
1 | | -Function TestObjectForData(ByVal objToCheck) |
2 | | - 'region FunctionMetadata #################################################### |
3 | | - ' Checks an object or variable to see if it "has data". |
4 | | - ' If any of the following are true, then objToCheck is regarded as NOT having data: |
5 | | - ' VarType(objToCheck) = 0 |
6 | | - ' VarType(objToCheck) = 1 |
7 | | - ' objToCheck Is Nothing |
8 | | - ' IsEmpty(objToCheck) |
9 | | - ' IsNull(objToCheck) |
10 | | - ' objToCheck = vbNullString (or "") |
11 | | - ' IsArray(objToCheck) = True And UBound(objToCheck) throws an error |
12 | | - ' IsArray(objToCheck) = True And UBound(objToCheck) < 0 |
13 | | - ' In any of these cases, the function returns False. Otherwise, it returns True. |
14 | | - ' |
15 | | - ' Version: 1.1.20210115.0 |
16 | | - 'endregion FunctionMetadata #################################################### |
17 | | - |
18 | | - 'region License #################################################### |
19 | | - ' Copyright 2021 Frank Lesniak |
20 | | - ' |
21 | | - ' Permission is hereby granted, free of charge, to any person obtaining a copy of this |
22 | | - ' software and associated documentation files (the "Software"), to deal in the Software |
23 | | - ' without restriction, including without limitation the rights to use, copy, modify, merge, |
24 | | - ' publish, distribute, sublicense, and/or sell copies of the Software, and to permit |
25 | | - ' persons to whom the Software is furnished to do so, subject to the following conditions: |
26 | | - ' |
27 | | - ' The above copyright notice and this permission notice shall be included in all copies or |
28 | | - ' substantial portions of the Software. |
29 | | - ' |
30 | | - ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
31 | | - ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
32 | | - ' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
33 | | - ' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
34 | | - ' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
35 | | - ' DEALINGS IN THE SOFTWARE. |
36 | | - 'endregion License #################################################### |
37 | | - |
38 | | - 'region DownloadLocationNotice #################################################### |
39 | | - ' The most up-to-date version of this script can be found on the author's GitHub repository |
40 | | - ' at https://github.com/franklesniak/Test_Object_For_Data |
41 | | - 'endregion DownloadLocationNotice #################################################### |
42 | | - |
43 | | - 'region Acknowledgements #################################################### |
44 | | - ' Thanks to Scott Dexter for writing the article "Empty Nothing And Null How Do You Feel |
45 | | - ' Today", which inspired me to create this function. https://evolt.org/node/346 |
46 | | - ' |
47 | | - ' Thanks also to "RhinoScript" for the article "Testing for Empty Arrays" for providing |
48 | | - ' guidance for how to test for the empty array condition in VBScript. |
49 | | - ' https://wiki.mcneel.com/developer/scriptsamples/emptyarray |
50 | | - ' |
51 | | - ' Thanks also "iamresearcher" who posted this and inspired the test case for vbNullString: |
52 | | - ' https://www.vbforums.com/showthread.php?684799-The-Differences-among-Empty-Nothing-vbNull-vbNullChar-vbNullString-and-the-Zero-L |
53 | | - 'endregion Acknowledgements #################################################### |
54 | | - |
55 | | - Dim boolTestResult |
56 | | - Dim boolFunctionReturn |
57 | | - Dim intArrayUBound |
58 | | - |
59 | | - Err.Clear |
60 | | - |
61 | | - boolFunctionReturn = True |
62 | | - |
63 | | - 'Check VarType(objToCheck) = 0 |
64 | | - On Error Resume Next |
65 | | - boolTestResult = (VarType(objToCheck) = 0) |
66 | | - If Err Then |
67 | | - 'Error occurred |
68 | | - Err.Clear |
69 | | - On Error Goto 0 |
70 | | - Else |
71 | | - 'No Error |
72 | | - On Error Goto 0 |
73 | | - If boolTestResult = True Then |
74 | | - 'vbEmpty |
75 | | - boolFunctionReturn = False |
76 | | - End If |
77 | | - End If |
78 | | - |
79 | | - 'Check VarType(objToCheck) = 1 |
80 | | - On Error Resume Next |
81 | | - boolTestResult = (VarType(objToCheck) = 1) |
82 | | - If Err Then |
83 | | - 'Error occurred |
84 | | - Err.Clear |
85 | | - On Error Goto 0 |
86 | | - Else |
87 | | - 'No Error |
88 | | - On Error Goto 0 |
89 | | - If boolTestResult = True Then |
90 | | - 'vbNull |
91 | | - boolFunctionReturn = False |
92 | | - End If |
93 | | - End If |
94 | | - |
95 | | - 'Check to see if objToCheck Is Nothing |
96 | | - If boolFunctionReturn = True Then |
97 | | - On Error Resume Next |
98 | | - boolTestResult = (objToCheck Is Nothing) |
99 | | - If Err Then |
100 | | - 'Error occurred |
101 | | - Err.Clear |
102 | | - On Error Goto 0 |
103 | | - Else |
104 | | - 'No Error |
105 | | - On Error Goto 0 |
106 | | - If boolTestResult = True Then |
107 | | - 'No data |
108 | | - boolFunctionReturn = False |
109 | | - End If |
110 | | - End If |
111 | | - End If |
112 | | - |
113 | | - 'Check IsEmpty(objToCheck) |
114 | | - If boolFunctionReturn = True Then |
115 | | - On Error Resume Next |
116 | | - boolTestResult = IsEmpty(objToCheck) |
117 | | - If Err Then |
118 | | - 'Error occurred |
119 | | - Err.Clear |
120 | | - On Error Goto 0 |
121 | | - Else |
122 | | - 'No Error |
123 | | - On Error Goto 0 |
124 | | - If boolTestResult = True Then |
125 | | - 'No data |
126 | | - boolFunctionReturn = False |
127 | | - End If |
128 | | - End If |
129 | | - End If |
130 | | - |
131 | | - 'Check IsNull(objToCheck) |
132 | | - If boolFunctionReturn = True Then |
133 | | - On Error Resume Next |
134 | | - boolTestResult = IsNull(objToCheck) |
135 | | - If Err Then |
136 | | - 'Error occurred |
137 | | - Err.Clear |
138 | | - On Error Goto 0 |
139 | | - Else |
140 | | - 'No Error |
141 | | - On Error Goto 0 |
142 | | - If boolTestResult = True Then |
143 | | - 'No data |
144 | | - boolFunctionReturn = False |
145 | | - End If |
146 | | - End If |
147 | | - End If |
148 | | - |
149 | | - 'Check objToCheck = vbNullString |
150 | | - If boolFunctionReturn = True Then |
151 | | - On Error Resume Next |
152 | | - boolTestResult = (objToCheck = vbNullString) |
153 | | - If Err Then |
154 | | - 'Error occurred |
155 | | - Err.Clear |
156 | | - On Error Goto 0 |
157 | | - Else |
158 | | - 'No Error |
159 | | - On Error Goto 0 |
160 | | - If boolTestResult = True Then |
161 | | - 'No data |
162 | | - boolFunctionReturn = False |
163 | | - End If |
164 | | - End If |
165 | | - End If |
166 | | - |
167 | | - If boolFunctionReturn = True Then |
168 | | - On Error Resume Next |
169 | | - boolTestResult = IsArray(objToCheck) |
170 | | - If Err Then |
171 | | - 'Error occurred |
172 | | - Err.Clear |
173 | | - On Error Goto 0 |
174 | | - boolTestResult = False |
175 | | - Else |
176 | | - 'No Error |
177 | | - On Error Goto 0 |
178 | | - End If |
179 | | - If boolTestResult = True Then |
180 | | - ' objToCheck is an array |
181 | | - On Error Resume Next |
182 | | - intArrayUBound = UBound(objToCheck) |
183 | | - If Err Then |
184 | | - 'Undimensioned array |
185 | | - Err.Clear |
186 | | - On Error Goto 0 |
187 | | - intArrayUBound = -1 |
188 | | - Else |
189 | | - On Error Goto 0 |
190 | | - End If |
191 | | - If intArrayUBound < 0 Then |
192 | | - boolFunctionReturn = False |
193 | | - End If |
194 | | - End If |
195 | | - End If |
196 | | - |
197 | | - TestObjectForData = boolFunctionReturn |
198 | | -End Function |
199 | | - |
200 | 1 | Function ConvertStringVersionNumberToMajorMinorBuildRevisionIntegers(ByRef lngMajor, ByRef lngMinor, ByRef lngBuild, ByRef lngRevision, ByVal strVersionNumber) |
201 | 2 | 'region FunctionMetadata #################################################### |
202 | 3 | ' Safely takes a string that contains a version number and converts it to a series of four |
|
0 commit comments