Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Posts
    19

    Smile Remove unwanted empty lines

    I have several input boxes and want to send the text of the input boxes to a Paragraph Object. I have used the code below.


    content =(strButter.."\r\n"..strEggs.."\r\n"..strCheese.." \r\n"..strYoghurt.."\r\n"..strCream.."\r\n"..strMi lk);
    Paragraph.SetText ("Paragraph1", content);


    The problem is that I do not want empty inputs being sent so I dont get empty lines in the paragraph as the example below.Can I do this? I have searched but cannot find an answer to this.
    ie.

    Eggs
    Cheese
    Yoghurt

    Milk

  2. #2
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Well, you would need to see if the Input fields actually contain data before you concatenate the string into "content", wouldn't you?

    Ulrich

  3. #3
    Join Date
    May 2006
    Posts
    5,380
    Code:
    if content ~= "" then

  4. #4
    Join Date
    Feb 2007
    Location
    Como, Italy
    Posts
    1,415
    Maybe, because John31 is a new user, it is necessary to kindly invite him to read the user manual?
    We are slowly invading your planet to teach lazy humans to read the user manual.
    But don't be scared: we are here to help.

  5. #5
    Join Date
    Apr 2010
    Posts
    529
    Hey John,

    Welcome to the forum. Things will be a little daunting and overwhelming to start with, but here's one to get you going.

    What RizlaUK said is the key to this.

    Copy the following code to the "On Click" of the button.

    We need to test the values of the text from each Input and appending the "\r\n" ONLY if the value of the Input field is not (~=) empty. This is a simple, rudimentary style, laying everything out to see, and it'll help you get a better understanding.

    Code:
    strButter	= Input.GetText("Input1")
    strEggs		= Input.GetText("Input2")
    strCheese	= Input.GetText("Input3")
    strYoghurt	= Input.GetText("Input4")
    strCream	= Input.GetText("Input5")
    strMilk		= Input.GetText("Input6"))
    
    if strButter ~= "" then
    	strButter = strButter.." butter\r\n";
    end
    
    if strEggs ~= "" then
    	strEggs = strEggs.." eggs\r\n";
    end
    
    if strCheese ~= "" then
    	strCheese = strCheese.." cheese\r\n";
    end
    
    if strYoghurt ~= "" then
    	strYoghurt = strYoghurt.." yoghurt\r\n";
    end
    
    if strCream ~= "" then
    	strCream = strCream.." cream\r\n";
    end
    
    if strMilk ~= "" then
    	strMilk = strMilk.." milk\r\n";
    end
    
    content = strButter..strEggs..strCheese..strYoghurt..strCream..strMilk;
    
    if content == "" then
    	Paragraph.SetText("Paragraph1", "We have everything!");
    else Paragraph.SetText("Paragraph1", "We need:\r\n"..content);
    end
    Hope this helps to get you started. The forum is a great place for sampling code and getting a feel for what does what.

    Cheers,
    MadDogDean

    PS. If whatever you're baking works out, I get a dozen!
    Last edited by MadDogDean; 02-03-2012 at 05:31 PM.

  6. #6
    Join Date
    Feb 2012
    Posts
    19
    Many thanks for the help and special thanks to you MadDogDean for the sample code. The code you supplied really helped me see how to go about this probably easy problem (to anyone who knows the program better). I promise I looked through the online user manual which is how I got as far as I did.
    Many thanks great help.
    Last edited by John31; 02-03-2012 at 10:02 PM. Reason: Spelling Mistake

  7. #7
    Join Date
    Apr 2010
    Posts
    529
    Quote Originally Posted by John31 View Post
    The code you supplied really helped me see how to go about this probably easy problem (to anyone who knows the program better). I promise I looked through the online user manual which is how I got as far as I did.
    Many thanks great help.
    Glad to help John. Just wait... in a year you'll look back to this first posting and go

    "D'oh, how could I NOT have gotten it??!"

    Cheers,
    MadDogDean
    Last edited by MadDogDean; 02-03-2012 at 10:44 PM.

Posting Permissions

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