New to Gambas.. seek some help

New to Gambas? Post your questions here. No question is too silly or too simple.
Mudassir
Posts: 13
Joined: Monday 5th February 2024 11:10pm

Re: New to Gambas.. seek some help

Post 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'.
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: New to Gambas.. seek some help

Post 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.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Mudassir
Posts: 13
Joined: Monday 5th February 2024 11:10pm

Re: New to Gambas.. seek some help

Post 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.
User avatar
BruceSteers
Posts: 1580
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: New to Gambas.. seek some help

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
grayghost4
Posts: 187
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: New to Gambas.. seek some help

Post 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 
      
Post Reply