Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Reading binary files


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-25-2008, 09:38 AM
jgm jgm is offline
Newbie
 
Join Date: May 2008
Location: Lisbon
Posts: 6
Default Reading binary files

Hi,
I need to read a dbase III file (*.dbf), change a few records and write it back.
As I do not know a better way to do it, I'm trying to open it as a binary file,
I tried reading help on binary files but couldn't get what I need to know.
Question1:
I managed to read one file, in binary mode, using ReadBytes, but got an error message when trying to assign what I read to a string using BytesToString (help file says BytesToString returns a string):
length = bin.ReadBytes(buffer(),5)
Version = bin.BytesToString(buffer(),1,3)
What am I missing?

Question2:
I have a text file that has just two chars "AB".
A is ASCII 65 (41HEX) and B is ASCII 66 (42HEX).
I read the file in binary mode using
in_data = bin.ReadInt16
and printed in_data in a MsgBox; got the decimal value 16961, which means (I think) that those bytes are dealt in reverse order "BA", otherwise I would get for "AB" = 41HEX 42HEX = 16706 decimal.
Is that so, I mean, are bytes in binary numbers written in reverse order?
Reply With Quote
  #2 (permalink)  
Old 05-25-2008, 11:18 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by jgm View Post
What am I missing?
Might be useful to know what the error message and byte data was?
Quote:
Is that so, I mean, are bytes in binary numbers written in reverse order?
Yes, numerics are usually written least significant byte first (on Wintel systems at least).
EDIT : That is true of binary numerics. I seem to remember (dredges deeply!) that in dBase files numerics are actually stored as strings.

Last edited by agraham : 05-25-2008 at 11:24 AM.
Reply With Quote
  #3 (permalink)  
Old 05-25-2008, 12:55 PM
jgm jgm is offline
Newbie
 
Join Date: May 2008
Location: Lisbon
Posts: 6
Default

The file I'm reading is a text file with five chars "ABCDEF".

I believe I found what was happening.
I assigned what I read to a variable named Version and I got the message:
"Error compiling program.
Error description: Illegal first word in line.
Occured on line: 37
Version= bin.BytesToString(buffer(),1,3)"

Version must be a reserved word because after changing variable's name to VVersion I got no more error messages.

Thank you for your help.
Reply With Quote
  #4 (permalink)  
Old 05-28-2008, 09:01 AM
jgm jgm is offline
Newbie
 
Join Date: May 2008
Location: Lisbon
Posts: 6
Default More than one Binary File open at the same time?

Is it possible to have more than one Binary File open at the same time, for example, one for reading and the other for writing?

If so, how can you tell which file you are referring to when using instructions like:
bin.Position
bin.ReadBytes
...
Reply With Quote
  #5 (permalink)  
Old 05-28-2008, 09:24 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 707
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

You must define 2 binary file objects like and open the 2 files.

Code:
  FileOpen(c1,file,cRandom)
  bin1.New1(c1,false)

  FileOpen(c2,file,cRandom)
  bin2.New1(c2,false)
This should work.

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #6 (permalink)  
Old 05-28-2008, 11:09 AM
jgm jgm is offline
Newbie
 
Join Date: May 2008
Location: Lisbon
Posts: 6
Default

It worked fine.
Thank you for your help.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coverting text files with binary file page code functionality kolbe Code Samples & Tips 1 06-21-2008 06:06 PM
Using Binary.dll... how to? Rod Questions & Help Needed 9 12-17-2007 02:24 PM
Binary files on device Ianmac Questions & Help Needed 4 08-24-2007 08:49 AM
Binary File problem Ianmac Questions & Help Needed 3 08-07-2007 06:44 PM
Binary Files- Love'm and sometimes confused XerVision Questions & Help Needed 2 06-10-2007 08:55 PM


All times are GMT. The time now is 03:34 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0