Jump to content

Return variable data from a function into another function


Recommended Posts

How can I get $iIPO2 and $iIPO3 values from the GetPCNumber function into the PingPCGateway function?

PingPCGateway()

;Ping PC Gateway
Func PingPCGateway()
    GetPCNumber()
    MsgBox(0, "", $iIPO2 & "  " & $iIPO3)
    Local $iIPO1 = 10
    Local $iIPO4 = 1
    Local $iIPAddress = ($iIPO1 & "." & $iIPO2 & "." & $iIPO3 & "." & $iIPO4)
    Run(@ComSpec & " /k" & "ping.exe -t " & $iIPAddress)
EndFunc   ;==>PingPCGateway

;Extrapolate Second and Third Octet From PC Number
Func GetPCNumber()
    Local $iPCNumber = InputBox("Enter PC Number", "Enter a 4 digit PC Number")
    If $iPCNumber > "" Then
        Local $iIPO2 = StringRegExpReplace($iPCNumber, "\d{2}$", "")

        Local $iIPO3 = StringRegExpReplace($iPCNumber, "^\d{2}", "")

        If StringTrimRight($iIPO2, 1) = 0 Then
            $iIPO2 = StringTrimLeft($iIPO2, 1)
        EndIf

        If StringTrimRight($iIPO3, 1) = 0 Then
            $iIPO3 = StringTrimLeft($iIPO3, 1)
        EndIf
        If $iIPO3 = 0 Then
            $iIPO3 = 100
        EndIf
    ElseIf $iPCNumber = "" Then
        MsgBox(262160, "Invalid Entry", "Please Enter a Valid Four Digit PC Number")
    EndIf
    ;MsgBox(0, "", $iIPO2)
    ;MsgBox(0, "", $iIPO3)
EndFunc   ;==>GetPCNumber
Edited by m1975michael
Link to comment
Share on other sites

  • Developers

Open the Helpfile on Func where this is nicely explained.

