Jump to content

Set color to label variable based of number


 Share

Recommended Posts

If $PingNum = 125 OR $PingNum < 125 Then
    GuiCtrlSetColor($PingNum, $COLOR_GREEN)
    
Else
    GUICtrlSetColor($PingNum, 0xff0000)
    EndIf

I have tried everything, using $COLOR_RED instead but nothing seems to work when I have $PingNum be over 125. It just doesn't want to come up as the color red when the variable is over 125.

Edited by autosm
Link to comment
Share on other sites

  • Moderators

Wait, what is $PingNum?  You're using it as a controlid.

Edit:

BTW, if you're unsure or can't explain correctly (because your code makes little sense), then you're going to need to provide a working recreation script that demonstrates your issue.  Not a conditional statement that really says nothing.  BTW

If $PingNum <= 125 Then
is the same as your "Or" statement. Edited by SmOke_N

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

I ping an ip adress and the ms gets set to $PingNum.

Local $iPing = Ping("IP ADRESS THAT IS SET HERE", 1850)
If $iPing Then ; If a value greater than 0 was returned then display the following message.
GUICtrlSetData ($PingNum, $iPing)
Else
MsgBox($MB_SYSTEMMODAL, "", "An error occurred. If this conitues the region severs might be down/busy.")
EndIF
 
I have a few of those set my code based of of what radio button is selected. Everything works fine but my major issue is that when controlID PingNum is over 126 it doesnt set the color to red.
Link to comment
Share on other sites

$Label = GUICtrlCreateLabel("", 10, 10, 200, 25)
; [...]
$ping = Ping($host, 2000)
If $ping >= 125 Then
    $color = 0x00ff00
Else
    $color = 0xff0000
EndIf
GUICtrlSetBkColor($label, $color)

Link to comment
Share on other sites

@autosm - have a close look at the first code you posted.

You have intermixed the ID or handle of your label, with your ping variable.

This is why, it is always best to post a larger portion of code, than just some snippet.

We can see instantly then, that you have made such a glaring mistake.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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