Jump to content

read WHOLE string ie number


buzz44
 Share

Recommended Posts

im making a simple script that will convert the RGB to Hex and visversa in a GUI format ... and a little coloured label will chnage so that u know wat colour it is ..

because RGB is a value 1-255 i dont want the values to be less than "0" or greater than "255" which i have done... the problem is the blue code below ... it recognises not the whole string . but the first 2 digits or sumthing .. eg... if i type the number 174 in it works fine ... but say if i type the number in 26 it immediatly jumps the number to 255 .. alos if i put "026" instead of "26" it works .. but as soon as i click the "updown" thing is jumps to 255 again .. is there andway i can correct this so that is reads 255 as a whole not as 25..

thx

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 

0x04000000

GuiCreate("MyGUI", 162, 81,(@DesktopWidth-162)/2, (@DesktopHeight-81)/2 , 

$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Input_Red = GuiCtrlCreateInput("255", 10, 24, 40, 20, $ES_NUMBER)
$Input_Green = GuiCtrlCreateInput("255", 60, 24, 40, 20, $ES_NUMBER)
$Input_Blue = GuiCtrlCreateInput("255", 110, 24, 40, 20, $ES_NUMBER)
$Input_Hex = GuiCtrlCreateInput("Input4", 10, 50, 80, 20)
$Label_Blue = GuiCtrlCreateLabel("Blue", 110, 10, 30, 13)
$Label_Red = GuiCtrlCreateLabel("Red", 10, 10, 40, 11)
$Label_Green = GuiCtrlCreateLabel("Green", 60, 10, 40, 14)
$Label_Colour = GuiCtrlCreateLabel("", 100, 50, 50, 20)
$updown_Red = GUICtrlCreateUpdown($Input_Red)
$updown_Blue = GUICtrlCreateUpdown($Input_Blue)
$updown_Green = GUICtrlCreateUpdown($Input_Green)

GUICtrlSetPos($Input_Red, 10,20, 50, 20 )
GUICtrlSetPos($Input_Blue, 60,20, 50, 20 )
GUICtrlSetPos($Input_Green, 120,20, 50, 20 )

GuiSetState()
While 1
   _GetHex()
;;;;;HERE IS MY PROBLEM___________________________
   If GUICtrlRead ($Input_Red) > "255" Then
      GUICtrlSetData ($Input_Red, "255")
   ElseIf GUICtrlRead ($Input_Green) > "255" Then
      GUICtrlSetData ($Input_Green, "255")
   ElseIf GUICtrlRead ($Input_Blue) > "255" Then
      GUICtrlSetData ($Input_Blue, "255")
   ElseIf GUICtrlRead ($Input_Red) < "0" Then 
      GUICtrlSetData ($Input_Red, "0")
   ElseIf GUICtrlRead ($Input_Green) < "0" Then 
      GUICtrlSetData ($Input_Green, "0")
   ElseIf GUICtrlRead ($Input_Blue) < "0" Then 
      GUICtrlSetData ($Input_Blue, "0")
;;;;;HERE IS MY PROBLEM___________________________
   EndIf
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
 ;;;
    EndSelect
WEnd
Exit

Func _GetHex()
   $Hex_Red = Hex(GUICtrlRead ($Input_Red), 2)
   $Hex_Green = Hex(GUICtrlRead ($Input_Green), 2)
   $Hex_Blue = Hex(GUICtrlRead ($Input_Blue), 2)
   GUICtrlSetData ($Input_Hex, "0x" & $Hex_Red & $Hex_Green & $Hex_Blue)
   GUICtrlSetBkColor($Label_Colour, GUICtrlRead ($Input_Hex))
EndFunc

edit: didnt realise i could have colour inside code tags =(

Edited by burrup

qq

Link to comment
Share on other sites

You should compare numerical values, not strings.

If Number(GUICtrlRead ($Input_Red)) > 255 Then
      GUICtrlSetData ($Input_Red, "255")

e.t.c.

But even better to get rid all code between ";;;;;HERE IS MY PROBLEM___________________________ " :lmao: and just use limits for Updown control:

$updown_Red = GUICtrlCreateUpdown($Input_Red)
GUICtrlSetLimit(-1, 255, 0)
$updown_Blue = GUICtrlCreateUpdown($Input_Blue)
GUICtrlSetLimit(-1, 255, 0)
$updown_Green = GUICtrlCreateUpdown($Input_Green)
GUICtrlSetLimit(-1, 255, 0)

Edit: second example valid, but you still can enter any value by hand... so this not for your case.

Edited by Lazycat
Link to comment
Share on other sites

cool Thx :lmao: ... you 2nd eg ... thats why i didnt use that method lol .. but i still could and use GUICtrlRead($Input_red) to check if it is over 255 .. thx

edit: u can type in a number over 255 but asoon as u click up or down it sets it back to 255 so its ok.

Edited by burrup

qq

Link to comment
Share on other sites

cool Thx :lmao: ... you 2nd eg ... thats why i didnt use that method lol .. but i still could and use GUICtrlRead($Input_red) to check if it is over 255 .. thx

edit: u can type in a number over 255 but asoon as u click up or down it sets it back to 255 so its ok.

<{POST_SNAPBACK}>

You could also stringformat(var1=%3d,$input_red) to force everything into a 3 digit number that is zero padded.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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