Jump to content
Sign in to follow this  

variable issue

Recommended Posts

Hello IM new to AutoIT
I have been Scripting In batch code For a long time

What I want to do:
I have been trying to make a simple script to communicate over a network
Here it is:

#cs ----------------------------------------------------------------------------

 AutoIt Version:
 Author:         DarkPhoeniX

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

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

#Region ### START Koda GUI section ###
Global $Form1 = GUICreate("Saddle Server", 333, 450, 192, 124)
Global $IPAddress1Input = _GUICtrlIpAddress_Create($Form1, 40, 24, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1Input, "")
Global $Label1 = GUICtrlCreateLabel("IP :", 16, 24, 22, 20)
GUICtrlSetFont($Label1, 10, 400, 0, "MS Sans Serif")
Global $PortInput1 = GUICtrlCreateInput("0", 232, 24, 65, 21)
Global $Label2 = GUICtrlCreateLabel("Port :", 198, 24, 34, 20)
GUICtrlSetFont($Label2, 10, 400, 0, "MS Sans Serif")
Global $TestButton = GUICtrlCreateButton("Test Connection", 208, 56, 99, 25)
Global $ClientInfoButton = GUICtrlCreateButton("Client Info", 207, 87, 99, 25)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE

        Case $TestButton
        Case $ClientInfoButton

Func IPsetup()
    Global $szIPADDRESS = _GUICtrlIpAddress_Get($IPAddress1Input)
    if $szIPADDRESS == "" Then
        MsgBox(4112, "Error", "Please Enter IP Address")
    Global $nPORT = $PortInput1
    if $nPORT == "0" Then
        MsgBox(4112, "Error", "Please Enter Port Number" & $nPORT & $PortInput1 )

Func Speak()
    Local $ConnectedSocket, $szData

    $ConnectedSocket = -1
    $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)

    If @error Then
        MsgBox(4112, "Error", "Connection to Flank Failed: " & @error)
        ;Loop forever asking for data to send to the SERVER
        While 1
            ; InputBox for data to transmit
            $szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:")

            ; If they cancel the InputBox or leave it blank we exit our forever loop
            If @error Or $szData = "" Then ExitLoop

            ; We should have data in $szData... lets attempt to send it through our connected socket.
            ; convert AutoIt native UTF-16 to UTF-8
            TCPSend($ConnectedSocket, StringToBinary($szData, 4))

            ; If the send failed with @error then the socket has disconnected
            If @error Then ExitLoop

Please note IPsetup()

at Global $nPORT = $PortInput1
The variable $PortInput1 keeps reverting to 4
I have perversely typed 4 in for a test into the input-box


The error seems to be in :
Global $PortInput1 = GUICtrlCreateInput("0", 232, 24, 65, 21)
but when I change $PortInput1 to $PortInput
I get the same problem

I ran this code on my other PC and it works fine
But after a autoit reinstalling and PC restart the $PortInput1 keeps reverting back to my previous input (4)
What is Wrong!?

Share this post

Link to post
Share on other sites

Hello and welcome to the forums :)

When you do this:


Global $nPORT = $PortInput1


You put the value of $PortInput1 inside $nPort.

But what is the value of $PortInput1? :)


Global $PortInput1 = GUICtrlCreateInput("0", 232, 24, 65, 21)


The value of $PortInput1 is the return value of the function GUICtrlCreateInput("0", 232, 24, 65, 21).

So let's have a look to the return value of this function in the help file of Autoit:


Returns the identifier (controlID) of the new control.
Returns 0.



So what there is inside $PortInput1 is not what the user wrote in the "port" box, but the control ID of this box :)

If you want to get the content of what is inside the box, you must use GUICtrlRead()

So what you need to do is change:


Global $nPORT = $PortInput1


by this:


Global $nPORT = GUICtrlRead($PortInput1)




Share this post

Link to post
Share on other sites

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...