Skip to content

Commit cf2bced

Browse files
committed
1 liners and such
1 parent f347066 commit cf2bced

File tree

3 files changed

+223
-5
lines changed

3 files changed

+223
-5
lines changed

Syntax.vbs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'Syntactical Sugar
2+
' 1 Line If Else
3+
Dim x : x = True
4+
' If x = True Then : MsgBox "True" : Else MsgBox "False"
5+
' x = False
6+
' If x = True Then : MsgBox "True" : Else MsgBox "False" : MsgBox "False2"
7+
8+
' 1 Line For Each
9+
''For Each v IN strAr : sout=sout&v : Next
10+
11+
' 1 Line For To
12+
'For x=0 To UBound(strAr) : sout=sout&strAr(x) : Next
13+
14+
' 1 Line While
15+
'' X=0 : While X<4 : MsgBox X : X=X+1 : Wend
16+
17+
18+
' Functions for byRef, byVal
19+
' Sub F (v) : v=v*2 : End Sub
20+
' Function Fs (v) : Fs=v*2 : End Function
21+

VBSExtras.vbs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Sub puts(byRef arr, byVal n)
8989
arr(UBound(arr)) = n
9090
End Sub
9191

92+
Sub inc (byRef O)
93+
O = O + 2
94+
End Sub
95+
9296
Sub C(byRef str, byVal str2)
9397
str = str & str2
9498
End Sub
@@ -99,7 +103,7 @@ v(1) = 1
99103
v(2) = 3
100104
v(3) = 5
101105
Call sets(v,55,5)
102-
MsgBox "55:" & v(55) & " 1:" & v(1) & " 2:" & v(2) & " 3:" & v(3)
106+
'MsgBox "55:" & v(55) & " 1:" & v(1) & " 2:" & v(2) & " 3:" & v(3)
103107

104108
Redim v2(5)
105109
v2(0) = 10
@@ -113,14 +117,23 @@ C str , "Hi"
113117
C str , " Hello"
114118
C str , " Hi"
115119
C str , " Hiya"
116-
MsgBox str
120+
121+
Dim o1(3,1)
122+
Dim a : a = UBound(o1,1)
123+
Dim b : b = UBound(o1,2)
124+
Dim c1 : c1 = LBound(o1,3)
125+
MsgBox "a " & a
126+
MsgBox "b " & b
127+
MsgBox "c1 " & c1
128+
MsgBox "E " & TypeName(o1(0,0))
129+
117130

118131
' Would Break v2(6) = 60
119132
Call puts(v2,60)
120133
Dim iV2
121-
For iV2=0 To UBound(v2)
122-
MsgBox "v("&iV2&"): " & v2(iV2)
123-
Next
134+
' For iV2=0 To UBound(v2)
135+
' MsgBox "v("&iV2&"): " & v2(iV2)
136+
' Next
124137

125138
'###############################################'
126139
' ############### MAIN TEST ################### '

