March 28, 2024, 09:19:28 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


writing commas to hard drive

Started by TexasPete, April 29, 2011, 08:16:41 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

TexasPete

Is the following the correct way to write a string to hard drive to include commas in the string'
I did not see an example in the manual. What about other special characters . Are there any other special rules.


OPENCONSOLE
DEF myfile:FILE
IF(OPENFILE(myfile,"C:\CBASICTEST.TXT","W") = 0)
   WRITE myfile,"john Henry, Philip Hughes"
   CLOSEFILE myfile
   PRINT "File created successfully"
ELSE
   PRINT "File could not be created"
ENDIF
PRINT "Press Any Key To Close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END


Thanks
Texas Pete

LarryMc

The only specialthings I can think of right now is if you wanted to have \ or " in your string.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

TexasPete

April 29, 2011, 03:28:52 PM #2 Last Edit: April 29, 2011, 03:30:37 PM by TexasPete
Larry would I put the slash or quote  In quotes or use a chr$ code like
write , using say a chr$(34) for quote.



WRITE myfile,chr$(34)+"john Henry, Philip Hughes"+chr$(34)

Texas Pete
Thanks

LarryMc

I don't thick CBasic recognizes escape sequences so you would have to use Chr$() like you've done.

In IWB  for a \ and a " you would use \\ and \"

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

I don't see the problem.  This example prints to the screen, but writing to a file would be just the same.


openconsole
cls

a$="This is a $2 test, isn't it? - I thought so!"
print a$

a$ = "She said "Hello" - and I smiled."
print a$

do:until inkey$<>""
closeconsole
end


best wishes, :)

Graham
Tomorrow may be too late ..

TexasPete

Graham ,

The reason I was asking is because several other basics that I have used in the past had special ways to handle a comma. In the old commodore several hidden characters simple could not be written to hard drive with out substituting one character code for another and then swapping the character back upon reading a string back in. So far the more up  to date  languages, each had unique requirements.

I am simply trying to understand how the writer of the compiler expected it to be handled

Thanks
Texas Pete

LarryMc

@Graham
While there is no problem with this
a$ = "She said "Hello" - and I smiled."
print a$


This won't print
a$ = "She said "Why, Hello!" - and I smiled."
print a$


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Hi Larry,  :)

It works fine for me - but then I'm still using CB Version 1.0.

Some problems seem to have been introduced into later versions, which I don't use because none of the recent changes brought anything I really needed.

best wishes, :)

Graham
Tomorrow may be too late ..