IonicWind Software

IWBasic => General Questions => Topic started by: AdrianFox on November 19, 2009, 03:05:22 AM

Title: Can I represent a data pointer with a string?
Post by: AdrianFox on November 19, 2009, 03:05:22 AM
Hi,

I'm trying to access sets of text lines contained in data statements at random.

I had the bright idea that I could use :

random$=str$(rand(15)

if random$="2"
dataname$="two"
endif

and then to access data I would access the data statements in 'databegin two' (or databegin three etc etc)
with .....

"getdata,dataname$,new$"

This won't work as I get the 'no appropriate conversion' error message. So I guess you can't use a variable to represent the data block.

The other problem is that I can only read the integer from str$(rand(15)) when it's read with:  instr(random$,"3")

Why is this?  If I simply print the string representation of the random number, I get "1", "2", "3" etc perfectly ok.  But I can't seem to put it into another string variable without using instr.

I find in dealing with lots of text in programs (being an ex-English teacher who does things like that!) , that data statements are ideal, except when I want to randomise which sets of texts I want to 'read' from the data.

Is there another way I could do this which would be better, without using text files external to the program?  

Thanks for any suggestions.  And sorry if some of the questions above are dumb, but I have looked through the documentation and searched the forums without success.
:-\

D'OH!..... Quick walk in the sun, and I realize the simplest method of doing what I want is to have all my text statements in a single set of data and then to randomize the position from which I get the data!  Sorry to be so thick!   Still wonder about the integer/string thing above though.

Title: Re: Can I represent a data pointer with a string?
Post by: LarryMc on November 20, 2009, 06:03:47 AM
Adrian,
when you use the str$ function the returned string has a space before the number.

if you use ltrim$(str$(rand(15))) the returned string will be just the number with no space.

Larry
Title: Re: Can I represent a data pointer with a string?
Post by: AdrianFox on November 20, 2009, 06:41:38 AM
Thanks Larry.   I do remember now having read about this null character in number strings.   

Thanks very much for reminding me. 

The problem with people like me who only program in fits and starts with huge gaps in the middle, is that we forget what we had already learned a year ago!

Best wishes

Adrian
Title: Re: Can I represent a data pointer with a string?
Post by: mrainey on November 20, 2009, 01:42:29 PM
Quotewe forget what we had already learned a year ago!

You too?   :D