Jump to content

Having trouble with simple GUI button control


Kovacic
 Share

Recommended Posts

Hi All, I am noob status when it comes to AutoIt Programming, but im very interested in getting more into it. as for right now, I am so stumped.

Im trying to write a simple GUI that when you put in the IP address of a remote windows computer, it returns some information about it. When I put in the IP Address, it doesnt seem to carry the value to the controls where I have the button. I know this is a super easy fix, but it has me stumped. Here is what I have so far...

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

Global $IP

Opt('MustDeclareVars', 0)
GeeWiz()
Func GeeWiz()
GUICreate("IP", 383, 463, 1481, 119)
$IP = GUICtrlCreateInput("", 120, 48, 137, 21)
$Label1 = GUICtrlCreateLabel("Client IP Address", 144, 31, 84, 17)
$Button1 = GUICtrlCreateButton("GET", 152, 80, 75, 25)
$Group2 = GUICtrlCreateGroup("Data", 48, 136, 297, 313)
$Label2 = GUICtrlCreateLabel("Location of Program Files:", 64, 168, 126, 17)
$Label3 = GUICtrlCreateLabel(".", 200, 168, 7, 17)
$Label4 = GUICtrlCreateLabel("By Mike Kovacic", 160, 424, 84, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()


While 1
    $msg = GUIGetMsg()
    select
        Case $msg = $Button1
        DoSumthin()
            ;RunWait("net use \\" & $IP & "\ipc$",@SW_SHOW)
            ;$Label3 = RegRead("\\" & $IP & "\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion","ProgramFilesDir")
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect
    WEnd
EndFunc 

Func DoSumthin()
$msg = GUIGetMsg()
MsgBox(0, "Value","" & $IP & "", 5)
    
; See if it is pingable
  ;$status = Ping($IP)
    ;If $status Then
      
     ; Perform actions needed
     
   ; Else
    ;     MsgBox(0, "Sorry", "I was unable to PING the remote machine.", 10)
   ; EndIf
endfunc

You will notice much of it is commented out, because I eventually maybe want to pull installed programs from a remote computer. Anyhelp would be insanely appreciated!

Thanks in advance!! :)

Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Here is what you would like to see:

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

Opt('MustDeclareVars', 0)
GeeWiz()
Func GeeWiz()
GUICreate("IP", 383, 463, 1481, 119)
$IP = GUICtrlCreateInput("", 120, 48, 137, 21)
$Label1 = GUICtrlCreateLabel("Client IP Address", 144, 31, 84, 17)
$Button1 = GUICtrlCreateButton("GET", 152, 80, 75, 25)
$Group2 = GUICtrlCreateGroup("Data", 48, 136, 297, 313)
$Label2 = GUICtrlCreateLabel("Location of Program Files:", 64, 168, 126, 17)
$Label3 = GUICtrlCreateLabel(".", 200, 168, 7, 17)
$Label4 = GUICtrlCreateLabel("By Mike Kovacic", 160, 424, 84, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()


While 1
    $msg = GUIGetMsg()
    select
        Case $msg = $Button1
        DoSumthin(GUICtrlRead($IP))
            ;RunWait("net use \\" & $IP & "\ipc$",@SW_SHOW)
            ;$Label3 = RegRead("\\" & $IP & "\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion","ProgramFilesDir")
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect
    WEnd
EndFunc 

Func DoSumthin($IP)
MsgBox(0, "Value","" & $IP & "", 5)
    
; See if it is pingable
  ;$status = Ping($IP)
    ;If $status Then
      
     ; Perform actions needed
     
   ; Else
    ;     MsgBox(0, "Sorry", "I was unable to PING the remote machine.", 10)
   ; EndIf
endfunc

Problem was: 1. if you want to read data of an input you have to use guictrlread

2. I do not advice to use globals, unless you have 3 or more functions with the same string that doesn't change to much.

Edited by Gideon

Many times you need to think like hobby-bob:')

Link to comment
Share on other sites

Here is what you would like to see:

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

Opt('MustDeclareVars', 0)
GeeWiz()
Func GeeWiz()
GUICreate("IP", 383, 463, 1481, 119)
$IP = GUICtrlCreateInput("", 120, 48, 137, 21)
$Label1 = GUICtrlCreateLabel("Client IP Address", 144, 31, 84, 17)
$Button1 = GUICtrlCreateButton("GET", 152, 80, 75, 25)
$Group2 = GUICtrlCreateGroup("Data", 48, 136, 297, 313)
$Label2 = GUICtrlCreateLabel("Location of Program Files:", 64, 168, 126, 17)
$Label3 = GUICtrlCreateLabel(".", 200, 168, 7, 17)
$Label4 = GUICtrlCreateLabel("By Mike Kovacic", 160, 424, 84, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()


While 1
    $msg = GUIGetMsg()
    select
        Case $msg = $Button1
        DoSumthin(GUICtrlRead($IP))
            ;RunWait("net use \\" & $IP & "\ipc$",@SW_SHOW)
            ;$Label3 = RegRead("\\" & $IP & "\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion","ProgramFilesDir")
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect
    WEnd
EndFunc 

Func DoSumthin($IP)
MsgBox(0, "Value","" & $IP & "", 5)
    
; See if it is pingable
  ;$status = Ping($IP)
    ;If $status Then
      
     ; Perform actions needed
     
   ; Else
    ;     MsgBox(0, "Sorry", "I was unable to PING the remote machine.", 10)
   ; EndIf
endfunc

Problem was: 1. if you want to read data of an input you have to use guictrlread

2. I do not advice to use globals, unless you have 3 or more functions with the same string that doesn't change to much.

Thank you SOOOOO MUCH!! This has been driving me up the wall with the whole "why wont it work" chant.

You Rox!

C0d3 is P0etry( ͡° ͜ʖ ͡°)

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...