...

View Full Version : multi-line variable?



Codin_away
02-12-2004, 03:39 PM
Is there a way to declare a multi-line variable?

i.e.:

var fig = "adding text here but will span onto next line " *symbol*
"continuing to add text here but part of same variable."

is that possible? Should I just make it an array?

Vladdy
02-12-2004, 03:43 PM
What's wrong with one line :confused:

Willy Duitt
02-12-2004, 03:46 PM
var fig = "adding text here but will span onto next line "+
"continuing to add text here but part of same variable."

.....Willy

jbot
02-12-2004, 03:47 PM
willy, javascript really wants all statements to carry on one line and to end in a semi-colon, otherwise it can break in certain browsers. ie:

var strFoobar = "this is foo is foo is foo" ;

and not ...

var strFoobar = "this is foo" +
"is foo" +
"is foo"

------------------------

geddit?

Codin_away
02-12-2004, 03:49 PM
I'm creating the *.js file that I'm using from another program & another programming language. In the programming language that I'm using a variable can only contain 1000 characters. So I have switched to an array there. But the way it writes files is line by line, so each line of the *.js file I write will contain the data that I would like to be in a variable. But it's too big for me to just say:

var jsvariable = myvar //because myvar >1000 for my language.

so I have:

var jsvariable = myarray[5] //becuase I can hold infinite data here.

but can I do:

var jsvariable = myarray[1] thru myarray[5] ??

not sure if that made sense or not.

well jbot and willy disagree... :eek:

anyone else wanna chime in? :thumbsup:

Codin_away
02-12-2004, 04:26 PM
AND THE WINNER IS.....


WILLY!!!


Tried breaking the line up into multiple lines using + and it worked like a charm. Thanks.

Tails
02-12-2004, 07:19 PM
Why must you break it up into lines? Remember, word wrap is not the same as a hard return. You could even put your entire document on a single line if you wanted to, providing you use semicolons to separate multiple javascript statements on the same line.:p

Codin_away
02-12-2004, 07:24 PM
Can't break it up into lines because of 2 facts:

1- I MUST use an array to store data because variables in my coding language (that I use to generate the javascript file) only allows me to store 1000 characters into a variable.

2- I CANNOT write the contents of the entire array to one line of the javascript file (the end product) because my write command in this programming language writes one line at a time.

So I would have to have a for loop to empty out the array, but I cannot empty it out into a variable (too small) so I must start placing the conents of it into the file. But fact 2 states that my function to write to file rights a line at a time. So everytime it would move onto a new element in the array it would have written the previous element onto the previous line.

example:

arraysize=array.length
for cnt=1 to arraysize
write to javascript from array[cnt]
end for

each time through the loop writes a line. Now I'm adding on + characters and ; to end it.

Willy Duitt
02-12-2004, 08:41 PM
Originally posted by jbot
willy, javascript really wants all statements to carry on one line and to end in a semi-colon, otherwise it can break in certain browsers. ie:

var strFoobar = "this is foo is foo is foo" ;

and not ...

var strFoobar = "this is foo" +
"is foo" +
"is foo"

------------------------

geddit?

jbot;

I did not say nor imply that I condoned splitting the variable across multiple lines. I merely answered the question which was posed.

Sometimes people have reasons for doing something even if I do not agree with them.

Anyway, Which browser(s) break because of breaking a line?
I'm no expert, but I have never seen this.....

.....Willy

Codin_away
02-12-2004, 08:49 PM
I'm in a controlled environment, this is not for internet use. I'll be able to determine which browsers are used.

Willy Duitt
02-12-2004, 08:57 PM
Codin_away

I only was asking because jbot spoke with authority and I was curious which browsers are known to break.

.....Willy

Codin_away
02-12-2004, 08:58 PM
i figured... I posted that in response to jbot, before reading your reply.

trib4lmaniac
02-13-2004, 07:53 AM
Better that using "+", just escape the line break...

var myvar="This is foo\
is foo\
is foo";

As far as i no this works in all browsers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum