Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Binary File

Posted on 2000-02-15
19
Medium Priority
?
181 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:compguru
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 2
  • +1
19 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2523335
Post the snippet of code that you're currently using...


Cheers!
0
 
LVL 15

Expert Comment

by:lyonst
ID: 2523396
Hi,

Can you also Mail me a copy of your code please and a sample of you file if possible.

Thanks,

T.
0
 

Author Comment

by:compguru
ID: 2523397
Dim string1(10000) As String

 Open "c:\windows\desktop\test.exe" For Binary As #1
 ProgressBar1.Max = FileLen("c:\windows\desktop\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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:compguru
ID: 2523408
forgot this....

 Dim tst As Byte
0
 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2523492
instead of doing this 6 times in the above code:

   string1((len1 - 1) / 3000)

Do this right after the GET:

   iVal = string1((len1 - 1) / 3000)

Then replace all of the "string1((len1 - 1) / 3000)" with:

   string1(iVal)


That should speed your program quite a bit...


Cheers!
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2523493
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.
0
 

Author Comment

by:compguru
ID: 2523561
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
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523565
TimCottee, Yes, that too!

;-)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523581
Actually, that line:

   iVal = string1((len1 - 1) / 3000)

Should have been:

   iVal = (len1 - 1) / 3000)


(cut-n-paste booboo!)


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523583
Dang! did it again... should be:

   iVal = (len1 - 1) / 3000


Cheers!
0
 

Author Comment

by:compguru
ID: 2523591
how would i implement TimCottee's response?
0
 

Author Comment

by:compguru
ID: 2523596
mcrider...i got yours done...your definately getting some points for that! :)
0
 

Author Comment

by:compguru
ID: 2523633
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.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523691
Tims solution would be implemented like this:

Dim string1(10000) As String

 Open "c:\windows\desktop\test.exe" For Binary As #1
 ProgressBar1.Max = FileLen("c:\windows\desktop\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!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523698
By the way, Tim's solution was missing a parenthesis...


Cheers!
0
 

Author Comment

by:compguru
ID: 2523713
so do you have any more suggestions to speed up this process?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2523788
To do anything any faster, you'd have to leave the VB environment and do something in C...


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2524065
Thanks for the points! Glad I could help!


Cheers!
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2526230
Sorry about the missing parenthesis, I just typed it out and didn't check it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question