DarkP03n1X Posted May 24, 2013 Share Posted May 24, 2013 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: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 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, "0.0.0.0") 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) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $TestButton IPsetup() Case $ClientInfoButton EndSwitch WEnd Func IPsetup() Global $szIPADDRESS = _GUICtrlIpAddress_Get($IPAddress1Input) if $szIPADDRESS == "0.0.0.0" Then MsgBox(4112, "Error", "Please Enter IP Address") EndIf Global $nPORT = $PortInput1 if $nPORT == "0" Then MsgBox(4112, "Error", "Please Enter Port Number" & $nPORT & $PortInput1 ) EndIf EndFunc Func Speak() TCPStartup() Local $ConnectedSocket, $szData $ConnectedSocket = -1 $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) If @error Then MsgBox(4112, "Error", "Connection to Flank Failed: " & @error) exit Else ;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 WEnd EndIf EndFunc 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!? Link to comment Share on other sites More sharing options...
Neutro Posted May 24, 2013 Share Posted May 24, 2013 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: Success: Returns the identifier (controlID) of the new control. Failure: 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) . Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
DarkP03n1X Posted May 24, 2013 Author Share Posted May 24, 2013 ThanX a lot that Helped! I have been struggling with this for hours Link to comment Share on other sites More sharing options...
Neutro Posted May 24, 2013 Share Posted May 24, 2013 You're welcome I sometimes also get stuck for some time for little things like this, it's frustrating Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now