Jump to content

A little help with GUI and Buttons


eeglave
 Share

Recommended Posts

First of all let me say thanks for any help I recieve I am new to this and appriciate the tool itself and the community as well.

I am having trouble with buttons and GUI . It is proabaly something stupid but I can't fiqure it out. At this time I am only trying to open a msage box

when a button is pressed within a gui. I will modify later. Thanks in advance for any help

Here is my code:

; Tool for quicly setting TMC and SMC CPN IPV4 Settings

#include 

#include 

#include 

#include 

#include 

#include 



Main()

Func Main()

#Region ### START Koda GUI section ### Form=U:\Downloads\Programing\Autoit\Koda\Forms\CPNFORM.kxf

$Form1 = GUICreate("CPN IPV4 Settings", 264, 550, 414, 146)

GUISetFont(12, 400, 0, "NetSoft")

$FacLabel = GUICtrlCreateLabel("Choose The Facility", 16, 16, 194, 22)

$Combo1 = GUICtrlCreateCombo("", 16, 56, 209, 25)

GUICtrlSetData(-1, "TMC|SMC")

$PingButton = GUICtrlCreateButton("PING", 8, 509, 121, 25)

GUICtrlSetOnEvent (-1 ,"PINGON")

$ApplyButton = GUICtrlCreateButton("APPLY", 137, 509, 121, 25)

GUICtrlSetOnEvent (-1 ,"APPLYON" )

$IPIP = _GUICtrlIpAddress_Create($Form1, 16, 112, 201, 25)

_GUICtrlIpAddress_Set($IPIP, "0.0.0.0")

$SubnetMaskIP = _GUICtrlIpAddress_Create($Form1, 16, 168, 201, 25)

_GUICtrlIpAddress_Set($SubnetMaskIP, "255.255.255.0")

$IPLabel = GUICtrlCreateLabel("IP", 16, 88, 24, 22)

$SubnetLabel = GUICtrlCreateLabel("Subnet", 16, 146, 64, 22)

$GatewayLabel = GUICtrlCreateLabel("Gateway", 16, 201, 74, 22)

$GatewayIP = _GUICtrlIpAddress_Create($Form1, 16, 225, 201, 25)

_GUICtrlIpAddress_Set($GatewayIP, "0.0.0.0")

$DNSLabel = GUICtrlCreateLabel("DNS", 16, 256, 34, 22)

$DNS1 = _GUICtrlIpAddress_Create($Form1, 16, 281, 201, 25)

_GUICtrlIpAddress_Set($DNS1, "170.150.160.107")

$DNS2 = _GUICtrlIpAddress_Create($Form1, 16, 310, 201, 25)

_GUICtrlIpAddress_Set($DNS2, "10.154.24.11")

$DNS3 = _GUICtrlIpAddress_Create($Form1, 16, 342, 201, 25)

_GUICtrlIpAddress_Set($DNS3, "159.139.152.114")

$WinsLabel = GUICtrlCreateLabel("WINS", 16, 374, 44, 22)

$WINS1 = _GUICtrlIpAddress_Create($Form1, 16, 399, 201, 25)

_GUICtrlIpAddress_Set($WINS1, "170.150.160.107")

$WINS2 = _GUICtrlIpAddress_Create($Form1, 16, 428, 201, 25)

_GUICtrlIpAddress_Set($WINS2, "10.154.24.11")

$WINS3 = _GUICtrlIpAddress_Create($Form1, 16, 460, 201, 25)

_GUICtrlIpAddress_Set($WINS3, "159.139.152.114")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###





While 1

$Fac_Chosen = GUICtrlRead($Combo1)

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Combo1

$Fac_Chosen = GUICtrlRead($Combo1)

Switch $Fac_Chosen

Case "TMC"

_GUICtrlIpAddress_Set($IPIP, "10.34.238.0")

_GUICtrlIpAddress_Set($GatewayIP, "10.34.238.1")

Case "SMC"

_GUICtrlIpAddress_Set($IPIP, "10.34.97.0")

_GUICtrlIpAddress_Set($GatewayIP, "10.34.97.1")

EndSwitch

Case $PingButton

GUICtrlSetOnEvent ($PingButton,"PINGON" )

Case $ApplyButton

GUICtrlSetOnEvent ($ApplyButton ,"APPLYON" )



EndSwitch

WEnd

EndFunc

;--------------- Functions ---------------

Func PINGON()

MsgBox(0, "You clicked on", "PING")

EndFunc

Func APPLYON()

MsgBox(0, "You clicked on", "APPLY")

EndFunc
Link to comment
Share on other sites

you cannot use event and msgloops simultaneously

this should help

; Tool for quicly setting TMC and SMC CPN IPV4 Settings

#include <Guiconstantsex.au3>

#include <guiipaddress.au3>



Main()

Func Main()

