Sign in to follow this  
Followers 0
IvanCodin

variable set in one Function used in another

2 posts in this topic

The script I have that sets various variables in the GUI's > I then send it to a function that creates my output file. If I set MustDeclareVars, 1 I found the variables used between the functions look like they are independently. I want to set the varaiable in one function and use it in another. I tried set the values to Global and Local and it still didn't work. The code below isn't functional but depicts what I am trying to do. Could someone point me in the right direction?

; Declair the vars used
$GW_Type = "None"
$ip = ""
$mask = ""

Global $Width = ('499')
Global $Height = ('447')

$GUI1 = GUICreate("Tools - G1", $Width, $Height, 270, 98)
$G1IP = GUICtrlCreateInput("", 115, 46, 150, 20)
GUICtrlSetLimit($G1IP, '23', '23')
GUICtrlCreateLabel("Mask => ", 30, 77)
$G1IP_Mask = GUICtrlCreateInput("", 115, 77, 150, 20)
GUICtrlSetLimit($G1IP_Mask, '23', '23')
$G1But2 = GUICtrlCreateButton("Make My Config", 392, 46, 89, 23, 0)
$GW_Type = "G1"
GUICtrlSetOnEvent($G1, "Config_GW")


$GUI2 = GUICreate("Tools - G2", $Width, $Height, 270, 98)
$G2IP = GUICtrlCreateInput("", 115, 46, 150, 20)
GUICtrlSetLimit($G2IP, '23', '23')
GUICtrlCreateLabel("Mask => ", 30, 77)
$G2IP_Mask = GUICtrlCreateInput("", 115, 77, 150, 20)
GUICtrlSetLimit($G2IP_Mask, '23', '23')
$G1But2 = GUICtrlCreateButton("Make My Config", 392, 46, 89, 23, 0)
$GW_Type = "G2"
GUICtrlSetOnEvent($G1, "Config_GW")


Func Config_GW()
If $GW_Type = "G1" Then
    $ip = GUICtrlRead($G1IP)
    $Mask = GuiCtrlRead($G1IP_Mask)
    GWDoc()
If $GW_Type = "G2" Then
    $ip = GUICtrlRead($G2IP)
    $Mask = GuiCtrlRead($G2IP_Mask)
    GWDoc()
EndFunc

Func GWDoc()
SplashTextOn("Info", "Creating configuration file", 380, 55)
    Sleep(3000)
    SplashOff()
    ;   _CreateGWDoc()
    $GWDoc = "c:\GWDoc.txt"
    $250file = FileOpen($GWDoc, 10) ; Check if file is opened for writing successfully
    If $250file = -1 Then
        MsgBox(0, "Error", "Unable to create the gateway document." & $250file)
        Exit
    EndIf
        FileWrite($250file, "<===  End GW Doc  ===>" & @CRLF)
        FileWrite($250file, "show username" & @CRLF)
    FileWrite($250file, "show interface" & @CRLF)
    FileWrite($250file, "show ip route" & @CRLF)
    FileWrite($250file, "show spantree" & @CRLF)
    FileClose($250file)
    Run("notepad.exe " & $GWDoc)
FileWrite($250file, "ip address " & $ip & " " & $Mask & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites



try instead

; Declair the vars used
$GW_Type = "None"
$ip = ""
$mask = ""

Global $Width = ('499')
Global $Height = ('447')

to

; Declair the vars used
Global $GW_Type = "None",$ip = "",$mask = "",$Width = "499",$Height = "447"

and i think that your funcs Config_GW() with "if" and with no "endif" is badly formated and i dont see the main loop


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


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
Sign in to follow this  
Followers 0