compguru
asked on
Binary File
Experts,
Currently i am writing a program that opens a file as binary and it needs to input each byte and adjust it to 3 characters long (e.g. if the byte is < 10 then add 2 zeros to the front of the number). Currently i use the get statement to do this...the problem i have run into is that it takes so increadibly long to load the file. Is there a quicker (much quicker preferably) way to do this? Let me know...thanks! Oh ya...sorry for the small ammount of points...i don't have many because i'm new.
Currently i am writing a program that opens a file as binary and it needs to input each byte and adjust it to 3 characters long (e.g. if the byte is < 10 then add 2 zeros to the front of the number). Currently i use the get statement to do this...the problem i have run into is that it takes so increadibly long to load the file. Is there a quicker (much quicker preferably) way to do this? Let me know...thanks! Oh ya...sorry for the small ammount of points...i don't have many because i'm new.
Hi,
Can you also Mail me a copy of your code please and a sample of you file if possible.
Thanks,
T.
Can you also Mail me a copy of your code please and a sample of you file if possible.
Thanks,
T.
ASKER
Dim string1(10000) As String
Open "c:\windows\desktop\test.e xe" For Binary As #1
ProgressBar1.Max = FileLen("c:\windows\deskto p\test.exe ") + 1
'Input
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
If CInt(tst) < 10 Then string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & "00" Else If CInt(tst) < 100 Then string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & "0"
string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & CInt(tst)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
Open "c:\windows\desktop\test.e
ProgressBar1.Max = FileLen("c:\windows\deskto
'Input
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
If CInt(tst) < 10 Then string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & "00" Else If CInt(tst) < 100 Then string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & "0"
string1((len1 - 1) / 3000) = string1((len1 - 1) / 3000) & CInt(tst)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
ASKER
forgot this....
Dim tst As Byte
Dim tst As Byte
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For a start I would simplify the if statement a bit,
string1(len1 - 1) / 3000) = right("000" & trim(cstr(tst)),3)
should accomplish the task of prefixing with one or two zeros.
string1(len1 - 1) / 3000) = right("000" & trim(cstr(tst)),3)
should accomplish the task of prefixing with one or two zeros.
ASKER
This seems to be causing an error....suggestions....?
------
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
ival = string1((len1 - 1) / 3000)
If CInt(tst) < 10 Then string1(ival) = string1(ival) & "00" Else If CInt(tst) < 100 Then string1(ival) = string1(ival) & "0"
string1(ival) = string1(ival) & CInt(tst)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
------
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
ival = string1((len1 - 1) / 3000)
If CInt(tst) < 10 Then string1(ival) = string1(ival) & "00" Else If CInt(tst) < 100 Then string1(ival) = string1(ival) & "0"
string1(ival) = string1(ival) & CInt(tst)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
TimCottee, Yes, that too!
;-)
;-)
Actually, that line:
iVal = string1((len1 - 1) / 3000)
Should have been:
iVal = (len1 - 1) / 3000)
(cut-n-paste booboo!)
Cheers!
iVal = string1((len1 - 1) / 3000)
Should have been:
iVal = (len1 - 1) / 3000)
(cut-n-paste booboo!)
Cheers!
Dang! did it again... should be:
iVal = (len1 - 1) / 3000
Cheers!
iVal = (len1 - 1) / 3000
Cheers!
ASKER
how would i implement TimCottee's response?
ASKER
mcrider...i got yours done...your definately getting some points for that! :)
ASKER
I have one more question....i tried loading a larger file (1mb about). Is there any possible way to load that quicker? I don't care if it involves completely changing my code around (as long as it does the same thing)..but i really would like to be able to speed that loading time up.
Tims solution would be implemented like this:
Dim string1(10000) As String
Open "c:\windows\desktop\test.e xe" For Binary As #1
ProgressBar1.Max = FileLen("c:\windows\deskto p\test.exe ") + 1
'Input
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
string1((len1 - 1) / 3000) = Right$("000" & Trim(CStr(tst)), 3)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
Cheers!
Dim string1(10000) As String
Open "c:\windows\desktop\test.e
ProgressBar1.Max = FileLen("c:\windows\deskto
'Input
For len1 = 1 To 200000000 Step 3000
For z = 0 To 2999
Get #1, len1 + z, tst
string1((len1 - 1) / 3000) = Right$("000" & Trim(CStr(tst)), 3)
If EOF(1) Then Exit For
Next z
ProgressBar1.Value = len1 + z
If EOF(1) Then Exit For
Next len1
Close #1
Cheers!
By the way, Tim's solution was missing a parenthesis...
Cheers!
Cheers!
ASKER
so do you have any more suggestions to speed up this process?
To do anything any faster, you'd have to leave the VB environment and do something in C...
Cheers!
Cheers!
Thanks for the points! Glad I could help!
Cheers!
Cheers!
Sorry about the missing parenthesis, I just typed it out and didn't check it.
Cheers!