ops.vbs

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
' Select Cases can be used to short - circuit to prevent errors like 4/0
2+
OPTION EXPLICIT
3+
DIM V : V = TRUE
4+
SELECT CASE V
5+
CASE TRUE
6+
CASE Val
7+
MsgBox "False"
8+
END SELECT
9+
Dim x
10+
Redim y(1)
11+
Dim tStart, tStop1
12+
Dim d : Set d=CreateObject("Scripting.Dictionary")
13+
' ==== Basic For Loop
14+
' tStart = Timer
15+
' For x=0 To 100000
16+
' Next
17+
' tStop1 = Timer
18+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
19+
' TIME = .006
20+
21+
' ===== Addingg 100,000 Elements to a dictionary with mult
22+
' tStart = Timer
23+
' For x=0 To 100000
24+
' d.add "F("&x&")", x*2
25+
' Next
26+
' tStop1 = Timer
27+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
28+
' msgBox d.count ' About 0.7 Seconds
29+
30+
' ==== Adding 100,001 Items to an array with continuous redim
31+
' tStart = Timer
32+
' For x=0 To 100000
33+
' Redim y(x)
34+
' y(x) = "F("&x&")=" & x*2
35+
' Next
36+
' tStop1 = Timer
37+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
38+
' ' 101 Seconrds
39+
' msgBox UBound(y)
40+
' ==== Calling UBound
41+
' tStart = Timer
42+
' For x=0 To 100000
43+
' UBound(y)
44+
' Next
45+
' tStop1 = Timer
46+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
47+
' Time = .04
48+
' ==== Incremental Redim
49+
' tStart = Timer
50+
' For x=0 To 100000
51+
' If x = UBound(y) Then Redim y(x+1)
52+
' y(x) = x
53+
' Next
54+
' tStop1 = Timer
55+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
56+
' Time = 101.063
57+
58+
' ==== Incremental Redim*2
59+
' tStart = Timer
60+
' For x=0 To 100000
61+
' If x = UBound(y) Then Redim y(x*2)
62+
' y(x) = x
63+
' Next
64+
' tStop1 = Timer
65+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
66+
' MsgBox "New UBound " & UBound(y)
67+
' Time = .08
68+
69+
' ==== Incremental Redim*2 With Preserve
70+
' tStart = Timer
71+
' For x=0 To 100000
72+
' If x = UBound(y) Then Redim Preserve y(x+1)
73+
' y(x) = x
74+
' Next
75+
' tStop1 = Timer
76+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
77+
' Time = .53
78+
79+
' ==== Incremental Redim With Preserve\
80+
' tStart = Timer
81+
' For x=0 To 100000
82+
' If x = UBound(y) Then Redim Preserve y(x*2)
83+
' y(x) = x
84+
' Next
85+
' tStop1 = Timer
86+
' MsgBox "???tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
87+
' Time = .53?!
88+
89+
90+
' ==== 100 Redim
91+
' tStart = Timer
92+
' For x=0 To 100
93+
' Redim y(10000000)
94+
' y(x) = x
95+
' Next
96+
' tStop1 = Timer
97+
' MsgBox "???tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
98+
' MsgBox y(4)
99+
' Time = 22
100+
' ==== 100 Redim Preserve
101+
' tStart = Timer
102+
' Redim y(0,0)
103+
' For x=0 To 1000
104+
' Redim y(x,x)
105+
' y(x,x) = x
106+
' Next
107+
' tStop1 = Timer
108+
' MsgBox "???tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
109+
' Time = 7.5
110+
111+
112+
Sub psh(byRef a, byVal v)
113+
Redim Preserve a(UBound(a)+1)
114+
a(UBound(a))=v
115+
End Sub
116+
117+
Sub psh2(byRef a, byVal v)
118+
Dim enda : enda = UBound(a)
119+
Redim Preserve a(UBound(a)*2)
120+
a(enda) = v
121+
End Sub
122+
123+
124+
'=========== Loading a Dictionary and Making Copies
125+
Function FormIn(O)
126+
Dim formi : Set formi=CreateObject("Scripting.Dictionary")
127+
For Each x In O
128+
formi.add x, O(x)
129+
Next
130+
Set FormIn = formi
131+
End Function
132+
133+
d.add "v", 2
134+
d.add "2v", 22
135+
Dim F : Set F = FormIn(d)
136+
Dim F2 : Set F2 = FormIn(d)
137+
Set d = Nothing
138+
139+
For Each x in F2.keys
140+
MsgBox F2(x)
141+
Next
142+
143+
For Each x in F2.keys
144+
F2(x) = F2(x)+4
145+
Next
146+
147+
For Each x in F2.keys
148+
MsgBox F2(x)
149+
Next
150+
151+
For Each x in F.keys
152+
MsgBox F(x)
153+
Next
154+
MsgBox TypeName(d)
155+
156+
' ReDim testManDim(10)
157+
' testManDim(1) = 1
158+
' testManDim(2) = 2
159+
' testManDim(5) = 5
160+
' testManDim(8) = 8
161+
' testManDim(10) = 10
162+
' psh testManDim, 99
163+
' psh testManDim, 11
164+
' Dim sOut : sOut = ""
165+
' For Each v IN testManDim : sout=sout&v : Next
166+
167+
' MsgBox sout
168+
' sout =""
169+
' MsgBox UBound(testManDim)
170+
' psh2 testManDim, 1
171+
' MsgBox UBound(testManDim)
172+
' Time = 0.11
173+
174+
' tStart = Timer
175+
' For x=0 To 100000
176+
' IF UBound(y) < x Then
177+
' Redim y(x)
178+
' End If
179+
' y(x) = "F("&x&")=" & x*2
180+
' Next
181+
' tStop1 = Timer
182+
' MsgBox "tStart: " & tStart & " tStop: " & tStop1 & " Diff: " & Round((tStop1 - tStart),4)
183+
' ' 101.241 Seconrds
184+
' msgBox UBound(y)

0 commit comments

Comments
 (0)