Jump to content

Inputbox (increase and decrease with button)


Giggo
 Share

Recommended Posts

  • Developers

Build your own inputbox (GUI) and this should be pretty easy to do. ;) 

The helpfile and Wiki are your friend to get started.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

That is great that you are trying to learn to program and we will be happy to help you out were we can. ;) 

Just open the helpfile and look at the example of GUICtrlCreateUpdown() which will show you how you can easily do an up down action.
You will of course also need an GUICtrlCreateInput()  box to be filled with the new number whenever you click the UpDown buttons.

Just try together to get something going and post here when you have questions. :) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Just take the example from the helpfile an modify that....  as you can see it will show correctly this way:

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

Example()

Func Example()
    GUICreate("My GUI UpDown", -1, -1, -1, -1, $WS_SIZEBOX)

    Local $idInput = GUICtrlCreateInput("2", 10, 10, 50, 20)
    GUICtrlCreateUpdown($idInput)

    ; Attempt to resize input control
    GUICtrlSetPos($idInput, 10, 10, 100, 40)

    GUISetState(@SW_SHOW)

    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()

        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idInput
                $curVal = Number(GUICtrlRead($idInput))
                ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $curVal = ' & $curVal & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                If $curVal > 30 Then GUICtrlSetData($idInput, "30")
                If $curVal < 1 Then GUICtrlSetData($idInput, "1")
        EndSwitch
    WEnd

    MsgBox($MB_SYSTEMMODAL, "Updown", GUICtrlRead($idInput))
EndFunc   ;==>Example

EDIT: Added some MIN / MAX logic..   Let me know when you have questions and please post a runnable script when you want to show an issue.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You can use GUICtrlSetLimit to set the limits of the up/down control and use the same to limit the number of char of the input.

Example :

Local $idInput = GUICtrlCreateInput("1", 10, 5, 100, 20, $ES_NUMBER) ; only number accepted
  GUICtrlSetLimit(-1, 2) ; maximum of 2 characters
  Local $idUpDown = GUICtrlCreateUpdown(-1)
  GUICtrlSetLimit(-1, 30, 1) ; up/down from 1 to 30

 

Edited by Nine
Link to comment
Share on other sites

1 hour ago, Jos said:

Just take the example from the helpfile an modify that....  as you can see it will show correctly this way:

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

Example()

Func Example()
    GUICreate("My GUI UpDown", -1, -1, -1, -1, $WS_SIZEBOX)

    Local $idInput = GUICtrlCreateInput("2", 10, 10, 50, 20)
    GUICtrlCreateUpdown($idInput)

    ; Attempt to resize input control
    GUICtrlSetPos($idInput, 10, 10, 100, 40)

    GUISetState(@SW_SHOW)

    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()

        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idInput
                $curVal = Number(GUICtrlRead($idInput))
                ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $curVal = ' & $curVal & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                If $curVal > 30 Then GUICtrlSetData($idInput, "30")
                If $curVal < 1 Then GUICtrlSetData($idInput, "1")
        EndSwitch
    WEnd

    MsgBox($MB_SYSTEMMODAL, "Updown", GUICtrlRead($idInput))
EndFunc   ;==>Example

EDIT: Added some MIN / MAX logic..   Let me know when you have questions and please post a runnable script when you want to show an issue.

thanks jos, i had come to your example for a long time, maybe i speak badly, but i see that updown becomes child of the inputbox  and is "forced to become a limited control", i seem to understand that it does not fully access the inputbox control because it is forced by it, I can hardly believe that it remains such an unmanageable control, in a nutshell you can't use it externally to the inputbox and give the size you want as a button?

Edited by Giggo
Link to comment
Share on other sites

hi forum!

I tried to post an example of what I meant, now I have to limit the box to just 30 numbers

Code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $n = 1

$Form = GUICreate("Simple Button UpDown", 400, 67, -1, -1)
$iInput = GUICtrlCreateInput("1", 13, 21, 250, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY,$ES_NUMBER))
$bLeft = GUICtrlCreateButton(ChrW(706), 280, 8, 50, 50)
$bRight = GUICtrlCreateButton(ChrW(707), 330, 8, 50, 50)

GUISetState(@SW_SHOW)

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        exitloop    
        Case $bRight
            $n += 1
        GUICtrlSetData($iInput, $n)
            
        Case $bLeft
            If $n == 1 Then
                $n = 1
            GUICtrlSetData($iInput, $n)
            Else
            $n -= 1
            GUICtrlSetData($iInput, $n)
            EndIf
    EndSwitch  
WEnd

 

Link to comment
Share on other sites

A few comments.

1- Do not use == in if as this is reserved for case-sensitive strings comparaison

2- No need to specify number only if the input box is readonly

Here a way to simplify your loop :

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
    Case $bRight
      If $n = 30 Then ContinueLoop
      $n += 1
      GUICtrlSetData($iInput, $n)
    Case $bLeft
      If $n = 1 Then ContinueLoop
      $n -= 1
      GUICtrlSetData($iInput, $n)
  EndSwitch
WEnd

 

Link to comment
Share on other sites

9 minutes ago, Nine said:

A few comments.

1- Do not use == in if as this is reserved for case-sensitive strings comparaison

2- No need to specify number only if the input box is readonly

Here a way to simplify your loop :

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
    Case $bRight
      If $n = 30 Then ContinueLoop
      $n += 1
      GUICtrlSetData($iInput, $n)
    Case $bLeft
      If $n = 1 Then ContinueLoop
      $n -= 1
      GUICtrlSetData($iInput, $n)
  EndSwitch
WEnd

 

you ROCK bro... thanks!

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