Page 1 of 1

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

Posted: Sun Mar 29, 2009 1:21 am
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!

Posted: Sun Mar 29, 2009 12:41 pm
by burger2227
Post your code please.

Ted

heeeelp! the beep dont stop!

Posted: Sun Mar 29, 2009 8:39 pm
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.

Posted: Sun Mar 29, 2009 9:14 pm
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

ding dang commas

Posted: Mon Mar 30, 2009 8:47 am
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

Posted: Tue Mar 31, 2009 6:03 pm
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.

Posted: Tue Mar 31, 2009 6:15 pm
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

Posted: Tue Mar 31, 2009 6:25 pm
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?

Posted: Tue Mar 31, 2009 6:44 pm
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

heeeelp! the beep dont stop!

Posted: Wed Apr 01, 2009 3:39 pm
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.

Posted: Thu Apr 02, 2009 4:24 pm
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

Posted: Fri Jun 12, 2009 5:04 am
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?