Jump to content

Recommended Posts

Posted (edited)

I wanted to make a GUI form for inputting an IP and Port to then connect to the server that has that IP, however, when I use GUICtrlRead on $cl_IP (which is an IP input box), I get 0 eventhough it should give me 127.0.0.1, what am I doing wrongly here?

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

Global $IP
Global $Port

; Connect to IP
$MainForm = GUICreate("Server Starter", 158, 113, 192, 124);
$cl_IP = _GUICtrlIpAddress_Create($MainForm, 16, 16, 130, 21);
_GUICtrlIpAddress_Set($cl_IP, "127.0.0.1")
$cl_Port = GUICtrlCreateInput("1018", 56, 44, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER));
$bStartServer = GUICtrlCreateButton("Connect", 40, 72, 75, 25);
GUISetState(@SW_SHOW);

msgbox(0, "", GUICtrlRead($cl_IP))

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit;
         Case $bStartServer
            $IP = GUICtrlRead($cl_IP);
            $Port = CheckPort($cl_Port);
            GUIDelete($MainForm);
            ExitLoop;
    EndSwitch
 WEnd

Func CheckPort($PortGui)
   if (GUICtrlRead($PortGui) >= 0 and GUICtrlRead($PortGui) <= 65535) then
      return GUICtrlRead($PortGui);
   Else
      msgbox(0, "Port is not correct", "Please, pick a different Port");
      return -1;
   EndIf
EndFunc

 

Edited by Hylia
Posted

try..

 

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

Global $IP
Global $Port

; Connect to IP
$MainForm = GUICreate("Server Starter", 158, 113, 192, 124);
$cl_IP = _GUICtrlIpAddress_Create($MainForm, 16, 16, 130, 21);
_GUICtrlIpAddress_Set($cl_IP, "127.0.0.1")
$cl_Port = GUICtrlCreateInput("1018", 56, 44, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER));
$bStartServer = GUICtrlCreateButton("Connect", 40, 72, 75, 25);
GUISetState(@SW_SHOW);

 MsgBox( 0, "Information", "IP Address: " & _GUICtrlIpAddress_Get($cl_IP))


While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit;
         Case $bStartServer
            $IP = GUICtrlRead($cl_IP);
            $Port = CheckPort($cl_Port);
            GUIDelete($MainForm);
            ExitLoop;
    EndSwitch
 WEnd

Func CheckPort($PortGui)
   if (GUICtrlRead($PortGui) >= 0 and GUICtrlRead($PortGui) <= 65535) then
      return GUICtrlRead($PortGui);
   Else
      msgbox(0, "Port is not correct", "Please, pick a different Port");
      return -1;
   EndIf
EndFunc

8)

NEWHeader1.png

Posted
  On 10/9/2015 at 10:20 PM, Valuater said:

try..

 

_GUICtrlIpAddress_Get($cl_IP)

8)

Thanks that did the trick, I assume GUICtrlReadData doesn't work properly for an IP Input box then?

  • Moderators
Posted

Hylia,

  Quote

 I assume GUICtrlReadData doesn't work properly for an IP Input box then?

Correct. In general, GUICtrl* functions only work on controls created by the native GUICtrlCreate* functions which return a ControlID - these controls are tracked internally by AutoIt. To interact with controls created by the UDF functions (those preceded by an underscore), you usually need to use other UDF functions - as is the case here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...