muXed
New Member
Posts: 15
|
Post by muXed on Jun 18, 2022 14:49:50 GMT -5
Evening all.
I've come across an issue and don't really no the best method to solve.
ES_NUMBER not allowing for periods.
The only method i can think of is replacing each unwanted character on a scan loop, but this doesn't seem a very efficient method especially when dealing with many textboxes at a time.
Any suggestions?
Thanks in advance
|
|
|
Post by Brandon Parker on Jun 18, 2022 20:02:06 GMT -5
Is this for use with monetary values? If it is, then I would have the value entered as a string, run it through some checking when it is time to do something with it, and convert the amount to the number of 1P (penny) there.
For instance, if you are in the US and someone enters $15.75 then your variable would hold 1575. This way your math is always dealing with integers. Due to the way floating-point math works, it is best to handle monetary amounts with integers.
{:0)
Brandon Parker
|
|
|
Post by Rod on Jun 19, 2022 6:48:54 GMT -5
What Brandon said plus two text boxes? Dollars and cents still held as 1575 but displayed as 15.75
|
|
|
Post by Walt Decker on Jun 19, 2022 9:07:31 GMT -5
ES_NUMBER does not allow negative numbers either, e. g. -125. Since LB does not allow us to capture the EN_CHANGE message the only alternative is a loop where you look at the input value as the user is inserting the character. I use a valid string consisting of "+-.0123456789" and compare that to the entered value. If the entered value contains any character other than one of the valid string characters I drop that character from the input string.
|
|
|
Post by Walt Decker on Jun 19, 2022 10:22:55 GMT -5
DEMO:
' EM.SETSEL = HEXDEC("&H00B1")
TEXTBOX #DMO.EDT1, 5, 5, 100, 25 TEXTBOX #DMO.EDT2, 5, 35, 100, 25
OPEN "NUMBERS" FOR WINDOW AS #DMO
EdtHndl1 = HWND(#DMO.EDT1) EdtHndl2 = HWND(#DMO.EDT2) [BEGIN.TIME]
TIMER 150, [CHECK.EDT] WAIT
'----------------------------------------------- '-----------------------------------------------
[CHECK.EDT]
TIMER 0 FocusHndl = 0 Wparam = 0 Lparam = 0 RetVal = 0
TxtTag$ = "" StrIn$ = ""
CALLDLL #user32, "GetFocus", FocusHndl AS ULONG
SELECT CASE FocusHndl CASE EdtHndl1 TxtTag$ = "#DMO.EDT1" StrIn$ = FN.GetTxtInput$(TxtTag$) PRINT #TxtTag$, StrIn$ Wparam = LEN(StrIn$) Lparam = Wparam + 1 CALLDLL #user32, "SendMessageA", EdtHndl1 AS ULONG, EM.SETSEL AS ULONG, _ Wparam AS LONG, Lparam AS LONG, RetVal AS VOID CASE EdtHndl2 TxtTag$ = "#DMO.EDT2" StrIn$ = FN.GetTxtInput$(TxtTag$) PRINT #TxtTag$, StrIn$ Wparam = LEN(StrIn$) Lparam = Wparam + 1 CALLDLL #user32, "SendMessageA", EdtHndl2 AS ULONG, EM.SETSEL AS ULONG, _ Wparam AS LONG, Lparam AS LONG, RetVal AS VOID
END SELECT
GOTO [BEGIN.TIME] [CHECK.EDT.END]
'------------------------------------------------------- '-------------------------------------------------------
FUNCTION FN.GetTxtInput$(TxtTag$)
Valid$ = "+-.1234567890" TxtOut$ = "" TxtIn$ = "" Char$ = ""
I = 0 J = 0
PRINT #TxtTag$, "!contents? TxtIn$"
IF TxtIn$ = "" THEN FN.GetTxtInput$ = TxtOut$ EXIT FUNCTION END IF
FOR I = 1 TO LEN(TxtIn$) Char$ = MID$(TxtIn$, I, 1) J = INSTR(Valid$, Char$) IF J = 0 THEN TxtOut$ = LEFT$(TxtIn$, I - 1) FN.GetTxtInput$ = TxtOut$ EXIT FUNCTION END IF
TxtOut$ = TxtOut$ + Char$ NEXT I
FN.GetTxtInput$ = TxtOut$ END FUNCTION '[code]
|
|