Testing numeric TextBox if it is empty....

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Testing numeric TextBox if it is empty....

Post by mol »

Hello everybody!

I need to test TextBox defined as numeric if it is empty - "on the screen", but not equal to zero.
I need to differ two situations
1) equal to zero - someone inputed 0
2) empty - nothing was already inputed

Have you any suggestions?

Marek
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Testing numeric TextBox if it is empty....

Post by Rathinagiri »

One way is this. You don't put any value while defining the control. You have a variable to record whether there is any change in the value of the control. If there is no change, we can be sure that the value is Nil, if it is changed, the value may be 0. Consider my example.

Code: Select all

# include "minigui.ch"

function main
private lValueChanged := .f.

define window sample at 0,0 width 200 height 200 main
define textbox t1
   row 10
   col 10
   width 100
   numeric .t.
   rightalign .t.
   on change lValuechanged := .t.
end textbox
define textbox t2
   row 40
   col 10
   width 100
   numeric .t.
   rightalign .t.
end textbox
define button b1
   row 70
   col 10
   caption "Click Me"
   action msginfo(iif(lValueChanged, str(sample.t1.value),"Entered Nil"))
end button 
end window
sample.center
sample.activate
return nil
But this will not work out if the user enters something and deletes the whole thing again. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Testing numeric TextBox if it is empty....

Post by mol »

I rather thought about samothing like in VBA for Excel
In Excel, If I define numeric box e.g. T_Price
T_Price.Value returns it's real value
T_Price.Text returns "buffer", that contains really entered characters

Maybe something undocumented????

Regards, Marek
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Testing numeric TextBox if it is empty....

Post by Roberto Lopez »

mol wrote:I rather thought about samothing like in VBA for Excel
In Excel, If I define numeric box e.g. T_Price
T_Price.Value returns it's real value
T_Price.Text returns "buffer", that contains really entered characters

Maybe something undocumented????

Regards, Marek
You could access to textbox content directly via a low level function:

Code: Select all

cRetValue := GetWindowText ( GetControlHandle (cControl,cWindow))
Be carefull, since you will be 'bypassing' most of MiniGUI layer, so, it is a non recommended action and coul bring some conflicts.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply