#204899 - 2012-04-23 03:35 PM
Re: Resolving one or more variables in a string
[Re: Lonkero]
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ok, I don't know do you set the vars in the script and thus want them executed or do you just have the names stored somewhere with their value, but with this you should get on your way:
[postprep]$rc = Open(1, "d:\oldfile.html", 2)
if @error "couldn't open the source file: " @error ? get $ endif
if exist("d:\newfile.html") del "d:\newfile.html" endif
$rc = Open(2, "d:\newfile.html", 5)
$line = ReadLine(1)
While @ERROR = 0
If InStr($line, "$$")
"vars on this line: " ?
$line=Split($line,"$$")
For $c=1 to Ubound($line)
$line[$c]="$$"+Trim(Split($line[$c],"<")[0])
$line[$c] ?
Next
?
$line=join($line,"")
Endif
$rc = WriteLine(2, $line + @CRLF)
$line = ReadLine(1)
Loop
"done, good night." get $
$rc = Close(1)
$rc = Close(2)
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#204924 - 2012-04-23 09:52 PM
Re: Resolving one or more variables in a string
[Re: Mart]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
OMG! During diner I remebered something. Late March I had this working and copied the executable to the workstation of one of my colleagues doing logistics so he could do some beta testing for me. Browsed the machine and found the executable I created just before my laptop got stolen. Monitored the temp folder when I fired up the original executable and there was my script. You can’t even imagine how much of a relieve this is. The question in my original post is a part of a huge script compiled into an executable for creating shipping documents (pickup requests for our trucking company) and CMR forms for our logistics department. I'm so f-ing happy now! Below is the code I used to get it done. I guess it was a little less flexible than I thought 
Lonk, Glenn, Both nice solutions but due to other stuff this afternoon I did not get much time to play with it yet. Will do later this week. Thanks for the suggestions. Looks cleaner than what I did below.
....
If Exist("D:\TempFiles\pickuprequest.html")
Del "D:\TempFiles\pickuprequest.html"
EndIf
$rc = Open(1, "D:\Templates\Template_pickuprequest.html", 2)
$rc = Open(2, "D:\TempFiles\pickuprequest.html", 5)
$variables = "$$LabelDateTodayDate.Text", "$$TextBoxOurReference.Text", "$$LabelLoadingDate.Text", "$$TextBoxPackages.Text",
"$$TextBoxWeight.Text", "$$ComboBoxPackaging.Text", "$$ComboBoxDescription.Text", "$$TextBoxSize.Text",
"$$LabelRecipientText.Text", "$$TextBoxAttn.Text", "$$LabelAddressText.Text", "$$LabelZipcodeText.Text",
"$$LabelCityText.Text", "$$LabelPhoneText.Text", "$$LabelCountryText.Text", "$$ComboBoxADR.Text",
"$$ComboBoxStackable.Text", "$$ComboBoxSwapPackaging.Text"
$line = ReadLine(1)
While Not @ERROR
While InStr($line, "$")
For Each $variable in $variables
If InStr($line, $variable)
$rc = Execute("$$variabletext = $variable")
$line = Join(Split($line, $variable), $variabletext)
EndIf
Next
Loop
$rc = WriteLine(2, $line + @CRLF)
$line = ReadLine(1)
Loop
$rc = Close(1)
$rc = Close(2)
$ie = ReadValue("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE", "")
$shellline = $ie + " " + '"D:\TempFiles\pickuprequest.html"'
Run $shellline
....
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 793 anonymous users online.
|
|
|