Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    multi-line variable?

    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?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's wrong with one line
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var fig = "adding text here but will span onto next line "+
    "continuing to add text here but part of same variable."


    .....Willy

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Last edited by jbot; 02-12-2004 at 03:58 PM.

  • #5
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

    anyone else wanna chime in?

  • #6
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    AND THE WINNER IS.....


    WILLY!!!


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

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #8
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by Codin_away; 02-12-2004 at 07:27 PM.

  • #9
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm in a controlled environment, this is not for internet use. I'll be able to determine which browsers are used.

  • #11
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Codin_away

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

    .....Willy

  • #12
    New Coder
    Join Date
    Feb 2004
    Location
    St. Louis
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i figured... I posted that in response to jbot, before reading your reply.

  • #13
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •