Jump to content

Read text doc and use as script in au3


Recommended Posts

Hello,

Small desscription what I want to do:

Step1:

I start my reg.au3.

The au3 script must read a text document (code.txt)

and save as a variable

"$text = FileRead(@ScriptDir & "code.txt")"

------------------------------------------------------

Step2:

Inside the "code.txt" is a command "Guictrlcreatebutton("Test",10,90,50,50)" for the au3 scriipt.

The variable $text is now "Guictrlcreatebutton("Test",10,90,50,50)"

-------------------------------------------------------

Step3:

Now I want that the variable starts inside my reg.au3

but how ?

I tryed just write the variable in a line but doesn't works.

Here is the script and the Text Document

Please help :(

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Debug.au3>
#include <String.au3>
#include <NetShare.au3>
#include <Array.au3>
#include <EditConstants.au3>
#Include <Misc.au3>
#include <array.au3>
#include <GuiStatusBar.au3>
#include <GuiButton.au3>
#include <File.au3>
#include <Array.au3>
#include <Inet.au3>
#include <GuiStatusBar.au3>
#include <Timers.au3>
#include <ProgressConstants.au3>
#include <GuiMenu.au3>



Opt("GUIOnEventMode",1) ;OnEvent Modus für GUIs' , die dem User als Tool dienen.
Opt("TrayIconHide", 0)  ;0 Zeigt TrayIcon des Programms, 1 versteck TrayIcon
Opt("GUICloseOnESC",1)  ;Schließt das Programm beim Drücken der ESC Taste
;~ Opt("SendCapslockMode", 0)

;******************SOLUTION MENÜ*************************************
$main_gui = GUICreate("EDV",281, 300, 500,200)
;***************S T E U E R E L E M E N T E********
GUISetOnEvent($GUI_EVENT_CLOSE, "close_main_gui")

$text = FileRead(@ScriptDir & "\code.txt")

start > $text



WinSetTrans($main_gui,"",220)
GUISetBkColor(0xFFFFFF)
GUISwitch($main_gui)
GUISetState(@SW_SHOW)

While 1
Sleep(0)
WEnd

Func close_main_gui()
   Exit
EndFunc

code.txt

Link to comment
Share on other sites

  • Moderators

AndroidZero,

You cannot do what you want directly. You will have to do one of 2 things:

- 1. Create a new file and run it:

; Define initial lines
$sStart_Lines = '#include <GUIConstantsEx.au3>' & @CRLF & _
                'Opt("GUIOnEventMode", 1)' & @CRLF & _
                '$main_gui = GUICreate("EDV", 281, 300, 500, 200)' & @CRLF & _
                'GUISetOnEvent($GUI_EVENT_CLOSE, "close_main_gui")' & @CRLF

; Read in new lines
$sAdded_lines = FileRead(@ScriptDir & "\code.txt") & @CRLF

; Define ending lines
$sEnding_Lines = 'WinSetTrans($main_gui, "", 220)' & @CRLF & _
                 'GUISetBkColor(0xFFFFFF)' & @CRLF & _
                 'GUISwitch($main_gui)' & @CRLF & _
                 'GUISetState(@SW_SHOW)' & @CRLF & _
                 'While 1' & @CRLF & _
                 @TAB & 'Sleep(10)' & @CRLF & _
                 'WEnd' & @CRLF & _
                 'Func close_main_gui()' & @CRLF & _
                 @TAB & 'Exit' & @CRLF & _
                 'EndFunc   ;==>close_main_gui'

; Create file to run
Global $sRun_File = @ScriptDir & "\Runit.au3"
If FileExists($sRun_File) Then
    FileDelete($sRun_File)
EndIf
FileWrite($sRun_File, $sStart_Lines & $sAdded_lines & $sEnding_Lines)

; And then run it
Run('AutoIt3.exe /AutoIt3ExecuteScript "' & $sRun_File & '"')
- 2. Write code to parse the line you read in and write the code directly:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
$main_gui = GUICreate("EDV", 281, 300, 500, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "close_main_gui")

; Read in new line
$sAdded_lines = FileRead(@ScriptDir & "\code.txt")

; Parse the line
$aSplit_1 = StringSplit($sAdded_lines, "(")
; Confirm type of command
If $aSplit_1[1] = "GUICtrlCreateButton" Then
    ; Parse the parameters
    $aSplit_2 = StringSplit($aSplit_1[2], ",")
    ; Create the control
    GUICtrlCreateButton($aSplit_2[1], Number($aSplit_2[2]), Number($aSplit_2[3]), Number($aSplit_2[4]), Number($aSplit_2[5]))
EndIf

WinSetTrans($main_gui, "", 220)
GUISetBkColor(0xFFFFFF)
GUISwitch($main_gui)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func close_main_gui()
    Exit
EndFunc
I would strongly recommend using the first of those techniques as the parsing of commands will rapidly become a unmanageable task - imagine having to do it for each AutoIt command listed in the Help file! :o

Please ask if anything is unclear. :)

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Could it not be as simple as Execute?

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Debug.au3>
#include <String.au3>
#include <NetShare.au3>
#include <Array.au3>
#include <EditConstants.au3>
#Include <Misc.au3>
#include <array.au3>
#include <GuiStatusBar.au3>
#include <GuiButton.au3>
#include <File.au3>
#include <Array.au3>
#include <Inet.au3>
#include <GuiStatusBar.au3>
#include <Timers.au3>
#include <ProgressConstants.au3>
#include <GuiMenu.au3>



Opt("GUIOnEventMode",1) ;OnEvent Modus für GUIs' , die dem User als Tool dienen.
Opt("TrayIconHide", 0)  ;0 Zeigt TrayIcon des Programms, 1 versteck TrayIcon
Opt("GUICloseOnESC",1)  ;Schließt das Programm beim Drücken der ESC Taste
;~ Opt("SendCapslockMode", 0)

;******************SOLUTION MENÜ*************************************
$main_gui = GUICreate("EDV",281, 300, 500,200)
;***************S T E U E R E L E M E N T E********
GUISetOnEvent($GUI_EVENT_CLOSE, "close_main_gui")

;$text = 'Guictrlcreatebutton("Test",10,90,50,50)'
$text = FileRead(@ScriptDir & "\code.txt")

Execute($text)



WinSetTrans($main_gui,"",220)
GUISetBkColor(0xFFFFFF)
GUISwitch($main_gui)
GUISetState(@SW_SHOW)

While 1
Sleep(0)
WEnd

Func close_main_gui()
   Exit
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

It works for a single line with no dependencies, but I can see a few problems if that is not the case. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you both !

I will test it first with "execute" because I don't really need to give the GuiCtrl commands a variable.

My plan is that the user can open the reg.au3 with their own configurations.

For example:

-they start the "reg.au3".

-a small gui opens with a combobox

-the combobox read out a (hidden folder) inside the folder are text documents with scripts.

-if he select for example the text document "code.txt" then a the small GUI closes and a new bigger GUI opens with the button "Test"

Of corse the text documents will be much bigger

The reason why I decided for text documents and not directly creating new au3.scrupts in a folder is because the users who will use this reg.au3  - if finished I will convert to exe - don't have autoit installed.

Next step is creating an option maybe in a menubar which allows the user to create an own user-defined gui saved in a text document.

It's is hard to explain so I will post soon my finished script.

I'm sure that this is an usefull script if it is finished.

See you

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...