Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get/put/open
#1
uhh i need help with figuring out the get put and open commands, and i cant fugure out the manual so plz help lol. googles being mean. and the manual hates me :oops:
Reply
#2
By "GET" and "PUT", do you mean "GET#"and "PUT#", as opposed to the graphics GET and PUT statements? They're used when you open a file FOR BINARY or FOR RANDOM. Let's say you want to read two bytes from "MYFILE.BIN" at byte #6 into the INTEGER variable A:

DIM A AS INTEGER
OPEN "MYFILE.BIN" FOR BINARY AS #1
GET#1, 6, A
CLOSE #1

To write A to the file, change the "GET" to "PUT". Note that GET and PUT read/write the number of bytes associated with the type of variable you're using. That makes binary file I/O somewhat more "difficult" than sequential file I/O, where you can generally ignore "variable storage details".
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
You can just store any data available in the file into a variable.

E.g. you have this file:
MYDATA.DAT
Code:
1234567890abcdefghijklmnñopqrstuvwxyz

To store the first 26 bytes into a string, see this code:
Code:
OPEN "MYDATA.DAT" FOR BINARY AS #1
   mystr$ = SPACE$(26)
   GET #1, 1, mystr$
CLOSE #1
PRINT mystr$

To get the first 2 bytes in an integer (INTEGER = 2 BYTES):
Code:
OPEN "MYDATA.DAT" FOR BINARY AS #1
   myint% = 0
   GET #1, 1, myint%
CLOSE #1

You can do the same with long ints, singles etc...
Reply
#4
Could this be used to capture data from a device attached to com2?
ide to live, Live to ride!!
Reply
#5
why yes it can!

http://qbasicnews.com/qboho/qckadvr.opcom.shtml
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#6
The reason I ask is I'm trying to write a program to test a serial printer (pretty archaic devices too I might add!!)

The first part of the test involves printing a series of characters to the printer to test to print quality of the machine.
using the code:

open "com2:9600,n,8,1" for random as #1
Print #1, chr$(13)

so and so forth.....

But I also need to conduct a "LOOPBACK" test, to ascertain to condition of the RS232 comm's I.C. in the printer.

The printer actually generates the test but I need the program to automatically detect that the test has been run and display the data captured on the screen with a results message.

somthing like:

select case a$
case a$ = "12345"
print "Loopback Test detected"
print "Data Captured:-" 'code to display captured data here
case a$ <> "12345"
print "Loopback Test FAILED"
end select

please forgive any syntax errors, I'm trying to remeber all the BBC BASIC I learned as a kid with a C64 (and haven't used in 15 years)
ide to live, Live to ride!!
Reply
#7
have to do with capturing output to a serial port? Smile (I have a TSR that will actually do that, but it won't work if windows is running and it won't work with QB because QB writes to COM ports directly, i.e., without using the bios.)

Quote:why yes it can!

http://qbasicnews.com/qboho/qckadvr.opcom.shtml
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#8
I'm sorry maybe I wasn't clear enough, the question I meant to ask was: what additions to the above code would I need to use to capture data at com2. A Terminate and Stay program like that would be usefull but it's not exactly what I need as I need the program to output specific character strings to printer as well as capture incomming data and display it.

Do I have to DIM an ARRAY to do this? I have absolutly no idea, as I said earlier I haven't use any form of BASIC in 15 years, and the BASIC I did learn was nothing like QBASIC.

For example, in the BBC/C64 BASIC that I learned, PEEK and POKE codes were used to change the screen colours (among other things), I have never seen them used the way QBASIC applies them.
ide to live, Live to ride!!
Reply
#9
they do with QB and Qbasic. It's just that the C64 insisted that you change screen colors by altering the contents of specific memory locations (which is what POKE does) and "PCs" don't work that way. If all you want is to write data to a COM port and read data from it, well, the link toonski posted should be useful. I put a routine at

http://www.geocities.com/gstumpff/Glenns_Page.html

that demonstrates one method of reading data from a COM port. (I just can't remember right now what I called it, but there are descriptions there that say what the files do.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#10
THANX HEAPS GUYS!!
I will check out the links you have suggested and get back to you!!
By the way.....great web site!! :bounce: .... It's the best and most informative Qbasic site I have so far found. I'll be returning here quite often I think, to ask more dumb questions!! (you'll probably get sick of me after a while!!)
ide to live, Live to ride!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)