Jump to content

Formatting from file?


Things
 Share

Recommended Posts

I have a script that reads data values from an array and inserts them into a string for submission into a form, however I'm trying to make the string editable from a txt file.

Basically what I did, was the usual FileRead, some more code, then this:

_IEFormElementSetValue ($oForm2, $sigstring)

$sigstring is filled with the contents of the file, which for example, might be this:

"Wind: " & $datarray[6] & $datarray[14] & " from " & $datarray[12] & @LF & "[size:8pt]Last update: " & $datarray[2] & ""

As you can see, there are a few array values etc Autoit needs to fill in before it's written to the form field, however, it doesn't, it just prints that whole thing as a string. Is there a way around this?

Thanks

Link to comment
Share on other sites

... and an error code, just as stated in the help file.

Eval() need variable names without the leading $.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hmm, though technically wouldn't it still be a string by the time it reached the _IEFormElementSetValue ?

Since you'd be looking in the string, replacing the variables with eval(), but then just sending it back as a string?

Then again, this doesn't have to be settable through a text file, but I don't see any other way of doing it (Once compiled as an .exe).

Edited by Things
Link to comment
Share on other sites

Made a harness to test:

dim $datarray[4]
 
 
local $answer
 
for $x = 0 to 3
    $datarray[$x] = "Value" & $x
Next
 
 
$sigstring = FileReadLine("stringtest.txt")
 
$array = StringSplit($sigstring," & ")
for $x = 0 to $array[0]
    if StringLeft($array[$x],1) = "$" Then
        msgbox(1,"TRIMMED STRING" & $x , StringTrimLeft($array[$x],1))
        $n = StringTrimLeft($array[$x],1)
        $a = eval($n)
        msgbox(1,"EVALed" & $x, $a)
        $array[$x] = eval(StringTrimLeft($array[$x],1))
        msgbox(1,"ARRAY["&$x&"]",$array[$x])
    EndIf
Next
 
for $x = 1 to $array[0]
    $answer &= $array[$x]
Next
 
msgbox(1,"SIGSTRING",$sigstring)
msgbox(1,"ANSWER",$answer)

and a file with:

"Wind: " & $datarray[0] & $datarray[1] & " from " & $datarray[2] & @LF & "[size:8pt]Last update: " & $datarray[3] & "[/size]"

Doesn't look like eval can evaluate an array:

eval(array[1]) doesn't work.

Anyone?

Link to comment
Share on other sites

Well, this is what I have at the moment:

#include <IE.au3>
_IEErrorHandlerRegister()
$file = FileOpen("SigFormat.txt")
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$sigstring = FileRead($file)
$file1 = FileOpen("realtime.txt")
; Check if file opened for reading OK
If $file1 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$chars1 = FileRead($file1)
$datarray = StringSplit($chars1, " ")
$oIE = _IECreate ("TheFormURL",0,0)
_IELoadWait ($oIE)
$oSubmit = _IEGetObjByName($oIE, "buttlogin")
$oForm = _IEGetObjByName ($oIE, "Loginname")
_IEFormElementSetValue ($oForm, "UserName")
$oForm1 = _IEGetObjByName ($oIE, "Loginpass")
_IEFormElementSetValue ($oForm1, "Password")
_IEAction ($oSubmit, "click" )
_IELoadWait ($oIE)
$oForm2 = _IEGetObjByName ($oIE, "Signature")
_IEFormElementSetValue ($oForm2, $sigstring)
$oSubmit1 = _IEGetObjByName($oIE, "buttsubmit")
_IEAction ($oSubmit1, "click" )
_IELoadWait($oIE)
_IEQuit($oIE)

I already have all the values in datarray.

The problem I'm having is reading a string from a separate txt file, that those variables will be inserted in.

Since, when this script is compiled as an exe, editing it is kind of out of the question. So what I'd hoped to do, was have a text file that would contain the format I wanted to fill the form box with.

So for example, say the realtime.txt file contained 2 values of 32 and km/h

Those values are read into their respective array positions (in datarray), so $datarray[1] would contain 32, and $datarray[2] would contain km/h.

I have that all sorted in working.

Now, I want to be able to insert the array values into a string, but have it editable outside of the exe.

So for example, I'd create a text file containing:

"The current wind speed is: " $datarray[1] & datarray[2]

Autoit would read that in from the text file, and replace those 2 array variables with 32 and km/h, THEN fill in the form field. So it should then read: The current wind speed is: 32km/h. Instead, the form field is filled with "The current wind speed is: " $datarray[1] & datarray[2]

Because autoit obviously isn't looking for variables embedded in a string (thus, variables embedded in variables).

EDIT: Nevermind, it turns out it was as simple as adding Execute($sigstring)

Thanks for the help anyway :graduated:

Edited by Things
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...