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!

binary files

Status
Not open for further replies.

tigerclaw

Programmer
Sep 12, 2001
15
US
i am writing a program and want to create a binary file but i do not know how
this is the syntax:
open "music.bin" for binary as #1
and i get this error:
string operand expected
let me know if you can help
thanks live life to the fullest. we only go around once.
 
I don't see anything wrong with the line you posted. Where do you get the error?

We need more code or a better description of the problem to help here.
VCA.gif
 
I found the problem. When i wrote this question I had corrected a mistake that i didnt realize until just now. but I am having a problem trying to print information from the music.bin file to the screen. Thank you for your time and patience live life to the fullest. we only go around once.
 
Is there any code that goes along with this new question? If so, you should post the section that is troubling you.
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
this is the section that is giving me the most problems
thank you for any help that you can give me

sub musView
open "music.bin" for input as #1
input #1, nam$, null$, artist$
close #1
print nam$, null$, artist$
end sub live life to the fullest. we only go around once.
 
You originally claim the file is BINARY (which is usually HEX format), and yet in this sub it's opened in INPUT (which is usually ASCI format). Hummmmmm??? Could be a problem.

if you decide to change to 'binary' then don't forget to set the storage variable's size (usually a User-Defined TYPE is best--especially if the data is of constant size). AND also change from INPUT to GET.

FROM:
open "music.bin" for [red]input[/red] as #1

TO:
open "music.bin" for [red]binary[/red] as #1

Good luck,
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
what if i had changed it to append as the output in the first question? live life to the fullest. we only go around once.
 
Ummmm...APPEND means "to add to" so it shouldn't work.

Think of it this way, (this is an example only):

You have a notebook; you place it in an envelope for safekeeping 'cause it is full of notes. Suddenly, you remember something else you wanted to add to this notebook and you write it on a separate sheet of paper, open up the envelope and you are just about to place it behind the notebook, BUT!! you suddenly think "gee, I thought I already place this note somewhere inside."

Which leads to this point: How can you APPEND this single sheet to this notebook without reading it first? Do you see the problem here with this analogy? You can't add (append) if you're going to read (input) it.


'here try this...

SUB MusView
'Open the file
OPEN "Music.bin" FOR BINARY AS 1

'create memory variables with certain
' lengths (as I had mentioned above).
'
'--Make NAM$ variable 10 characters long
Nam$ = "123456789+"

'--Make NULL$ variable 20 characters long
Null$ = "123456789+123456789+"

'--Make ARTIST$ variable 15 characters long
Artist$ = "123456789+12345"

'File pointer is already set to
' position 1 so...
'
'--store all characters from file
' positions 1 to 10 to Nam$
GET #1,,Nam$

'File pointer is already set to
' position 11 in file so...
'
'--store all characters from file
' position 11 to 30 to Null$
GET #1,,Null$

'File pointer is already set to
' positions 31 in file so...
'
'--store all characters from file
' positions 31 to 45 to Artist$
GET #1,,Artist$

'Display what was captured from binary file
'
PRINT Nam$; TAB(20); Artist$
PRINT Null$
CLOSE 1
END SUB


Here's another example you can study from. Just make sure that you have a file to open as binary...you may want to look in the help files on using the GET function (also mentioned above).

OPEN "C:\windows\win.com" FOR BINARY ACCESS READ AS 1
CLS
Dump$ = "+987654321+987654321"
FOR Cycle = 725 TO 775
GET #1, Cycle, Dump$
PRINT Dump$
SD = TIMER + .05
DO WHILE SD>TIMER
LOOP
NEXT
FOR Cycle = 2642 TO 3000
GET #1, Cycle, Dump$
PRINT Dump$
SD = TIMER + .05
DO WHILE SD>TIMER
LOOP
NEXT
CLOSE

'Good luck
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Toshi: I whole-heartedly agree. But, if you reread tigerclaw's last couple of postings (Nov. 9 & Nov. 14), you'd see that s/he is just beginning to program in QB.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top