Newbie going nuts... help!
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA
Newbie going nuts... help!
.
I got here googling and this is my first post. I was a fairly accomplished Basic programmer in the Commodore 64 days, which was M$ Basic 2.0, so I'm a little bit embarrassed by how simple my problem is, but here goes -
I need what should be an extremely simple program for the PC but I can't figure out how to make Qbasic do it. I'm using the ancient stock Qbasic that came with Windows 95, running under XP and it seems to be working fine.
I have a file of 100,025 bytes. I want to open it for reading and copy the first 100,000 bytes to a new file, then close the new file. I don't need to even look at these first 100,000 bytes, so if there's a way to do that part in a single step, great.
Next I need to fetch the remaining 25 bytes one at a time, and know the value of each one so I can act on it, and finally, close the source file.
I know this isn't proper syntax; I'm just trying to illustrate what I'm after:
OPEN "SOURCE.TXT" FOR BINARY AS #1
OPEN "DESTIN.TXT" FOR BINARY AS #2
FOR X = 1 TO 100000
GET #1,Y%
PUT #2,Y%;
NEXT X
CLOSE 2
FOR X = 1 TO 25
GET #1,Y% -or- GET #1, ,Y% -or- GET #1,X,Y%
PRINT X, Y%,
IF Y% = 0 THEN PRINT "ZERO":GOTO 1000
PRINT "GREATER THAN ZERO"
1000 NEXT X
CLOSE 1
END
Now that seems just screamingly simple! I could knock it out in thirty seconds on my old C64, but being new to Qbasic, I keep getting insane values that are greater than 255, or less than zero, when all I'm trying to do is determine the value of a single byte. The second GET line is where I've tried several different ways to confine the read to a single byte, and fetch the correct byte, but I'm just not having any kind of encouraging success at all.
Please help, and thanks!
NV
.
I got here googling and this is my first post. I was a fairly accomplished Basic programmer in the Commodore 64 days, which was M$ Basic 2.0, so I'm a little bit embarrassed by how simple my problem is, but here goes -
I need what should be an extremely simple program for the PC but I can't figure out how to make Qbasic do it. I'm using the ancient stock Qbasic that came with Windows 95, running under XP and it seems to be working fine.
I have a file of 100,025 bytes. I want to open it for reading and copy the first 100,000 bytes to a new file, then close the new file. I don't need to even look at these first 100,000 bytes, so if there's a way to do that part in a single step, great.
Next I need to fetch the remaining 25 bytes one at a time, and know the value of each one so I can act on it, and finally, close the source file.
I know this isn't proper syntax; I'm just trying to illustrate what I'm after:
OPEN "SOURCE.TXT" FOR BINARY AS #1
OPEN "DESTIN.TXT" FOR BINARY AS #2
FOR X = 1 TO 100000
GET #1,Y%
PUT #2,Y%;
NEXT X
CLOSE 2
FOR X = 1 TO 25
GET #1,Y% -or- GET #1, ,Y% -or- GET #1,X,Y%
PRINT X, Y%,
IF Y% = 0 THEN PRINT "ZERO":GOTO 1000
PRINT "GREATER THAN ZERO"
1000 NEXT X
CLOSE 1
END
Now that seems just screamingly simple! I could knock it out in thirty seconds on my old C64, but being new to Qbasic, I keep getting insane values that are greater than 255, or less than zero, when all I'm trying to do is determine the value of a single byte. The second GET line is where I've tried several different ways to confine the read to a single byte, and fetch the correct byte, but I'm just not having any kind of encouraging success at all.
Please help, and thanks!
NV
.
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Because Integer variables hold 2 bytes you need a string for 1 byte.
GET and PUT use a placeholder like: GET #1, placeholder, variable
You can skip the placeholder value, but not the commas.
GET #1, , y where y is defined as: DIM y AS STRING * 1 ' fixed length byte
Another way:
Using the file OPEN FOR INPUT number AS #1:
However QB can only do 32767 bytes at a time, so you will need a loop to get it 4 times at 25000 bytes at a time.
GET and PUT use a placeholder like: GET #1, placeholder, variable
You can skip the placeholder value, but not the commas.
GET #1, , y where y is defined as: DIM y AS STRING * 1 ' fixed length byte
Another way:
Using the file OPEN FOR INPUT number AS #1:
Code: Select all
IF LOF(1) >= 100000 THEN ' the length of the opened file is big enough
FOR i = 1 TO 4
data$ = INPUT$(25000, 1) ' byte syntax for files and ports
PRINT #2, data$ ' copy data to another file #2
NEXT
END IF
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA
.
Hi burger2227, thanks for the reply.
I had mine at OPEN FOR BINARY and got an OUT OF STRING SPACE error. I then noticed you said to use
OPEN FOR INPUT number AS #1
So I changed my BINARY to INPUT and now I get an INPUT PAST END OF FILE error with DATA$ highlighted in "DATA$ = INPUT$(25000, 1)". I get this on the first pass, before it writes anything to file #2. All I changed was to add a semicolon after PRINT #2, DATA$ so it wouldn't add the $0D $0A bytes, but it still returns the error with or without the semicolon.
Now the only thing I can see that I don't understand is the word "number" in your example:
OPEN FOR INPUT number AS #1
I have
OPEN "FILE.DAT" FOR INPUT AS #1
so I don't see what the word "number" in your example means. Please explain.
.
Hi burger2227, thanks for the reply.
I had mine at OPEN FOR BINARY and got an OUT OF STRING SPACE error. I then noticed you said to use
OPEN FOR INPUT number AS #1
So I changed my BINARY to INPUT and now I get an INPUT PAST END OF FILE error with DATA$ highlighted in "DATA$ = INPUT$(25000, 1)". I get this on the first pass, before it writes anything to file #2. All I changed was to add a semicolon after PRINT #2, DATA$ so it wouldn't add the $0D $0A bytes, but it still returns the error with or without the semicolon.
Now the only thing I can see that I don't understand is the word "number" in your example:
OPEN FOR INPUT number AS #1
I have
OPEN "FILE.DAT" FOR INPUT AS #1
so I don't see what the word "number" in your example means. Please explain.
.
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
My bad, INPUT$ cannot hold a string that large apparently. I was just saying to use the open file number with INPUT$.
File or port Syntax: INPUT$(numberofbytes, filenumber)
Using GET and PUT: Without placeholder work consecutive bytes.
GET can read past the end of a file and give PUT bad data.
File or port Syntax: INPUT$(numberofbytes, filenumber)
Code: Select all
OPEN file1$ FOR INPUT AS #1
OPEN file2$ FOR OUTPUT AS #2
IF LOF(1) >= 100000 THEN ' the length of the opened file is big enough
FOR i = 1 TO 50
IF EOF(1) THEN EXIT FOR
data$ = INPUT$(2000, 1) ' byte syntax for files and ports
PRINT #2, data$; ' use semicolon like you said
NEXT
END IF
CLOSE ' closes all open files
Code: Select all
DIM dat AS STRING * 1 ' one byte of the file
OPEN File1$ FOR BINARY AS #1
OPEN File2$ FOR BINARY AS #2
IF LOF(1) >= 100000 THEN
FOR i = 1 TO 100000
GET #1, , dat
IF EOF(1) THEN EXIT FOR ' checks for good GET data before PUT
PUT #2, , dat
NEXT
END IF
CLOSE
Last edited by burger2227 on Sat Dec 26, 2009 8:23 pm, edited 1 time in total.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA
.
All I get is "Input past end of file". I went from [50 x 2000] to [500 x 200] and several stages in between and it just doesn't work. I can do it byte by byte but it takes ten or fifteen seconds so a quicker way to do it in bigger chunks would be nice!
I'm guessing that "PRINT #2, datab$;" is a typo, still, I tried it both ways and no dice:
This happens before anything is written to #2. I use immediate mode to check i and it always happens on the very first pass, while i = 1.
I think I'm doing everything exactly as instructed!
.
All I get is "Input past end of file". I went from [50 x 2000] to [500 x 200] and several stages in between and it just doesn't work. I can do it byte by byte but it takes ten or fifteen seconds so a quicker way to do it in bigger chunks would be nice!
I'm guessing that "PRINT #2, datab$;" is a typo, still, I tried it both ways and no dice:
This happens before anything is written to #2. I use immediate mode to check i and it always happens on the very first pass, while i = 1.
I think I'm doing everything exactly as instructed!
.
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
I don't have Qbasic 2, but it runs in Qbasic 1.0 and Quickbasic 4.5. Perhaps it's time to upgrade to 4.5.
You might also like to try QB64. It will work on 64 bit machines as well.
See the link in my signature.
Ted
You might also like to try QB64. It will work on 64 bit machines as well.
See the link in my signature.
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA
.
I should have been more clear: the "ancient stock Qbasic that came with Windows 95" I mentioned is 1.1 which I got from Microsoft's website.
I went googling on 4.5 and most of the first page of hits are people complaining about it not working right under XP, so I think I'd better do without it for now.
I don't get QB64; is it a compiler to make .bas files into .exe programs that don't need Qbasic to run? Gotta remember, I'm absolutely new to all this, as in, I first fired up Qbasic and undertook this task less than 24 hours ago! At any rate, I have the function I wanted, in a quarter million steps that take ten seconds or so, and I can live with that and move on if need be. It's a better option for me than undertaking another learning curve at this time.
So, if anyone can show me how to chop those first 100,000 bytes off into a new file a lot more quickly, still using ancient 1.1, I'll appreciate it, otherwise I'll leave it as it is. I have the 25 byte analysis working perfectly, by the way.
Thanks again for your help.
NV
.
I should have been more clear: the "ancient stock Qbasic that came with Windows 95" I mentioned is 1.1 which I got from Microsoft's website.
I went googling on 4.5 and most of the first page of hits are people complaining about it not working right under XP, so I think I'd better do without it for now.
I don't get QB64; is it a compiler to make .bas files into .exe programs that don't need Qbasic to run? Gotta remember, I'm absolutely new to all this, as in, I first fired up Qbasic and undertook this task less than 24 hours ago! At any rate, I have the function I wanted, in a quarter million steps that take ten seconds or so, and I can live with that and move on if need be. It's a better option for me than undertaking another learning curve at this time.
So, if anyone can show me how to chop those first 100,000 bytes off into a new file a lot more quickly, still using ancient 1.1, I'll appreciate it, otherwise I'll leave it as it is. I have the 25 byte analysis working perfectly, by the way.
Thanks again for your help.
NV
.
'ancient' Qb 1.1 should be just as capable of doing this as 4.5, but 4.5 has more features such as compiling programs and using the command line with them. Qb45 works fine for me under windows XP as I use it all the time for ompiling my code. I still prefer to do my coding in 11 because it is simpler and smaller and I am more used to it.
I have tried qb64, and it is your best alternative for windows vista. It appears to compile your programs when you run them, but they dont seem to work without qb64.
I have tried qb64, and it is your best alternative for windows vista. It appears to compile your programs when you run them, but they dont seem to work without qb64.
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Well, it worked for me, so what can I say? I used a BAS file over 100K and it copied everything flawlessly to a TXT file in both instances. The GET PUT routine took less than 10 seconds.
There are some XP computers that are 64 bit and others may not run fullscreen graphic SCREEN modes 1 to 2 and 7 to 13. There is a video driver fix for most of those problems. QB45 is downloadable from the Member Files section at: www.qbasicstation.com
QB64 is simply a Qbasic compiler that can create EXE files to run on a 64 bit machine. Currently the compiler is only 32 bit, but that will be changed to 32/64 bit compatabilty soon.
There are some XP computers that are 64 bit and others may not run fullscreen graphic SCREEN modes 1 to 2 and 7 to 13. There is a video driver fix for most of those problems. QB45 is downloadable from the Member Files section at: www.qbasicstation.com
QB64 is simply a Qbasic compiler that can create EXE files to run on a 64 bit machine. Currently the compiler is only 32 bit, but that will be changed to 32/64 bit compatabilty soon.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Found some more info on INPUT$.
1) With BINARY files INPUT$ can use up to 32767 bytes. I'd use a max of 30000.
2) RANDOM files can use the LEN = recordlength statement bytes. If no record statement is used, max bytes = 128
No data on files opened for INPUT. So try BINARY mode instead.
1) With BINARY files INPUT$ can use up to 32767 bytes. I'd use a max of 30000.
2) RANDOM files can use the LEN = recordlength statement bytes. If no record statement is used, max bytes = 128
No data on files opened for INPUT. So try BINARY mode instead.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA
-
Just one last checkin to see if anyone can tell me how to copy 100,000 bytes in bigger chunks, using QB 1.1 and nothing else. One byte at a time takes ten seconds or so and I can live with that if need be, but if I could do it instantly in four chunks or whatever that would be cool too.
At any rate, thanks to everyone who replied to help.
NV
-
Just one last checkin to see if anyone can tell me how to copy 100,000 bytes in bigger chunks, using QB 1.1 and nothing else. One byte at a time takes ten seconds or so and I can live with that if need be, but if I could do it instantly in four chunks or whatever that would be cool too.
At any rate, thanks to everyone who replied to help.
NV
-
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Sent you a PM
Ted
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- NeonVincent
- Coder
- Posts: 10
- Joined: Sat Dec 26, 2009 4:38 am
- Location: Montana, USA