Jump to content

use #Include in a loop?


Recommended Posts

Look for #include in AutoIt help file:

#include

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

Includes a file in the current script.

#include "[path\]filename"

#include <filename>

Parameters

filename The filename of the current script to include. Path is optional. This must be a string--it cannot be a variable.

If "..." is used, the filename is taken to be relative to the current script.

If <...> is used the filename is taken to be relative to include library directory (usually C:\Program Files\AutoIt3\Include). The include library contains many pre-written user-functions for you to use!

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

You can use execute, however:

Horrible Pseudocode:

Open file1, read the text (function) that you want to run, write that text to a variable, $dynamicFunction1
close the file
Open file2, read the text (second function) that you want to run, write that text to a variable, $dynamicFunction2
close the file

Execute($dynamicFunction1)
Execute($dynamicFunction2)

I think the Execute command is what you need.

( I hope that doesn't translate to "I command you to die")

Edited by Jrowe
Link to comment
Share on other sites

You can use execute, however:

Horrible Pseudocode:

Open file1, read the text (function) that you want to run, write that text to a variable, $dynamicFunction1
close the file
Open file2, read the text (second function) that you want to run, write that text to a variable, $dynamicFunction2
close the file

Execute($dynamicFunction1)
Execute($dynamicFunction2)

I think the Execute command is what you need.

( I hope that doesn't translate to "I command you to die")

That wouldn't work at all, you can't have tried that.

You simply have to explicitly include the include file or you have to write a second script which adds the include files to the first script and then runs it.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <NomadMemory.au3>


;Initialize variables
Global $GUIWidth
Global $GUIHeight
Global $FuncVar

$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("New GUI", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it
$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

;Create an "Assign Text to Variable" button
$Assign_Btn = GUICtrlCreateButton("Assign", 5, 210, 70, 25)
$Execute_Btn = GUICtrlCreateButton("Execute", 75, 210, 70, 25)

;Create a "CANCEL" button
$Cancel_Btn = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)

;Show window/Make the window visible
GUISetState(@SW_SHOW)

;Loop until:
;- user presses Esc
;- user presses Alt+F4
;- user clicks the close button
While 1
 ;After every loop check if the user clicked something in the GUI window
   $msg = GUIGetMsg()

   Select
   
    ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
         GUIDelete()
       ;Exit the script
         Exit
         
    ;Check if user clicked on the "OK" button
      Case $msg = $Assign_Btn
         $FuncVar = GUICtrlRead($Edit_1)
      Case $msg = $Execute_Btn
        Execute($FuncVar)
    ;Check if user clicked on the "CANCEL" button
      Case $msg = $Cancel_Btn
         MsgBox(64, "New GUI", "You clicked on the Cancel button!")
         
   EndSelect

WEnd

Write a function into the edit box, hit the assign button, and then hit the execute button.

The function will then run...

Wouldn't it be exactly the same as reading the function from a text file and assigning it to a variable?

Link to comment
Share on other sites

GUICtrlSetColor($Edit_1,0xff0000) + Sleep(2000) + GUICtrlSetColor($Edit_1,0xff00ff) + Sleep(2000) + GUICtrlSetColor($Edit_1,0x0000ff) + Sleep(2000) + GUICtrlSetColor($Edit_1,0x000000)

Paste that into the edit box, then hit assign, and hit execute.

The text will change from red to pink to blue, back to black

You can chain functions on a single line, as well.

Let's say you had the function

MsgBox(64, "", "Here's a Dynamic Function!")

stored in a file called "functions.txt" on the first line, with other functions on the following lines.

By doing this

$file = FileOpen("functions.txt", 0)
$DynamicFunction = FileReadLine($file,1)
FileClose($file)
Execute($DynamicFunction)

You're doing exactly what I proposed in my horrible pseudocode.

Link to comment
Share on other sites

Write a function into the edit box, hit the assign button, and then hit the execute button.

The function will then run...

Thank for Reply.

But I have not "NomadMemory.au3" in my Include Folder.

I have tried with "Memory" & "MemoryConstants.au3", That wouldn't work at all.

Share share share... and share share shareForum AutoIT Việt

Link to comment
Share on other sites

Lol, im sorry,that was random crap from another script. Delete the #nomadmemory include and it should work just fine.

Link to comment
Share on other sites

(My Enlish is not Good :) )

I need help in this case:

Fisrt File: File1.au3

Func File1()
 MsgBox(0,"File1","Test1")
EndFunc

Second File: File2.au3

Func File2()
 MsgBox(0,"File2","Test2")
EndFunc

Main File: Main.au3

For $i=1 To 2 Step
 #include "File"&$i;Error here, how can I fix it?
Next

File1();Call Function in File1.au3
File2();Call Function in File2.au3

When I compile main.au3, does it work normal?

:) Thanks

The #include statement is a compiler directive, and is interpreted at compile time.

It is not interpreted at run time. By run time, the substitution of code from the #include file into the script has already happened.

Variables cannot be used to specify the #include file, as they cannot be used to specify the source for FileInstall(), because the path to the file must be resolved at compile time before any script code is run that would give value to the variables.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...