Qbasicnews.com
get/put/open - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: get/put/open (/thread-221.html)



get/put/open - Lanzaa - 02-15-2003

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:


What about those statements confuses you? - Glenn - 02-15-2003

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".


get/put/open - Neo - 02-17-2003

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...


get/put/open - audiossis - 03-04-2003

Could this be used to capture data from a device attached to com2?


get/put/open - toonski84 - 03-04-2003

why yes it can!

http://qbasicnews.com/qboho/qckadvr.opcom.shtml


get/put/open - audiossis - 03-04-2003

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)


What did that extraction from QB's on-line help... - Glenn - 03-05-2003

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



get/put/open - audiossis - 03-05-2003

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.


PEEK and POKE were doing the same thing on the C64 that... - Glenn - 03-05-2003

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.)


get/put/open - audiossis - 03-06-2003

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!!)