Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    variable in a paragraph object

    I have a text file that has been read into a variable, this variable needs to be inserted into some existing text that's in a paragraph object, how would that be done?

  2. #2
    Join Date
    Jul 2007
    Posts
    1,512
    Quote Originally Posted by Bruce View Post
    I have a text file that has been read into a variable, this variable needs to be inserted into some existing text that's in a paragraph object, how would that be done?
    you could have a place holder {Holder} for that one thing and if thats in your
    sting have it = "" and if then your new text that is ment to go there make it replace that place holder with the text.

    Not sure how to do it 100% but i do remeber doing something on these lines before.

  3. #3
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    Quote Originally Posted by Bruce View Post
    I have a text file that has been read into a variable, this variable needs to be inserted into some existing text that's in a paragraph object, how would that be done?
    Bruce,

    This may be a little convoluted but it should work for you, as long as you know where you want to insert the text...

    Code:
    Insert_String = TextFile.ReadToString("AutoPlay\\Docs\\MyFile.txt"); -- text to be inserted
    P_Orig=Paragraph.GetText("Paragraph1"); --original paragraph
    
    -- How to determine where to insert the text file....?
    whereAt=String.Find(P_Orig, "jumps over the lazy", 1, false); -- search for where to insert text string
    
    -- split the paragraph text at a known point
    T_Front=String.Mid(P_Orig, 1, whereAt -1); -- spit variable (front)
    T_Back=String.Mid(P_Orig, whereAt,  -1); -- spit variable (back)
    -- Now put them together
    P_New=T_Front..Insert_String..T_Back; -- insert string between front & back
    
    Paragraph.SetText("Paragraph1", P_New)
    -- Set and write P_New to a text file so that it's available for the paragraph next time?
    TextFile.WriteFromString("AutoPlay\\Docs\\MyPara.txt", P_New, false);
    LOL - some of the coding gurus could probably clean this up...

    hth

  4. #4
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Thx man I'll give it a go!

  5. #5
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    I need to get rid of the variable whereAt so it wont show up in the paragraph object, also, I can't write txt files back to the CD not a prob though.

  6. #6
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Or this way...

    Code:
    txt2Add = TextFile.ReadToString("D:\\test.txt");
    
    newText = [[
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
    
    ]]..txt2Add..[[
    
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
    ]]
    
    Paragraph.SetText("Paragraph1", newText);

  7. #7
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Nevermind...
    Last edited by mwreyf1; 06-10-2009 at 03:45 PM.

  8. #8
    Join Date
    Apr 2009
    Posts
    277
    if you simply want to add the text to the end of the existing text then try this
    Code:
    local sText = Paragraph.GetText("Object");
    local txt2Add = TextFile.ReadToString("D:\\test.txt");
    Paragraph.SetText("Object", sText.."\r\n"..txt2Add);
    or with some error checking
    Code:
    local txt2Add = TextFile.ReadToString("D:\\test.txt");
    -- Test for error
    error = Application.GetLastError();
    if (error ~= 0) then
    	Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    else
    	local sText = Paragraph.GetText("Object");
    	Paragraph.SetText("Object", sText.."\r\n"..txt2Add);
    end

  9. #9
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Quote Originally Posted by MicroByte View Post
    if you simply want to add the text to the end of the existing text then try this
    No but thank you MicroByte. What I need is to add the name of a business anywhere YOUR SALON is within the text of the Paragraph object, with what ever is in the text file. Not move it over, replace it.

  10. #10
    Join Date
    Aug 2003
    Posts
    2,427
    Quote Originally Posted by Bruce View Post
    What I need is to add the name of a business anywhere YOUR SALON is within the text of the Paragraph
    Sounds like all you need is String.Replace. Read the paragraph to a string and set the text to be replaced (or use the variable that already contains the replacement text) like-

    Code:
    stxt = Paragraph.GetText("Paragraph1");
    storeplace = "YOUR SALON"
    sreplacewith = "New salon name"
    snewtxt = String.Replace(stxt, storeplace, sreplacewith, false);
    -- the replacement text is now in the snewtxt variable ready for use.
    No no no.........

    What you want is to concatenate YOUR SALON with the additional text into a new string and *then* do a String.Replace as above.
    Last edited by longedge; 06-14-2009 at 03:23 AM. Reason: Just re-read what you said - Doh....

  11. #11
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Sounds like you have a standard application that is being resold to multiple clients and you want some of the components to be customized. How are you storing the company who purchases the product name on the application. Is there a configuration screen or text file that will store this information?

    I would have a common place holder like ##COMPANYNAME## in the standard text file and then read the file into variable and replace the above place holder with the variable whereever it is stored. That way the original file would not have to change for different users. I would also add a check into the app to see if any of you placeholder variables are still present and warn the user if they still exist and maybe prompt them to supply the value at that time and then store that variable into an ini file of registry if you can.

    That is how I would approach the issue.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  12. #12
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Helps if I read the help file...

    name_contents = TextFile.ReadToString("AutoPlay\\Docs\\business_na me.txt");
    -- Read the contents of a text file into a string.
    page1_contents = TextFile.ReadToString("AutoPlay\\Docs\\page1.txt") ;

    -- Check the error code of the last example.
    error = Application.GetLastError();
    -- If an error occurred, display the error message.
    if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    else
    -- Replace every occurrence of the string "BUSINESS" with the string "name_contents".
    new_page1_contents = String.Replace(page1_contents, "BUSINESS", name_contents, true);

    -- Write out the modified contents of the text file.
    Paragraph.SetText("Paragraph1", new_page1_contents);


    -- Check the error code of the last example.
    error = Application.GetLastError();
    -- If an error occurred, display the error message.
    if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    end
    end

Posting Permissions

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