Jump to content

Slider returning strange values!


Recommended Posts

Hello!

Please help me with this small problem I've encountered while learning to make GUI.

I'm not able to get the set slider values out of sliders and I can't figure out why.
The slider value in the example is preset to 1, but whatever I set the slider to, it returns the value 3 when I click Apply and I havn't set any value to 3.

Where is that 3 coming from?
 

#include <SliderConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>

Global $LRSlider

Opt("GUIOnEventMode", 1)

Global $Form1 = GUICreate("test slider", 200, 200, -1, -1)
Global $LRSlider = GUICtrlCreateSlider(50, 50, 100, 20, $TBS_TOOLTIPS)
GUICtrlSetLimit($LRSlider, 50, 1)
GUICtrlSetData($LRSlider, 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Exit1")

Global $ApplyButton = GUICtrlCreateButton("APPLY", 100, 150, 89, 17)
GUICtrlSetOnEvent($ApplyButton, "Apply")

GUISetState(@SW_SHOW)

Func Apply()
    GUICtrlRead($LRSlider)
    MsgBox(0, 0, $LRSlider)
    GUICtrlSetData($LRSlider, $LRSlider)
EndFunc   ;==>Apply

Func Exit1()
    Exit
EndFunc   ;==>Exit1

While 1
    Sleep(200)
WEnd

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By AndyS01
      I want to create a slider that has values representing colors, like the slider on the _ChooseColor() GUI in the Misc.au3 UDF, but the max value for a slider is 32767.  
      Here is my test code:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SliderConstants.au3> #include <Misc.au3> $hGUI = GUICreate("Test", 100, 560) $BtnID = GUICtrlCreateButton("Choose", 10, 10, 50, 25) ;~ GUICtrlSetOnEvent($BtnID, "handle_choose_btn") $flags = BitOR($TBS_AUTOTICKS, $TBS_VERT) $iSliderID = GUICtrlCreateSlider(10, 50, 40, 420, $flags) $hSlider_hWnd = GUICtrlGetHandle($iSliderID) $iMaxVal = 32767 GUICtrlSetLimit($iSliderID, $iMaxVal, 0) ; change min/max value GUISetState() GUIRegisterMsg($WM_VSCROLL, "WM_V_Slider") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP ToolTip("") case $BtnID handle_choose_btn() EndSwitch WEnd ; React to a slider movement Func WM_V_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam If $lParam = $hSlider_hWnd Then $iValue = GUICtrlRead($iSliderID) ConsoleWrite("+++: $iValue = " & $iValue & @CRLF) ToolTip(getRGB($iValue)) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_V_Slider ; Extract the RGB components from the color value Func getRGB($iColorVal) Local $hexstr, $b, $g, $r, $rgb $hexstr = StringFormat("%06X", $iColorVal) $r = StringMid($hexstr, 1, 2) $g = StringMid($hexstr, 3, 2) $b = StringMid($hexstr, 5, 2) $rgb = StringFormat("" & $iColorVal & " - rgb: %02s %02s %02s", $r, $g, $b) Return ($rgb) EndFunc ;==>getRGB Func handle_choose_btn() $color = _ChooseColor(2, 255, 0, $hGUI) ConsoleWrite("+++: $color = " & Hex($color, 8) & @CRLF) EndFunc ;==>handle_choose_btn  
    • By nacerbaaziz
      Hi guys
      I have a question about the slider  controle
      There is a problem with screen readers, wen we Using a screen reader We usually move between GUI controls using the tab key.
      But when you create a slider , beside to it there are  buttons and check boxes or any other controls, When I move between the GUI controls using the tab key I can not find the slider.
      But if it were alone in the window, I would find it normally.
      Is there a solution to Solve this problem please?
      This is the code i tried
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <SliderConstants.au3>
      main()
      Func main()
          GUICreate("slider", 200, 200, -1, -1)
      GUICtrlCreateGroup("slider", 10, 10, 240, 50)
          Local $idSlider1 = GUICtrlCreateSlider(50, 30, 200, 20, BitOr($TBS_DOWNISLEFT, $TBS_BOTH))
          GUICtrlSetLimit(-1, 100, 0)
      ;GUIStartGroup("")
          Local $idButton = GUICtrlCreatebutton("Value?", 75, 70, 70, 20)
          GUISetState(@SW_SHOW)
          GUICtrlSetData($idSlider1, 10)
      while 1
      switch GUIGetMsg()
      case $GUI_EVENT_CLOSE
      exit
      case $idButton
                  MsgBox($MB_SYSTEMMODAL, "slider1", GUICtrlRead($idSlider1))
      endSwitch
      Wend
      EndFunc
      [Click and drag to move]
       
       
    • By b9k
      Hi, I am stuck on a GUI problem and would like your help to solve it.
      I am trying to automate the SoundWire Server app to match my current system volume level while it is minimized to the notification area (so no clicking or stealing focus),
      I can already get the handle and alter the tracker position by sending a WM_SETPOS message, but somehow the actual volume is not changed: I think I need to do something else to trigger the event handler for the value change and propagate it correctly.
      This is the control summary from Au3 info:
      >>>> Window <<<< Title: SoundWire Server Class: #32770 Position: 441, 218 Size: 566, 429 Style: 0x94CA00C4 ExStyle: 0x00050101 Handle: 0x0000000000510E12 >>>> Control <<<< Class: msctls_trackbar32 Instance: 4 ClassnameNN: msctls_trackbar324 Name: Advanced (Class): [CLASS:msctls_trackbar32; INSTANCE:4] ID: 6002 Text: Position: 51, 222 Size: 47, 126 ControlClick Coords: 1, 101 Style: 0x5001000A ExStyle: 0x00000000 Handle: 0x00000000001234C8 >>>> Mouse <<<< Position: 496, 567 Cursor ID: 2 Color: 0xF0F0F0 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Default multimedia device Tray on Start Static Server Address: 192.168.1.8 Status: Connected to B9K~OP3 Audio Output Audio Input Level Record to File Input Select: 44.1 kHz Minimize to Master Volume Mute >>>> Hidden Text <<<< Slider2 Mute OK Cancel Label Balance Slider1 Volume Front L/R Fr C/LFE Side L/R Back L/R
      I am attaching the program in question so you don't have to install it (i don't know if it is portable enough, tough): 

      SoundWire Server_files.zip

      Thanks in advance and I hope I didn't post in the wrong section
    • By fopetesl
      One statement of GUICtrlRead() fails. Result is always "Long/Short" in written file.
      The other GUICtrlRead() calls work as expected
      Func GetScanSettings() ; Read User Input for scan Local $collectusername, $collectlot, $collectsample $UserFile = "Sample.dat" ; Global $UserFile = save this scan's parameters $datafile = FileOpen($UserFile) If( $datafile <> -1) Then $collectusername = FileReadLine($datafile, 1) EndIf FileClose($datafile) ; now open a new 'clean' file.. $datafile = FileOpen($UserFile,$FO_OVERWRITE ) ;Create GUI $Main = GUICreate('Enter Sample Detail', 500, 500) Opt("GUICoordMode",1) If( $collectusername <> "") Then $username = GUICtrlCreateInput($collectusername,100,20,100,20) Else $username = GUICtrlCreateInput('',100,20,100,20) EndIf $usernamelabel = GUICtrlCreateLabel('Username',30,22) $FileName = GUICtrlCreateInput("",100,45,100,0) $FileNamelabel = GUICtrlCreateLabel('File Name',30,47) $BatchNum = GUICtrlCreateInput("",100,65,100,0) $BatchNumlabel = GUICtrlCreateLabel('Lot',30,72) $SampleNum = GUICtrlCreateInput("",100,85,100,0) $SampleNumlabel = GUICtrlCreateLabel('Sample',30,97) $SampleLS = GUICtrlCreateInput("",100,105,100,0) $SampleNumLS = GUICtrlCreateLabel('Long/Short',30,117) $Button_1 = GUICtrlCreateButton ("OK", 190, 170, 0, 0, 0x0001) GUISetState (); Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() ; complete data entries Select Case $msg = $Button_1 $collectusername = GUICtrlRead($username) WinSetState('Collect Username','',@SW_HIDE) $collectfilename = GUICtrlRead($FileName) $collectlot = GUICtrlRead($BatchNum) $collectsample = GUICtrlRead($SampleNum) $collectLS = GUICtrlRead($SampleNumLS) ; Do ; $collectLS = GUICtrlRead($SampleNumLS) ; If $collectLS <> 'Long' And $collectLS <> 'Short' Then ; Soundplay("Windows XP Error.wav", 1) ; $collectLS = "" ; EndIf ; Until $collectLS = 'Long' Or $collectLS = 'Short' ExitLoop EndSelect Wend GUIDelete($Main) FileWrite($datafile,$collectusername & @CRLF & $collectfilename & @CRLF & $collectlot _ & @CRLF & $collectsample & @CRLF & 'Long' & @CRLF ) ; $collectLS & @CRLF) FileClose($datafile) EndFunc ;<=== GetScanSettings ================== I also tried to force user to enter either 'Short' or 'Long' but I got that wrong also
      The final FileWrite() edited so I do have a correct result.
      sample.dat
      Pete FilenamePete Num1 Samp2 Long/Short  
    • By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
×
×
  • Create New...