Page 2 of 2

Re: New to Gambas.. seek some help

Posted: Sunday 11th February 2024 2:39pm
by Mudassir
BruceSteers wrote: Sunday 11th February 2024 12:58pm I only know good tricks ;)
:o
Would love to see those good tricks please.
That was just a quick solution I could think of with anything I could remember about 'basic'.

Re: New to Gambas.. seek some help

Posted: Sunday 11th February 2024 2:51pm
by vuott
Mudassir wrote: Saturday 10th February 2024 7:56pm that's just a trick. It's about numeric input not formatted text.
No... I didn't understand.

Re: New to Gambas.. seek some help

Posted: Sunday 11th February 2024 3:00pm
by Mudassir
vuott wrote: Sunday 11th February 2024 2:51pm
Mudassir wrote: Saturday 10th February 2024 7:56pm that's just a trick. It's about numeric input not formatted text.
No... I didn't understand.
Sorry, let me explain... Suppose, I want to use Value Box to get user input for:
1. Rate of unit, there user should only enter value with 2 decimal places, not 3 or 4. like.. 2.25, not 2.258
2. Quantity (Decimal places depends on unit, like for units sold in pieces there would be no decimal places, for unit sold in meters there should be 2 decimal places and for units sold in kgs will have 3 decimal places. And we must not let user enter decimal value for pieces... there should not be 3 decimal places for units sold in meters. and likewise not 4 decimal places for units sold in kgs.

How to control user input when he/she is typing.. not on lost focus.

Re: New to Gambas.. seek some help

Posted: Sunday 11th February 2024 3:58pm
by BruceSteers
There is a ValueBox_Change() event
There is a ValueBox_KeyPress() event

Processing can be done there.

Change happens after a user types something and if needs be you can modify the Value and change it.
KeyPress happens before the key is accepted by the control and if you Stop Event it will not enter the press.

Stop Event will stop an event working normally and override it's behaviour.

For example..


Public Sub ValuBox_KeyPress()

  If Str(Last.Value).Len = iMaxLen then
    Stop Event  ' Stop the keypress event adding the char if the length is max
    Return
  Endif

End



I'm not exactly sure what you're doing but you can intercept and stop many internal control events
Right click a control in the IDE and see the available events listed in the events menu.

It's not too hard to make your own valuebox with a textbox and use the KeyPress event to completely control it's display manually.
That's essentially all a ValueBox is.

Re: New to Gambas.. seek some help

Posted: Sunday 7th April 2024 3:38am
by grayghost4
This checks two different text boxs and only allows a number or editing key strokes, the two boxes are grouped together so one sub checks both boxes.

Public Sub accountinfoBoxes_keypress()
   
   If Key.Code
      If Last.Name = "TBankroute" Or Last.Name = "TBaccNum" And Not (IsDigit(Key.Text) Or 
         Key.Code = Key.BackSpace Or Key.Code = Key.Tab Or Key.Code = Key.BackTab Or 
        Key.Code = Key.Left Or Key.Code = Key.Right) Then Stop Event