Jump to content

Help with an if then statement


Go to solution Solved by SmOke_N,

Recommended Posts

I'm trying to make this label change color when a ping is returned. I put in the button to test if the ping is working and i know that it is. So if anyone could help that would be awesome.

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Paul\Desktop\My Programs\IP hospital tool\koda form\ip hospital tool.kxf
Global $PingTime = Ping("www.google.com",250)
$Form1 = GUICreate("Form1", 212, 126, 347, 170)
$Button1 = GUICtrlCreateButton("Button1", 32, 8, 145, 33)
$Input1 = GUICtrlCreateInput("", 8, 48, 193, 21)
Global $Label1 = GUICtrlCreateLabel("", 0, 77, 212, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit
         case $Button1
            button1()
         case $input1
            input1()
         case $label1
            label1()
    EndSwitch
 WEnd

Func label1()
    if $pingtime then
       GUICtrlSetBkColor($label1, $color_green)
    Else
       GUICtrlSetBkColor($label1, $color_red)
    EndIf
 EndFunc

func button1()
    msgbox(0, "test", $pingtime)
EndFunc

[color=rgb(0,0,0);font-family:Lato, Arial, Helvetica, sans-serif;font-size:16px;]Baseball is the only field of endeavor where a man can succeed three times out of ten and be considered a good performer.[/color]

Link to comment
Share on other sites

  • Moderators
  • Solution

Ping only works when you call it.

You only call it once.

Your condition statement is merely looking to see if ping succeeded the first time, so the color will never change.

The label function, is only ever activated if you click on the label.

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Paul\Desktop\My Programs\IP hospital tool\koda form\ip hospital tool.kxf
; register a checking function
AdlibRegister("label1", 10000); every 10 seconds check

Global $PingTime = Ping("www.google.com",250)
$Form1 = GUICreate("Form1", 212, 126, 347, 170)
$Button1 = GUICtrlCreateButton("Button1", 32, 8, 145, 33)
$Input1 = GUICtrlCreateInput("", 8, 48, 193, 21)
Global $Label1 = GUICtrlCreateLabel("", 0, 77, 212, 49)
GUISetState(@SW_SHOW)
; initiate first call to ping
label1()
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit
         case $Button1
            button1()
         case $input1
;~             input1()
;~          case $label1
;~             label1()
    EndSwitch
 WEnd

Func label1()
    $pingtime = Ping("www.google.com",250)
    if $pingtime then
       GUICtrlSetBkColor($label1, $color_green)
    Else
       GUICtrlSetBkColor($label1, $color_red)
    EndIf
 EndFunc

func button1()
    msgbox(0, "test", $pingtime)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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