April 16, 2024, 12:08:27 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Can I represent a data pointer with a string?

Started by AdrianFox, November 19, 2009, 03:05:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

November 19, 2009, 03:05:22 AM Last Edit: November 19, 2009, 03:57:09 AM by AdrianFox
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.

Adrian Fox

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

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
Adrian Fox

mrainey

Quotewe forget what we had already learned a year ago!

You too?   :D
Software For Metalworking
http://closetolerancesoftware.com