#region ### START Koda GUI section ### Form=U:DownloadsProgramingAutoitKodaFormsCPNFORM.kxf

$Form1 = GUICreate("CPN IPV4 Settings", 264, 550, 414, 146)

GUISetFont(12, 400, 0, "NetSoft")

$FacLabel = GUICtrlCreateLabel("Choose The Facility", 16, 16, 194, 22)

$Combo1 = GUICtrlCreateCombo("", 16, 56, 209, 25)

GUICtrlSetData(-1, "TMC|SMC")

$PingButton = GUICtrlCreateButton("PING", 8, 509, 121, 25)

GUICtrlSetOnEvent(-1, "PINGON")

$ApplyButton = GUICtrlCreateButton("APPLY", 137, 509, 121, 25)

GUICtrlSetOnEvent(-1, "APPLYON")

$IPIP = _GUICtrlIpAddress_Create($Form1, 16, 112, 201, 25)

_GUICtrlIpAddress_Set($IPIP, "0.0.0.0")

$SubnetMaskIP = _GUICtrlIpAddress_Create($Form1, 16, 168, 201, 25)

_GUICtrlIpAddress_Set($SubnetMaskIP, "255.255.255.0")

$IPLabel = GUICtrlCreateLabel("IP", 16, 88, 24, 22)

$SubnetLabel = GUICtrlCreateLabel("Subnet", 16, 146, 64, 22)

$GatewayLabel = GUICtrlCreateLabel("Gateway", 16, 201, 74, 22)

$GatewayIP = _GUICtrlIpAddress_Create($Form1, 16, 225, 201, 25)

_GUICtrlIpAddress_Set($GatewayIP, "0.0.0.0")

$DNSLabel = GUICtrlCreateLabel("DNS", 16, 256, 34, 22)

$DNS1 = _GUICtrlIpAddress_Create($Form1, 16, 281, 201, 25)

_GUICtrlIpAddress_Set($DNS1, "170.150.160.107")

$DNS2 = _GUICtrlIpAddress_Create($Form1, 16, 310, 201, 25)

_GUICtrlIpAddress_Set($DNS2, "10.154.24.11")

$DNS3 = _GUICtrlIpAddress_Create($Form1, 16, 342, 201, 25)

_GUICtrlIpAddress_Set($DNS3, "159.139.152.114")

$WinsLabel = GUICtrlCreateLabel("WINS", 16, 374, 44, 22)

$WINS1 = _GUICtrlIpAddress_Create($Form1, 16, 399, 201, 25)

_GUICtrlIpAddress_Set($WINS1, "170.150.160.107")

$WINS2 = _GUICtrlIpAddress_Create($Form1, 16, 428, 201, 25)

_GUICtrlIpAddress_Set($WINS2, "10.154.24.11")

$WINS3 = _GUICtrlIpAddress_Create($Form1, 16, 460, 201, 25)

_GUICtrlIpAddress_Set($WINS3, "159.139.152.114")

GUISetState(@SW_SHOW)

#endregion ### END Koda GUI section ###




Local $Fac_Chosen
While 1


$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Combo1

$Fac_Chosen = GUICtrlRead($Combo1)

Switch $Fac_Chosen

Case "TMC"

_GUICtrlIpAddress_Set($IPIP, "10.34.238.0")

_GUICtrlIpAddress_Set($GatewayIP, "10.34.238.1")

Case "SMC"

_GUICtrlIpAddress_Set($IPIP, "10.34.97.0")

_GUICtrlIpAddress_Set($GatewayIP, "10.34.97.1")

EndSwitch

Case $PingButton
PINGON()
;GUICtrlSetOnEvent($PingButton, "PINGON")
Case $ApplyButton
APPLYON()
;GUICtrlSetOnEvent($ApplyButton, "APPLYON")
EndSwitch

WEnd

EndFunc ;==>Main

;--------------- Functions ---------------

Func PINGON()

MsgBox(0, "You clicked on", "PING")

EndFunc ;==>PINGON

Func APPLYON()

MsgBox(0, "You clicked on", "APPLY")

EndFunc ;==>APPLYON

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

use Ping orelse if your the client then use TCPConnect

if facing any problems try to search in the helpfiles or in the forum

if no result then post the code to get possible solutions

Br,

Phoenix xl

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Here is the Script I have so far corrected like you showed me before:

; Tool for quicly setting TMC and SMC CPN IPV4 Settings



#include 

#include 

#include 

#include 

#include 

#include 



Main()



Global $CurrentIP = GUICtrlRead($IPIP)



Func Main()



#region ### START Koda GUI section ### Form=U:DownloadsProgramingAutoitKodaFormsCPNFORM.kxf



$Form1 = GUICreate("TMC IPV4 Settings", 264, 550, 414, 146)



GUISetFont(12, 400, 0, "NetSoft")



