# Function Not Passing Variable

## Recommended Posts

In my For/Next loop \$intCount is assigned 1 as you would expect but when I call GetOctetNumber function it does not seem \$intCount is set to 1 as it displays "You entered a non-numeric digit" instead of opening up an input box.  I know this works in Vbscript but I am trying to learn AutoIT.  Any assistance would be greatly appreciated.  Thank You!

```Global \$intIPO1, \$intIPO2, \$intIPO3, \$intIPO4, \$varIPO, \$intCount

GetWholeIP()

Func GetWholeIP()
For \$intCount = 1 To 4
GetOctetNumber()
If \$intCount = 1 Then
\$intIPO1 = \$varIPO
ElseIf \$intCount = 2 Then
\$intIPO2 = \$varIPO
ElseIf \$intCount = 3 Then
\$intIPO3 = \$varIPO
ElseIf \$intCount = 4 Then
\$intIPO4 = \$varIPO
EndIf
Next
EndFunc   ;==>GetWholeIP

Func GetIP2_3()
For \$intCount = 2 To 3
GetOctetNumber()
If \$intCount = 2 Then
\$intIPO2 = \$varIPO
ElseIf \$intCount = 3 Then
\$intIPO3 = \$varIPO
EndIf
Next
EndFunc   ;==>GetIP2_3

Func GetOctetNumber()
If \$intCount = 1 Then
\$varIPO = InputBox("Enter the First Octet Number", "First Octet Number")
ElseIf \$intCount = 2 Then
\$varIPO = InputBox("Enter the Second Octet Number", "Second Octet Number")
ElseIf \$intCount = 3 Then
\$varIPO = InputBox("Enter the Third Octet Number", "Third Octet Number")
ElseIf \$intCount = 4 Then
\$varIPO = InputBox("Enter the Forth Octet Number", "Forth Octet Number")
EndIf

If Not StringIsDigit(\$varIPO) Then
MsgBox(0, "Not Numeric", "You entered a non-numeric digit")
GetOctetNumber()
ElseIf \$varIPO < 1 Then
MsgBox(0, "Number to Small", "The Number You Entered was to Small")
GetOctetNumber()
ElseIf \$varIPO > 254 Then
MsgBox(0, "Number to Large", "The Number You Entered was to Large")
GetOctetNumber()
EndIf
Return \$varIPO
EndFunc   ;==>GetOctetNumber```
##### Share on other sites

\$IntCount, when used in a loop like that is considered a Local variable that doesn't require declaration. So this means that you have 2 variables named \$IntCount, one is a global variable with no value, the other is a local variable with a value of 1, but that doesn't get passed to the function GetOctetNumber. GetOctetNumber is looking at your Global variable, and not seeing any value in it.

Here's how to do it with no globals used at all.

```GetWholeIP()

Func GetWholeIP()
Local \$intIPO, \$aIPO[4]
For \$intCount = 0 To 3
\$sIPO = GetOctetNumber(\$intCount)
\$intIPO &= \$sIPO & "."
\$aIPO[\$intCount] = \$sIPO
Next
\$intIPO = StringLeft(\$intIPO, StringLen(\$intIPO) - 1)
For \$I = 0 To 3
ConsoleWrite("\$aIPO[" & \$I & "] = " & \$aIPO[\$I] & @CRLF)
Next
ConsoleWrite("\$intIPO = " & \$intIPO & @CRLF)
EndFunc   ;==>GetWholeIP

Func GetOctetNumber(\$Incoming)
Return InputBox("Enter the Octet", "Octet Number")
EndFunc   ;==>GetOctetNumber```

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...