Give it a tried and comeback with some code in case you have issues. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Please review my code and see if there are any changes you suggest.  Is there a good way to get the script to work with out defining the local variables in the while loop.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=CEDUtilv3.2Personal.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Fileversion=3.2
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
Global $hCEDForm = GUICreate("CED Help Desk Utility", 443, 274, 242, 160)
GUISetBkColor(0xA6CAF0)
Global $hPCTools = GUICtrlCreateGroup("Profit Center Tools", 24, 16, 185, 241)
Global $hLabelPCNum = GUICtrlCreateLabel("PC Number", 40, 40, 58, 17)
Global $hPCNumInput = GUICtrlCreateInput("", 40, 59, 31, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetLimit(-1, 4)
Global $hButtonCheckBoxStatus = GUICtrlCreateButton("Execute Checked Items", 40, 212, 125, 25)
Global $hCheckboxPingPC = GUICtrlCreateCheckbox("Ping PC Gateway", 40, 92, 115, 25)
Global $hCheckboxFortiWiFiWeb = GUICtrlCreateCheckbox("Forti WiFi Web Login", 40, 122, 115, 25)
Global $hCheckboxFortiWiFiPutty = GUICtrlCreateCheckbox("Forti WiFi Putty Login", 40, 152, 115, 25)
Global $hCheckboxRDCEDSvr = GUICtrlCreateCheckbox("Remote Desktop CED Server", 40, 182, 155, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $hLableNetworkTools = GUICtrlCreateGroup("Network Tools", 232, 16, 185, 241)
Global $hButtonPingIPInput = GUICtrlCreateButton("Ping IP Address", 248, 122, 125, 25)
Global $hCheckboxClearIP = GUICtrlCreateCheckbox("Clear IP After Execution", 248, 92, 127, 25)
Global $hLabelIPAddress = GUICtrlCreateLabel("IP Address", 248, 40, 58, 17)
Global $hIPAddressInput = GUICtrlCreateInput("", 248, 59, 105, 21)
GUICtrlSetLimit(-1, 15)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButtonPingIPInput
            ;PingIPInput()
        Case $hButtonCheckBoxStatus
            Local $iIPO2
            Local $iIPO3
            Local $iIPAddress
            GetPCNumber($iIPO2, $iIPO3)
            CheckBoxStatus()
    EndSwitch

    Local $aCursorInfo = GUIGetCursorInfo($hCEDForm)
    If $aCursorInfo[2] Then
        If $aCursorInfo[4] = $hPCNumInput Then GUICtrlSetData($hPCNumInput, "")
    EndIf
WEnd

_WinAPI_SetFocus(ControlGetHandle("CED Help Desk Utility", "", $hPCNumInput))

;Profit Center Tools ----------

;Ping PC Gateway
Func PingPCGateway()
    Local $iIPO1 = 10
    Local $iIPO4 = 1
    IPAddress($iIPO1, $iIPO4, $iIPAddress)
    If $iIPO2 = 0 Then
        Return
    EndIf
    PingCmd($iIPO1, $iIPO4)
EndFunc   ;==>PingPCGateway


;Combine IP Address Octets
Func IPAddress($iIPO1, $iIPO4, ByRef $iIPAddress)
    $iIPAddress = ($iIPO1 & "." & $iIPO2 & "." & $iIPO3 & "." & $iIPO4)
EndFunc   ;==>IPAddress

;Ping Command
Func PingCmd($iIPO1, $iIPO4)
    Run(@ComSpec & " /k" & "ping.exe -t " & $iIPAddress)
EndFunc   ;==>PingCmd

;Extrapolate Second and Third Octet From PC Number
Func GetPCNumber(ByRef $iIPO2, ByRef $iIPO3)
    Local $iPCNumber = GUICtrlRead($hPCNumInput)
    If $iPCNumber > "" Then
        $iIPO2 = StringRegExpReplace($iPCNumber, "\d{2}$", "")
        If $iIPO2 = 0 Then
            MsgBox(262160, "Invalid Entry", "Please Enter a Valid Four Digit PC Number")
            _WinAPI_SetFocus(ControlGetHandle("CED Help Desk Utility", "", $hPCNumInput))
            GUICtrlSetData($hPCNumInput, "")
        EndIf

        $iIPO3 = StringRegExpReplace($iPCNumber, "^\d{2}", "")

        If StringTrimRight($iIPO2, 1) = 0 Then
            $iIPO2 = StringTrimLeft($iIPO2, 1)
        EndIf

        If StringTrimRight($iIPO3, 1) = 0 Then
            $iIPO3 = StringTrimLeft($iIPO3, 1)
        EndIf
        If $iIPO3 = 0 Then
            $iIPO3 = 100
        EndIf
        ;MsgBox(0, "", $iIPO2)
        ;MsgBox(0, "", $iIPO3)

    ElseIf $iPCNumber = "" Then
        MsgBox(262160, "Invalid Entry", "Please Enter a Valid Four Digit PC Number")
        _WinAPI_SetFocus(ControlGetHandle("CED Help Desk Utility", "", $hPCNumInput))
    EndIf
EndFunc   ;==>GetPCNumber

;Check Check Box Status For PC Tools
Func CheckBoxStatus()
    Local $iPCNumber = GUICtrlRead($hPCNumInput)
    If $iPCNumber = "" Then
        Return
    Else
        Local $CheckboxPingPCStatus = ControlCommand($hCEDForm, "", $hCheckboxPingPC, "IsChecked")
        Local $CheckboxFortiWiFiWebStatus = ControlCommand($hCEDForm, "", $hCheckboxFortiWiFiWeb, "IsChecked")
        Local $CheckboxFortiWiFiPuttyStatus = ControlCommand($hCEDForm, "", $hCheckboxFortiWiFiPutty, "IsChecked")
        Local $hCheckboxRDCEDSvrStatus = ControlCommand($hCEDForm, "", $hCheckboxRDCEDSvr, "IsChecked")
        If $CheckboxPingPCStatus = 1 Then
            PingPCGateway()
        EndIf
        If $CheckboxFortiWiFiWebStatus = 1 Then
            ;FortiWiFiWebLogin()
        EndIf
        If $CheckboxFortiWiFiPuttyStatus = 1 Then
            ;FortiWiFiPuttyLogin()
        EndIf
        If $hCheckboxRDCEDSvrStatus = 1 Then
            ;RDCEDSvr()
        EndIf
    EndIf
EndFunc   ;==>CheckBoxStatus
Link to comment
Share on other sites

You want <> or Not ($var = '')

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

 Is there a good way to get the script to work with out defining the local variables in the while loop.

 

If you are asking about vars $iIPO2, $iIPO3 and  $iIPAddress then yes, define them at the top of the script.  These vars are in GLOBAL scope because of where they are defined (outside of any function).

 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

If you are asking about vars $iIPO2, $iIPO3 and  $iIPAddress then yes, define them at the top of the script.  These vars are in GLOBAL scope because of where they are defined (outside of any function).

 

Is there a better way to write the script with out making those variables global? i have tried but failed.

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