$FacLabel = GUICtrlCreateLabel("Choose The Facility", 16, 16, 194, 22)



$Combo1 = GUICtrlCreateCombo("", 16, 56, 209, 25)



GUICtrlSetData(-1, "TMC CPN|SMC CPN|TMC VLAN 70|SMC VLAN 70")



$PingButton = GUICtrlCreateButton("PING", 8, 509, 121, 25)



GUICtrlSetOnEvent(-1, "PINGON")



$ApplyButton = GUICtrlCreateButton("APPLY", 137, 509, 121, 25)



GUICtrlSetOnEvent(-1, "APPLYON")



$IPIP = _GUICtrlIpAddress_Create($Form1, 16, 112, 201, 25)



_GUICtrlIpAddress_Set($IPIP, "0.0.0.0")



$SubnetMaskIP = _GUICtrlIpAddress_Create($Form1, 16, 168, 201, 25)



_GUICtrlIpAddress_Set($SubnetMaskIP, "255.255.255.0")



$IPLabel = GUICtrlCreateLabel("IP", 16, 88, 24, 22)



$SubnetLabel = GUICtrlCreateLabel("Subnet", 16, 146, 64, 22)



$GatewayLabel = GUICtrlCreateLabel("Gateway", 16, 201, 74, 22)



$GatewayIP = _GUICtrlIpAddress_Create($Form1, 16, 225, 201, 25)



_GUICtrlIpAddress_Set($GatewayIP, "0.0.0.0")



$DNSLabel = GUICtrlCreateLabel("DNS", 16, 256, 34, 22)



$DNS1 = _GUICtrlIpAddress_Create($Form1, 16, 281, 201, 25)



_GUICtrlIpAddress_Set($DNS1, "170.150.160.107")



$DNS2 = _GUICtrlIpAddress_Create($Form1, 16, 310, 201, 25)



_GUICtrlIpAddress_Set($DNS2, "10.154.24.11")



$DNS3 = _GUICtrlIpAddress_Create($Form1, 16, 342, 201, 25)



_GUICtrlIpAddress_Set($DNS3, "159.139.152.114")



$WinsLabel = GUICtrlCreateLabel("WINS", 16, 374, 44, 22)



$WINS1 = _GUICtrlIpAddress_Create($Form1, 16, 399, 201, 25)



_GUICtrlIpAddress_Set($WINS1, "170.150.160.107")



$WINS2 = _GUICtrlIpAddress_Create($Form1, 16, 428, 201, 25)



_GUICtrlIpAddress_Set($WINS2, "10.154.24.11")



$WINS3 = _GUICtrlIpAddress_Create($Form1, 16, 460, 201, 25)



_GUICtrlIpAddress_Set($WINS3, "159.139.152.114")





GUISetState(@SW_SHOW)





#endregion ### END Koda GUI section ###









Local $Fac_Chosen

While 1





$nMsg = GUIGetMsg()



Switch $nMsg



Case $GUI_EVENT_CLOSE



Exit



Case $Combo1



$Fac_Chosen = GUICtrlRead($Combo1)



Switch $Fac_Chosen



Case "TMC CPN"



_GUICtrlIpAddress_Set($IPIP, "10.34.238.0")



_GUICtrlIpAddress_Set($GatewayIP, "10.34.238.1")



Case "SMC CPN"



_GUICtrlIpAddress_Set($IPIP, "10.34.97.0")



_GUICtrlIpAddress_Set($GatewayIP, "10.34.97.1")



Case "TMC VLAN 70"



_GUICtrlIpAddress_Set($IPIP, "10.136.157.0")



_GUICtrlIpAddress_Set($GatewayIP, "10.136.157.1")



Case "SMC VLAN 70"



_GUICtrlIpAddress_Set($IPIP, "10.136.159.0")



_GUICtrlIpAddress_Set($GatewayIP, "10.136.159.1")



EndSwitch



Case $PingButton

PINGON()

;GUICtrlSetOnEvent($PingButton, "PINGON")

Case $ApplyButton

APPLYON()

;GUICtrlSetOnEvent($ApplyButton, "APPLYON")

EndSwitch



WEnd



EndFunc ;==>Main



;--------------- Functions ---------------



Func PINGON()



MsgBox(0, "Your current IP is on", $CurrentIP)

Ping ($CurrentIP)



EndFunc ;==>PINGON



Func APPLYON()



MsgBox(0, "You clicked on", "APPLY")



EndFunc ;==>APPLYON
Link to comment
Share on other sites

How about something like this?

#include <GUIConstantsEx.au3>
#include <GUIIPAddress.au3>
Global $CurrentIP
Main()
;~ Global $CurrentIP = GUICtrlRead($IPIP)

Func APPLYON()
     MsgBox(0, "You clicked on", "APPLY")
