Jump to content

Call Func located in .txt doc


Recommended Posts

I was just trying to figure out ways to save data to text documents so they can later be loaded back into the input boxes of my programs and I got curious....is it possible to somehow write a function inside of a text document, then call the function from the text file?

 

anywho, for those of you trying to save/load info to and from txt docs, here's some code:

#include <String.au3>

Global $userinput = "C:\location\location"&"\";save location for text doc
Global $fileofchoice

Global $NEW1val = "1234"
Global $NEW2val = "4565"
Global $NEW3val = "7896"

HotKeySet("{F1}", "writedata")
HotKeySet("{F2}", "readdata")
HotKeySet("{ESC}", "End")

While 1
    Sleep(10)
WEnd

Func writedata()

$randomness = Random(0, 999999)
$randomnumber = Round($randomness)

$fileofchoice = $userinput&"test "&$randomnumber&".txt"

$WRITE1val = "<1>"&"test1 = "&$NEW1val&"</1>"
$WRITE2val = "<2>"&"test2 = "&$NEW2val&"</2>"
$WRITE3val = "<3>"&"test3 = "&$NEW3val&"</3>"

FileWrite($fileofchoice,$WRITE1val&$WRITE2val&$WRITE3val)

MsgBox(0, "Notice", "Data written to:"&@CRLF&$userinput&$fileofchoice)
EndFunc

Func readdata()

    $READsource = FileRead($fileofchoice)
    $READ1val = FindBetweenString($READsource, "<1>", "</1>")
    $READ2val = FindBetweenString($READsource, "<2>", "</2>")
    $READ3val = FindBetweenString($READsource, "<3>", "</3>")

MsgBox(0, "Notice", $READ1val&@CRLF&$READ2val&@CRLF&$READ3val)
EndFunc

Func FindBetweenString($sString, $sStart, $sEnd)
    Local $sBetween = _StringBetween($sString, $sStart, $sEnd)
    If @error Then Return SetError(1,0,0)
    Return SetError(0,0,$sBetween[0])
EndFunc

Func End()
    Exit
EndFunc

 

Link to post
Share on other sites
9 minutes ago, Subz said:

Why not just use an Ini file and Ini functions?

well, I'm not exactly sure how to go about doing such a thing...however this is a kind of crude way of putting it....
 

$fileofchoice = "C:\location\testread.txt"
Local $READsource = FileRead($fileofchoice)

test()

Func test()
    Call($READsource)
EndFunc
;CONTENTS OF testread.txt
;-------------------------

Func testing()
MsgBox(0, "Notice", "Success")
EndFunc

 

Link to post
Share on other sites
Just now, Subz said:

Well in that case why don't you just save it as a .au3 file and then use #include for example:

#include "C:\location\testread.au3"

testing()
;CONTENTS OF testread.au3
;-------------------------

Func testing()
MsgBox(0, "Notice", "Success")
EndFunc

 

ohhh, tyty... now I see how that works, never used include for my own purposes

Link to post
Share on other sites

With regards to your OP around saving input, this is what I meant about ini files

; Create Gui - Read Data to Input Controls
....
$idInput1 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input1", ""), 10, 10, 200, 20)
$idInput2 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input2", ""), 10, 35, 200, 20)
$idInput3 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input3", ""), 10, 60, 200, 20)
....

; Save Input back to Ini
IniWrite("filename.ini", "Inputs", "Input1", GUICtrlRead($idInput1))
IniWrite("filename.ini", "Inputs", "Input2", GUICtrlRead($idInput2))
IniWrite("filename.ini", "Inputs", "Input3", GUICtrlRead($idInput3))
;~ Contents of Filename.ini
[Inputs]
Input1 = Input1 Text
Input2 = Input2 Text
Input3 = Input3 Text

 

Link to post
Share on other sites
5 minutes ago, Subz said:

With regards to your OP around saving input, this is what I meant about ini files

; Create Gui - Read Data to Input Controls
....
$idInput1 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input1", ""), 10, 10, 200, 20)
$idInput2 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input2", ""), 10, 35, 200, 20)
$idInput3 = GUICtrlCreateInput(IniRead("Filename.ini", "Inputs", "Input3", ""), 10, 60, 200, 20)
....

; Save Input back to Ini
IniWrite("filename.ini", "Inputs", "Input1", GUICtrlRead($idInput1))
IniWrite("filename.ini", "Inputs", "Input2", GUICtrlRead($idInput2))
IniWrite("filename.ini", "Inputs", "Input3", GUICtrlRead($idInput3))
;~ Contents of Filename.ini
[Inputs]
Input1 = Input1 Text
Input2 = Input2 Text
Input3 = Input3 Text

 

ohhh, gotchya, tyvm

Edited by HankHell
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...