Jump to content

radio not working


Recommended Posts

This is a script from another user that I simplified since I only need to ping two destinations. I do not understand how radio buttons work does anyone have a nice easy example or can you tell me why this does not work thanks a bunch

#include <GuiConstants.au3>

GuiCreate("Ping Tool", 300, 300)

GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; selection

GUISetFont (16, 400, 0, "Arial")

$radio = GuiCtrlCreateGroup("Domain Controller:", 30, 20, 180, 100)

$radio1 = GuiCtrlCreateRadio("CSCDC1", 50, 40, 120)

GuiCtrlSetState(-1, $GUI_CHECKED)

$radio2 = GuiCtrlCreateRadio("CSCDC2", 50, 80, 120)

GUICtrlCreateGroup ("",-99,-99,1,1);close group

; create ping button

$ping= GUICtrlcreateButton("Ping!", 130, 250, 60, 35)

; GUI MESSAGE LOOP

GuiSetState()

While 1

$msg = GUIGetMsg()

Select

Case GUICtrlRead($radio1) = $GUI_CHECKED

$ip = "novell.com"

Case GUICtrlRead($radio2) = $GUI_CHECKED

$ip = "yahoo.com"

Case $msg = $ping

RunWait(@ComSpec & " /C Ping -a -n 1 " & $ip & " > Find_IP.txt",@MyDocumentsDir, @SW_HIDE)

$ip = FileRead(@MyDocumentsDir & "\Find_IP.txt", FileGetSize(@MyDocumentsDir & "\Find_IP.txt"))

FileDelete(@MyDocumentsDir & "\Find_IP.txt")

MsgBox(0,"Returned Ping String [data]", "" & $ip)

; MsgBox(0,"" & $strcomputer & " IP:", "" & $ip)

EndSelect

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

Link to comment
Share on other sites

remove the Cases where you are checking the radio, and just put in the Case $msg = $ping area

If $GUICtrlRead($radio1) = $GUI_CHECKED Then

$ip = "novell.com"

Else

$ip = "yahoo.com"

EndIf

make sure to put that before the RunWait

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

It might be because the program is never reaching the $ping case. It checks the radio button and skips the rest

#include <GuiConstants.au3>

GUICreate("Ping Tool", 300, 300)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; selection
GUISetFont(16, 400, 0, "Arial")
$radio = GUICtrlCreateGroup("Domain Controller:", 30, 20, 180, 100)
$radio1 = GUICtrlCreateRadio("CSCDC1", 50, 40, 120)
GUICtrlSetState(-1, $GUI_CHECKED)
$radio2 = GUICtrlCreateRadio("CSCDC2", 50, 80, 120)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group


; create ping button
$ping = GUICtrlCreateButton("Ping!", 130, 250, 60, 35)

; GUI MESSAGE LOOP

GUISetState()

While 1
    $msg = GUIGetMsg()
    
    If GUICtrlRead($radio1) = $GUI_CHECKED Then
        $ip = "novell.com"
    Else
        $ip = "yahoo.com"
    EndIf
    
    Select
        Case $msg = $ping
            ConsoleWrite("ping")
            ConsoleWrite(@ComSpec & " /C Ping -a -n -1 " & $ip & " > Find_IP.txt")
            RunWait(@ComSpec & " /C Ping -a -n -1 " & $ip & " > Find_IP.txt", @MyDocumentsDir, @SW_HIDE)
            $ip = FileRead(@MyDocumentsDir & "\Find_IP.txt", FileGetSize(@MyDocumentsDir & "\Find_IP.txt"))
            FileDelete(@MyDocumentsDir & "\Find_IP.txt")
            MsgBox(0, "Returned Ping String [data]", "" & $ip)
        ; MsgBox(0,"" & $strcomputer & " IP:", "" & $ip)
            
    EndSelect
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

Just add more else

If <exp[b][/b]ression> Then
    statements
    ...
[ElseIf exp[b][/b]ression-n Then
    [elseif statements ... ]]
    ...
[Else
    [else statements]
    ...
EndIf
or use select case/endselect
Select
    Case <exp[b][/b]ression>
        statement1
        ...
    [Case 
        statement2
        ...]
    [Case Else
        statementN
        ...]
EndSelect

Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

While $msg <> $GUI_EVENT_CLOSE
If $msg = $ping Then
 If GUICtrlRead($radio1) Then $ip = "site1.com"
 If GUICtrlRead($radio2) Then $ip = "site2.com"
 If GUICtrlRead($radio3) Then $ip = "site3.com"
 If GUICtrlRead($radio4) Then $ip = "site4.com"
 RunWait(@ComSpec & " /c ping -a -n -1" & $ip & " > Find_IP.txt",  @MyDocumentsDir, @SW_HIDE)
;...more stuff

WEnd

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

perfect thank you

While $msg <> $GUI_EVENT_CLOSE
If $msg = $ping Then
 If GUICtrlRead($radio1) Then $ip = "site1.com"
 If GUICtrlRead($radio2) Then $ip = "site2.com"
 If GUICtrlRead($radio3) Then $ip = "site3.com"
 If GUICtrlRead($radio4) Then $ip = "site4.com"
 RunWait(@ComSpec & " /c ping -a -n -1" & $ip & " > Find_IP.txt",  @MyDocumentsDir, @SW_HIDE)
;...more stuff

WEnd

<{POST_SNAPBACK}>

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