EndFunc   ;==>APPLYON
Func Main()
     #region ### START Koda GUI section ### Form=U:DownloadsProgramingAutoitKodaFormsCPNFORM.kxf
     $Form1 = GUICreate("TMC IPV4 Settings", 264, 550, 414, 146)
     GUISetFont(12, 400, 0, "NetSoft")
     $FacLabel = GUICtrlCreateLabel("Choose The Facility", 16, 16, 194, 22)
     $Combo1 = GUICtrlCreateCombo("", 16, 56, 209, 25)
     GUICtrlSetData(-1, "TMC CPN|SMC CPN|TMC VLAN 70|SMC VLAN 70")
     $PingButton = GUICtrlCreateButton("PING", 8, 509, 121, 25)
;~    GUICtrlSetOnEvent(-1, "PINGON")
     $ApplyButton = GUICtrlCreateButton("APPLY", 137, 509, 121, 25)
;~    GUICtrlSetOnEvent(-1, "APPLYON")
     $IPIP = _GUICtrlIpAddress_Create($Form1, 16, 112, 201, 25)
     _GUICtrlIpAddress_Set($IPIP, "0.0.0.0")
     $SubnetMaskIP = _GUICtrlIpAddress_Create($Form1, 16, 168, 201, 25)
     _GUICtrlIpAddress_Set($SubnetMaskIP, "255.255.255.0")
     $IPLabel = GUICtrlCreateLabel("IP", 16, 88, 24, 22)
     $SubnetLabel = GUICtrlCreateLabel("Subnet", 16, 146, 64, 22)
     $GatewayLabel = GUICtrlCreateLabel("Gateway", 16, 201, 74, 22)
     $GatewayIP = _GUICtrlIpAddress_Create($Form1, 16, 225, 201, 25)
     _GUICtrlIpAddress_Set($GatewayIP, "0.0.0.0")
     $DNSLabel = GUICtrlCreateLabel("DNS", 16, 256, 34, 22)
     $DNS1 = _GUICtrlIpAddress_Create($Form1, 16, 281, 201, 25)
     _GUICtrlIpAddress_Set($DNS1, "170.150.160.107")
     $DNS2 = _GUICtrlIpAddress_Create($Form1, 16, 310, 201, 25)
     _GUICtrlIpAddress_Set($DNS2, "10.154.24.11")
     $DNS3 = _GUICtrlIpAddress_Create($Form1, 16, 342, 201, 25)
     _GUICtrlIpAddress_Set($DNS3, "159.139.152.114")
     $WinsLabel = GUICtrlCreateLabel("WINS", 16, 374, 44, 22)
     $WINS1 = _GUICtrlIpAddress_Create($Form1, 16, 399, 201, 25)
     _GUICtrlIpAddress_Set($WINS1, "170.150.160.107")
     $WINS2 = _GUICtrlIpAddress_Create($Form1, 16, 428, 201, 25)
     _GUICtrlIpAddress_Set($WINS2, "10.154.24.11")
     $WINS3 = _GUICtrlIpAddress_Create($Form1, 16, 460, 201, 25)
     _GUICtrlIpAddress_Set($WINS3, "159.139.152.114")
     GUISetState(@SW_SHOW)
     #endregion ### END Koda GUI section ###
     Local $Fac_Chosen
     While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
               Case $GUI_EVENT_CLOSE
                    Exit
               Case $Combo1
                    $Fac_Chosen = GUICtrlRead($Combo1)
                    Switch $Fac_Chosen
                         Case "TMC CPN"
                              _GUICtrlIpAddress_Set($IPIP, "10.34.238.0")
                              _GUICtrlIpAddress_Set($GatewayIP, "10.34.238.1")
                         Case "SMC CPN"
                              _GUICtrlIpAddress_Set($IPIP, "10.34.97.0")
                              _GUICtrlIpAddress_Set($GatewayIP, "10.34.97.1")
                         Case "TMC VLAN 70"
                              _GUICtrlIpAddress_Set($IPIP, "10.136.157.0")
                              _GUICtrlIpAddress_Set($GatewayIP, "10.136.157.1")
                         Case "SMC VLAN 70"
                              _GUICtrlIpAddress_Set($IPIP, "10.136.159.0")
                              _GUICtrlIpAddress_Set($GatewayIP, "10.136.159.1")
                    EndSwitch
               Case $PingButton
                    $CurrentIP = _GUICtrlIpAddress_Get($IPIP)
                    PINGON()

               Case $ApplyButton
                    APPLYON()

          EndSwitch
     WEnd
EndFunc   ;==>Main
;--------------- Functions ---------------
Func PINGON()
     MsgBox(0, "Your current IP is on", $CurrentIP)
     Ping($CurrentIP)
EndFunc   ;==>PINGON

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

Link to comment
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
 Share

  • Recently Browsing   0 members

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