Jump to content

Recommended Posts

Posted

I'm wondering if, once again, I might be able to get some assistance from those of you who are much more knowledgeable than I. I have written a function that uses an InputBox and asks for the name of the adapter the user wants to manipulate. The script is designed to assign the name of the adapter to the entire program (a global variable) for use in other functions throughout its use. It can also be called again to change the adapter or, if it mistakenly didn't get set, set it. The issue I'm having is that I can't figure out a way to keep the function from "clearing" or "deleting" the variable if the cancel button is pressed. The idea is that if the user assigns the variable at the start of the program running (the function is called before anything else happens in the script) then, mistakenly/accidentally, runs the function again and, at the InputBox, the user clicks "Cancel" it will leave the variable alone. Currently, I've been able to (after much trial, tribulation, and troubleshooting) get it actually cancel the operation when "Cancel" is pressed or assign the variable as needed/preferred when the information is entered and "OK" is pressed. However, if "Cancel" is pressed (again, after the variable has already been assigned), it completely clears the variable's assignment (as evidenced by calling the variable in another function. Below is the code for the function. Please let me know if more functions are needed for diagnosis.

Func selectAdapter()
    Global $adapterName
    $adapterName = InputBox("Select Adapter", "Please input the adapter name" & @CRLF & @CRLF & "or leave it at the default:", "Ethernet")
    If @error = 1 Then
        Return
    EndIf

EndFunc

Posted (edited)

To sum it up, only update the global adapter name variable if they successfully enter a new one.

 

Global $g_adapterName = "Ethernet"

example()
MsgBox(0,"",$g_adapterName)

example()
MsgBox(0,"",$g_adapterName)

;==========================================================================
;
;==========================================================================
Func example()
    Local $adapterName = InputBox("Select Adapter", "Please input the adapter name" & @CRLF & @CRLF & "or leave it at the default:", $g_adapterName)
    If Not @error Then $g_adapterName = $adapterName
EndFunc

 

Edited by TheXman

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
×
×
  • Create New...