Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 14 of 14
  1. #1
    Join Date
    Apr 2001
    Posts
    92

    Replacing variables in a Paragraph with values from an INI file

    I have a Paragraph which has text along with several variables. I want to replace the variables with values (text) I read from an INI file at runtime. Is there a way to do this in one step? I have been using labels for single words.
    Last edited by cchian; 04-27-2004 at 01:57 PM. Reason: better title

  2. #2
    Join Date
    Nov 2003
    Location
    Salzburg / Austria
    Posts
    312
    A way to it:

    Create a stringvariable wit text and placeholder

    longtext=[[bla bla bla %VAR_1% bla bla bla bla bla bla bla
    bla bla bla bla bla bla %VAR_2% bla bla bla bla bla bla
    bla bla bla bla bla bla %VAR_3% bla bla bla bla bla bla
    bla bla bla bla bla bla %VAR_4% bla bla bla bla bla bla]]

    run loop for all variables
    for x,max do
    result = String.Replace(longtext, "%VAR_"..x.."%", your ini[x], false);
    end

    write text to paragraphobject
    Paragraph.SetText("paragraph1", longtext);


    hope it helps

    Stefan

  3. #3
    Join Date
    Apr 2001
    Posts
    92
    Thanks, I will give that a try. Another question, if my paragraph only contains very few items (ie Product name, Version and Build), is your example still the quickest way of doing it?

  4. #4
    Join Date
    Nov 2003
    Location
    Salzburg / Austria
    Posts
    312
    maybe a faster way:

    --fix text
    text_part1="bla bla bla "
    text_part2="blo blo blo "
    text_part3="bli bli bli "
    text_part4="ble ble ble "
    text_part4="blu blu blu "

    --concat fixed text with inivariables
    longtext=text_part1..inivar1..text_part2..inivar2. .text_part3..inivar3..text_part4..inivar4..text_pa rt5;


    --write text to paragraphobject
    Paragraph.SetText("paragraph1", longtext);


    Stefan

  5. #5
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Yep Stefan M's right. A good rule of thumb is too, use his first method if you will be doing more than one replace during your project, use the second for scenarios where you will be setting those values once-per-run.

    I use ###TEXT### usually for my replace values, works good and eliminates any chance you may accidentally replace something unrelated. For example

    text="Hi ###NAME###, How are you. Today's date is ###DATE###.";

    And then you can use a String replace to swap the name anad date values. That's just one example, you can use anything really but it's good to create a habit for one method or the other right from the start, for your own reference.

    Corey Milner
    Creative Director, Indigo Rose Software

  6. #6
    Join Date
    Apr 2001
    Posts
    92
    How can I show the results in different lines? Like in:

    Product name: My App
    Version 1.0
    Build 1234

    I tried adding "\n" but I keep getting errors. This is what I have:

    longtext = "Product Name "..strname \n "Version "..strversion \n "Build "..strbuild;
    Paragraph.SetText("Paragraph1", longtext);

  7. #7
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    Try:

    Example:

    Dialog.Message("", "Hi\n\r\There!");
    Last edited by Intrigued; 04-27-2004 at 10:43 PM.
    Intrigued

  8. #8
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Hi.

    longtext = "Product Name "..strname.."\\n Version "..strversion.."\\n Build "..strbuild;

    Corey Milner
    Creative Director, Indigo Rose Software

  9. #9
    Join Date
    Apr 2001
    Posts
    92
    It is still concatenating everything together connected by "\n".

    Quote Originally Posted by Corey
    Hi.

    longtext = "Product Name "..strname.."\\n Version "..strversion.."\\n Build "..strbuild;

  10. #10
    Join Date
    Nov 2003
    Location
    Salzburg / Austria
    Posts
    312
    longtext = "Product Name: "..strname.."\r\n Version: "..strversion.."\r\n Build: "..strbuild;
    Attached Files

  11. #11
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Hmmm, works OK here. Here I've attached a working example, actions are Page OnShow. Just pick it apart and re-use what you need. Hi Stefan, just FYI you don't actually need the \r for a paragraph object but if you were going to use it, you would want to use this syntax FWIW:

    longtext = "Product Name: "..strname.."\\r\\n Version: "..strversion.."\\r\\n Build: "..strbuild;

    Main thing is escaping the slashes. Like Zorro!

    Corey Milner
    Creative Director, Indigo Rose Software
    Attached Files

  12. #12
    Join Date
    Apr 2001
    Posts
    92
    Stefan M, your example works perfectly. Corey, I still had the same results as before using your example. It is strange that it behaves different in your PC.
    Thanks for the help!

  13. #13
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Yes that is very strange, the example project should work fine on any PC in AMS. But anyoo.

    Corey Milner
    Creative Director, Indigo Rose Software

  14. #14
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Quote Originally Posted by Corey
    Hmmm, works OK here. Here I've attached a working example, actions are Page OnShow. Just pick it apart and re-use what you need. Hi Stefan, just FYI you don't actually need the \r for a paragraph object but if you were going to use it, you would want to use this syntax FWIW:

    longtext = "Product Name: "..strname.."\\r\\n Version: "..strversion.."\\r\\n Build: "..strbuild;

    Main thing is escaping the slashes. Like Zorro!
    Actually, Corey, in this case you don't want to escape the slashes. If you do that, the slashes (and the 'r' and 'n') will appear in the text.
    --[[ Indigo Rose Software Developer ]]

Similar Threads

  1. Replies: 4
    Last Post: 12-06-2003, 01:17 PM
  2. Display Text by Mouse Over of Image Object
    By jdanniel in forum AutoPlay Media Studio 4.0
    Replies: 3
    Last Post: 04-30-2003, 12:05 PM
  3. Setting Multiple FS Commands
    By johndove1 in forum AutoPlay Media Studio 4.0
    Replies: 1
    Last Post: 01-31-2003, 03:16 PM
  4. HOWTO: Display Conditional Text Based Upon a List Box Selection
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-15-2002, 10:54 AM
  5. Default text in edit field - Multiple edit screen
    By Romahe in forum Setup Factory 6.0
    Replies: 1
    Last Post: 12-18-2001, 01:01 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