HELP! ATTACKING COMMAS!!!!!!!!!!!!!!!!!!!!!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

HELP! ATTACKING COMMAS!!!!!!!!!!!!!!!!!!!!!

Post by bongomeno »

HELLO QBWORLD!

me and my friend are workin' on a new project....
a programming language dedicated to creating denial of service viruses.
it is called DCODE for denial code.
it outputs c++ code that can be compiled.

i am currently having a problem.

when I use 'PRINT #filenum, somecrap$' and there is a comma in the string it only prints the half before the comma. in other words it only prints the 1st half before the comma.

is there any way i can get around this???

btw...

if yall r interested in this, any questions or comments r nice.
or if ya wanna c our code, just ask!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Post your code please.

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
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

heeeelp! the beep dont stop!

Post by bongomeno »

example:

open "foo.poo" for output as #1
print #1, "this half before the comma will be printed, this half wont..."
close #1

it cuts off anything after the comma... :(

im unable to post the code because im replying to this on my psp and also dont have the file on me but ill post my code asap.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

THAT code works fine! You musta did something else. Commas, apostrophies and semicolons must be INSIDE the quotation marks of the actual string. Outside of the string, they format the print or comment code. Commas are like Tabs while semicolons are used to stop the cursor at that point and perhaps grab something else printed after it.

When using PRINT #, the only ASCII character required is for quotation marks. Say you make a program to write another QB procedure:

Code: Select all

 PRINT #1, "PRINT "; CHR$(34); "Print a string, now."; CHR$(34) 
The result in the file is: PRINT "Print a string, now."

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
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

ding dang commas

Post by bongomeno »

i got all that stuff down,
but the actual problem i am having is that when im reading or writing to a file the comma within the quotes messes it up.

i have found an error in my parser that might have been causing this....
so i think it may work now
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

When you open a file for input, commas are treated as newline characters (although the actual input variable doesn't get the newline AFAIK), which can be a pain. However, outputting a string with a comma inside should be just fine.

Code: Select all

DIM file AS STRING
DIM text AS STRING

'file name
file = "test.txt"
text = "Hello, world"

'Send text out
OPEN file FOR OUTPUT AS #1
PRINT #1, text
CLOSE #1

'Now read text from disk
OPEN file FOR INPUT AS #1
INPUT #1, text
PRINT text
END
If you run this and open test.txt, you'll find 'Hello, World'. But the program's output will be just 'Hello', because it acts as if the comma is a new line. You would have to query again for the 'World' literal.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Naw, you gotta use

LINE INPUT #1, text$

Anytime you PRINT # to a file, just get the entire line! It works just like LINE INPUT works instead of INPUT. You always get a STRING value back with LINE INPUT either way.

INPUT #1 can be used to get back Comma Separated Values from Data files that are made using WRITE #1.

INPUT #1, name$, age%, grade!, etc.

Ted
Last edited by burger2227 on Tue Mar 31, 2009 6:35 pm, edited 1 time in total.
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

burger2227 wrote:Naw, you gotta use

LINE INPUT #, text$

Anytime you PRINT # to a file, just get the entire line!

Ted
Image

I'm an idiot. You just solve one of my problems. Thanks though. :)

bongomeno:
Is the cutoff occurring in the file itself (when you open it in notepad or something), or is it cutting itself off when you read it from your program?
For any grievances posted above, I blame whoever is in charge . . .
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Don't feel bad! I have my memory lapses too.

Yep, INPUT #1 sure likes those commas! :oops:

Thanks for pointing me in the right (I hope) direction!

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
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

heeeelp! the beep dont stop!

Post by bongomeno »

yea i think the problem comes when im reading from the file. it cuts half of the parameters off the statement. so when my program outputs the c++ code, its all messed up... i have had the same problem before when i tried to make a basic interpreter.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can read any QB made sequencial files using Notepad.

You also can copy BAS code if it is saved as Text Readable in QB 4 up. Then you can paste the code to a forum. Here you should use the CODE and /CODE inside of [ brackets option in the post editor so that the code is not altered. Don't want any Smiley faces, lol.

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
Sunzoner
Newbie
Posts: 4
Joined: Thu Mar 05, 2009 11:00 pm

Post by Sunzoner »

burger2227 wrote:Naw, you gotta use

LINE INPUT #1, text$

Anytime you PRINT # to a file, just get the entire line! It works just like LINE INPUT works instead of INPUT. You always get a STRING value back with LINE INPUT either way.

INPUT #1 can be used to get back Comma Separated Values from Data files that are made using WRITE #1.

INPUT #1, name$, age%, grade!, etc.

Ted
Thanks. I was thinking of posting a similar question... Any chance this made it into some FAQs?
Post Reply