View Full Version : variable in a paragraph object
Bruce
06-10-2009, 11:10 AM
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?
rexzooly
06-10-2009, 11:18 AM
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.
holtgrewe
06-10-2009, 12:53 PM
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...
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
Bruce
06-10-2009, 01:04 PM
Thx man I'll give it a go!
Bruce
06-10-2009, 01:19 PM
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.
mwreyf1
06-10-2009, 04:03 PM
Or this way...
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);
mwreyf1
06-10-2009, 04:39 PM
Nevermind...
MicroByte
06-11-2009, 06:44 AM
if you simply want to add the text to the end of the existing text then try this
local sText = Paragraph.GetText("Object");
local txt2Add = TextFile.ReadToString("D:\\test.txt");
Paragraph.SetText("Object", sText.."\r\n"..txt2Add);
or with some error checking
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
Bruce
06-13-2009, 08:25 PM
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.
longedge
06-14-2009, 04:16 AM
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-
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.
TJ_Tigger
06-15-2009, 12:04 PM
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.
Bruce
07-17-2009, 12:48 AM
Helps if I read the help file...
name_contents = TextFile.ReadToString("AutoPlay\\Docs\\business_name.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
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.