Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which code is faster?

Status
Not open for further replies.

snorkle

Programmer
Apr 10, 2001
16
US
is it faster to have a byte array and use leftb$,rightb$,midb$ etc., or to have a string and use left$,right$ etc... ?


why is it faster to use the $ /w those commands?
 
If you want string processing use MID$, LEFT$ which return strings (not MID ,LEFT which return Variants). Use byte processing only for binary data encoded in strings e.g. BLOBs, images from a database. Each VB string character is two bytes of Unicode data so if you process it as byte, you better know what you are doing.
 
john - thank you for your response. i never noticed they returned variants. :)

what i am doing is loading a file into a byte array. then i wanted to assign different sections of that array to other arrays. i'm doing that like this:

dim b1() as byte
dim b2() as byte
dim f as long
Dim f As Long
f = FreeFile
Open "c:\something" For Binary As #f
ReDim b1(LOF(f))
Get #f, , b1
Close #f
b2 = MidB(b1, 10, 5)

is it faster to use the arrays like this, or to use strings in a simular way?
 
I do not know what kind of binary data you have. if it is truly ASCII characters then read it into a string. If not, you are better off staying in the byte array. Look at StrConv function. It does a lot of stuff I'd rather not mess with as far as Unicode. If you have character data go with strings. Look also at AscW and ChrW.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top