Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with variables loaded from text file 1

Status
Not open for further replies.

leearach2004

Technical User
Dec 8, 2005
86
GB
Hi there

Im having a few problems with variables I have loaded from a text file using LoadVars().

They all load fine and everything works o.k but the problem I am having is refrencing the text inside these variables.


What I have is an array created as so

list = new Array(this.name0,this.name1,this.name2,.....);

I know there are esier ways of populating array but ill change that later.

So my array contains all the variables from my text file.

Now if I do somthing like

TextFeild.text = list[1];

The variable text is displayed in the text field

But before i display the text in need to check what is contained in the variable.

If it equals 0 then dont dispaly it and if it doesnt equal 0 then display the text.

I used an if statment like this

randdisplay is a text area
r is a random variable

if(list[r]==0){
some code;
}else{
randdisplay.text = list[r];
}

this should then only display the variables that do not equal 0 but it does not work it also display the 0's as well.

hope somone can help me

lee
 
I think you need to evaluate it as a string.
Code:
if (list[r] == "0"){
    // some code
}else{
    randdisplay.text = list[r];
}

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
hi there thansk for the reply

tried evaluation as a string but that didnt work either

I have no idea as im new at this variable from text file thing

hope somone can help

lee
 
Is "r" defined in the same code block as the if statement?

Wow JT that almost looked like you knew what you were doing!
 
hi there thanks for the tips

my text file is laid out fine as

&name1=0 and so on

the r variable is defined in the same bloke of code yes

why is this a problem
lee
 
It isn't a problem if it's defined in the same code block. That is where it's supposed to be. Can you post the full code that you are having trouble with?
 
&myvar=0

will not evaluate as 0...it can include all sorts of thinga like space and line returns


&myvar=0&

always evaluates as 0 as the second & says end of variable
 
hi there bill

thanks for the tip on using & to end a variable what you described is whats happening

However what if i have more than one variable at the moment the txt file looks like this

&name1=some text
&name2=some text
&name3=some text
........ and so on

do i need to add another & at the end of each line

if so that will fix my problem
please let me know

lee
 
if(list[r]==0){ //or 2 or 3 etc.
some code;
}else{
randdisplay.text = list[r];
}

......

if(to.String(list[r]==0)){
some code;
}else{
randdisplay.text = list[r];
}

turning the entire "list property"to string would sort it out
..
let me know.
ps, your text is fine
pps, you might want to add, at the end of your text file "&eof=1" (after the last word with a comma"):

list = new Array(this.name0,this.name1,this.name2),&eof=1
 
you should really always finish with an ampersand

id lay out you text file like this

&name0=some text&
&name1=some text&
&name2=some text&

&numName=3&

then in the loadvars onLoad function

for(i=0;i<this.numName;i++){
list.push(this["name"+i])
}

you can then do whatever you want with equivelancy statements if(list== )
 
billwatson,

Thank you for &numName=3&

I have spent hours trying to find out why why my text will not load as I wanted and that solution was exactly what I needed.

For sure I will use this forum more often in the future.

 
hi there all thanks for the advice,

I have added & to the end of all my variables and that has done the job and removed any excess spaces in the string

Thanks alot id dont think id have ever worked that one out

lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top