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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading bytes from a Binary File

Status
Not open for further replies.

egstatus

Programmer
Apr 14, 2005
143
US
I Am trying to read bytes from a binary file

VB6 Code

Dim bTest1() As Byte
Dim hFile As Long
hFile = FreeFile
Open (sNewFile) For Binary As hFile
'btest1 is the byte array containing all the files data
'LOF(1) return the length of the file -
'in our case 1 represent the file handle
ReDim bTest1(LOF(1))
Get #1, , bTest1

'Get Stdjob Name stored in bytes 302 -311
For i = 302 To 311
strStdJob = strStdJob & Chr$(bTest1(i))
Next i

close #1

When this code executes strStdJob contain = 'STYLES' which is the name stored in bytes 302 to 311 of the binary file.


VB.NET 2008 Code

FileOpen(hFile, (sNewFile), OpenMode.Binary)
ReDim bTest1(LOF(1))
FileGet(1, bTest1)

For i = 302 To 311
strStdJob = strStdJob & Chr(bTest1(i))
Next i

FileClose(1)

When I execute this code in vb.net 2008 strStdJob is null or empty. why?

One thing I found is the Chr$ does not exist in vb.net

How do I transalete the above vb 6 code to vb.net

Thanks in advance

Ed
 
Try:

For i = 302 To 311
strStdJob [red]&= bTest1(i).ToString()[/red]
Next i

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
When I run the code with:
For i = 302 To 311
strStdJob &= bTest1(i).ToString()
Next i

strStdJob has a value of '0000000000' which is wrong. It should be 'STYLES'.

Again if I use vb 6, it returns the correct answer, but in vb.net it does not. What Am I doing wrong?

Thanks

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top