|
| 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