![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | array mid function :) Here is a new sub named aMid. (written today). Like the normal Mid: mid("abc",1,2) this new one takes an array instead Benny Pedersen, www.fineraw.com Example: dim arr: arr= split("a b c") aMid arr,1,2 msgBox """" & join(arr) & """" sub aMid(byRef a, byVal M1, byVal M2) dim b:b= uBound(a)+2-M2-M1: b= M2-1-(b<0)*b a= split(split(join(a,chr(0)),chr(0),M1,0)(M1-1),chr(0),M2+1,0) reDim preServe a(b) end sub |
My System Specs![]() |
| | #2 (permalink) |
| | Re: array mid function :) On Dec 13, 4:53*pm, Benny Pedersen <b.peder...@xxxxxx> wrote: Quote: > Here is a new sub named aMid. (written today). > > Like the normal Mid: mid("abc",1,2) > this new one takes an array instead > > Benny Pedersen,www.fineraw.com > > Example: > > dim arr: arr= split("a b c") > > aMid arr,1,2 > msgBox """" & join(arr) & """" > > sub aMid(byRef a, byVal M1, byVal M2) > * dim b:b= uBound(a)+2-M2-M1: b= M2-1-(b<0)*b > * a= split(split(join(a,chr(0)),chr(0),M1,0)(M1-1),chr(0),M2+1,0) > * reDim preServe a(b) > end sub "aMid(Array,X,Y)" should be written better than the normal "Mid(String, X, Y)", like this: sub aMid(byRef A,byVal X,byVal Y)_ dim B:B= uBound(A) +1: if X<1or X>B then reDim A(0): exit sub' A= split(split(join(A,chr(0)),chr(0),X,0)(X-1),chr(0),Y+1,0):_ B= B +1 -Y -X: B= Y -1 -(B<0)*B: reDim preServe A(-B*(Y>-1)):_ end sub Benny Pedersen, www.fineraw.com (my photo gallery) E-mail is outdated. instead use: firstname+dot+lastname gmail.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: array mid function :) On Dec 14, 3:09*am, Benny Pedersen <b.peder...@xxxxxx> wrote: Quote: > On Dec 13, 4:53*pm, Benny Pedersen <b.peder...@xxxxxx> wrote: > > > > > Quote: > > Here is a new sub named aMid. (written today). Quote: > > Like the normal Mid: mid("abc",1,2) > > this new one takes an array instead Quote: > > Benny Pedersen,www.fineraw.com Quote: > > Example: Quote: > > dim arr: arr= split("a b c") Quote: > > aMid arr,1,2 > > msgBox """" & join(arr) & """" Quote: > > sub aMid(byRef a, byVal M1, byVal M2) > > * dim b:b= uBound(a)+2-M2-M1: b= M2-1-(b<0)*b > > * a= split(split(join(a,chr(0)),chr(0),M1,0)(M1-1),chr(0),M2+1,0) > > * reDim preServe a(b) > > end sub > Hmm, after more testing, I decided that > "aMid(Array,X,Y)" should be written better > than the normal "Mid(String, X, Y)", like this: > > sub aMid(byRef A,byVal X,byVal Y)_ > * dim B:B= uBound(A) +1: if X<1or X>B then reDim A(0): exit sub' > * A= split(split(join(A,chr(0)),chr(0),X,0)(X-1),chr(0),Y+1,0):_ > * B= B +1 -Y -X: B= Y -1 -(B<0)*B: reDim preServe A(-B*(Y>-1)):_ > end sub > > Benny Pedersen,www.fineraw.com(my photo gallery) > E-mail is outdated. instead use: firstname+dot+lastname gmail.com- Hide quoted text - > > - Show quoted text - ' Oops, forgot to test some of the numbers below zero. ' Benny Pedersen, ' PS. The code for testing is now included: option explicit sub aMid(byRef A,byVal X,byVal Y) dim B:B= uBound(A) +1 if X<1 or Y<1 or X>B then reDim A(0): exit sub' A= split(split(join(A,chr(0)),chr(0),X,0)(X-1),chr(0),Y+1,0) B= B +1 -Y -X: B= Y -1 -(B<0)*B: reDim preServe A(B) end sub '// Testing aMid: sub BeginCScript(debug, maxWin) if wScript.arguments.count<>1 then createObject("wScript.shell").run"cScript.exe //nologo" _ & left(" //d", -4 * debug) & " """_ & wScript.scriptFullName &""" ""!""", 1-maxWin*2, false wScript.quit end if end sub BeginCScript true, true dim m1,m2, s, arr s= "a b c d" arr= split(s) wScript.echo string(18," ") & """" & join(arr) & """" for m1= -2 to 5: wScript.echo string(80,"_") for m2= -2 to 5 arr= split(s) aMid arr, m1, m2 wScript.echo "aMid(arr," & m1 & "," & m2 & ") is: """ &_ join(arr) & """" & vbLf next next msgBox "End of Test" & vbLf & s, 4096, " "wScript.quit |
My System Specs![]() |
| | #4 (permalink) |
| | Re: array mid function :) "Benny Pedersen" <b.pedersen@xxxxxx> wrote in message news:902c9084-f6f5-47fe-b0b8-8ac33046fc8c@xxxxxx On Dec 14, 3:09 am, Benny Pedersen <b.peder...@xxxxxx> wrote: Quote: > On Dec 13, 4:53 pm, Benny Pedersen <b.peder...@xxxxxx> wrote: > Quote: > > Here is a new sub named aMid. (written today). Quote: > > Like the normal Mid: mid("abc",1,2) > > this new one takes an array instead Quote: > > Benny Pedersen,www.fineraw.com > Hmm, after more testing, I decided that > "aMid(Array,X,Y)" should be written better > than the normal "Mid(String, X, Y)", like this: > > sub aMid(byRef A,byVal X,byVal Y)_ > dim B:B= uBound(A) +1: if X<1or X>B then reDim A(0): exit sub' > A= split(split(join(A,chr(0)),chr(0),X,0)(X-1),chr(0),Y+1,0):_ > B= B +1 -Y -X: B= Y -1 -(B<0)*B: reDim preServe A(-B*(Y>-1)):_ > end sub > > Benny Pedersen,www.fineraw.com(my photo gallery) > E-mail is outdated. instead use: firstname+dot+lastname gmail.com- Hide Quote: > > - Show quoted text - ' Benny Pedersen, ' PS. The code for testing is now included: Thinking aloud? |
My System Specs![]() |
| | #5 (permalink) |
| | Re: array mid function :) On Dec 14, 10:47*am, "Monitor" <nos...@xxxxxx> wrote: ....SNIP... Quote: > ' Oops, forgot to test some of the numbers below zero. > ' Benny Pedersen, > ' PS. The code for testing is now included: > > Thinking aloud? only the numbers above zero would make some sense (obvious)... The aMid procedure was written for speed testing some other code, but failed to speed up the single array version of BennySort. sub BennySort(byRef arr, iBegin) dim e, H, A, L, i, u: u= uBound(arr) if iBegin<1 then reDim preServe arr(u+1): arr(u+1)= arr(0)' for i= 2 to u -(iBegin<1): H= i: A= i\2: L= 0 e= arr(H) do: if e < arr(A) then H= A else L= A end if: A= (L+H)\2 loop until A=L for H= i to H +1 step-1 arr(H)= arr(H-1) next: arr(H)= e next if iBegin<1 then for i= 0 to u: arr(i)= arr(i+1): next: _ reDim preServe arr(u)' end sub ' Note: The argument iBegin should be 0 or 1. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Logon script - function array and select case not working | VB Script | |||
| VBscript Array Split Function | VB Script | |||
| Fast copy method of sub array (=array range) possible? | VB Script | |||
| Stupid Array Tricks: Initializing an Array to a Certain Size | PowerShell | |||
| adding function return to an array | PowerShell | |||