- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a simple way of checking that the text entered in an Edit Box is a real number, i.e. '12.345' would be OK, but '12.34x' would be wrong.
I tried using the WRITE statement with ERR but sometimes it doesn't work - it converted 'ty' to '1.0'.
Thanks,
David
I tried using the WRITE statement with ERR but sometimes it doesn't work - it converted 'ty' to '1.0'.
Thanks,
David
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you meant READ, not WRITE.
Don't use * format for this - it's much too flexible. Use G format (eg. G10.0) in an explicit format instead. Don't forget to check for a blank field.
Steve
Don't use * format for this - it's much too flexible. Use G format (eg. G10.0) in an explicit format instead. Don't forget to check for a blank field.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I had been using '*', I had never used 'G' before.
David
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In addition, you could subclass the edit box to accept only numbers, decimal point, +, and - sign. That is not foolproof either (cannot prevent things like 1.234.5) but IMO looks more coherent to the user:
CASE (WM_KEYDOWN)
!Filter all but 1-9, +, -, and special keys:
SELECT CASE (wParam)
CASE (#30:#39, VK_NUMPAD0:VK_NUMPAD9, VK_DECIMAL, VK_END:VK_DOWN, VK_DELETE, VK_SUBTRACT, VK_ADD)
ResultProc=CallWindowProc(lpOldEditProc, hWnd, Msg, wParam, lParam)
CASE DEFAULT
ResultProc=0
END SELECT
Jugoslav
CASE (WM_KEYDOWN)
!Filter all but 1-9, +, -, and special keys:
SELECT CASE (wParam)
CASE (#30:#39, VK_NUMPAD0:VK_NUMPAD9, VK_DECIMAL, VK_END:VK_DOWN, VK_DELETE, VK_SUBTRACT, VK_ADD)
ResultProc=CallWindowProc(lpOldEditProc, hWnd, Msg, wParam, lParam)
CASE DEFAULT
ResultProc=0
END SELECT
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is something I programmed with the same idea in mind.
I knew that I would not be entering numbers such as 1.2345d-09
or -0.23456e+07 (i.e. no 'e,E, d or D in it).
BAsically I get the character string from the edit box and
then call a routine to ignore all but the first occurrence of - and '.'
with the '-' sign having to be the
first non-blank character to be accepted.
I knew that I would not be entering numbers such as 1.2345d-09
or -0.23456e+07 (i.e. no 'e,E, d or D in it).
BAsically I get the character string from the edit box and
then call a routine to ignore all but the first occurrence of - and '.'
with the '-' sign having to be the
first non-blank character to be accepted.
(INSIDE SOME CALLBACK ROUTINE...) ..... ..... REAL*8 REALBOX4 CHARACTER*256 EDIT4 INTEGER*4 EDIT4LENG ....... ...... CASE(IDC_EDITBOX4) !GET THE NUMBER (CHARACTER STRING) retlog=DLGGET(dlg, IDC_EDITBOX4,EDIT4,DLG_STATE) EDIT4LENG=LEN_TRIM(EDIT4) ! call routine to filter the character string CALL FILTERSTRING(EDIT4,EDIT4LENG) ! Write out the filtered entry to the edit box retlog=DLGSET(dlg, IDC_EDITBOX4,TRIM(ADJUSTL(EDIT4)),DLG_STATE) REALBOX4=0 IF(EDIT4LENG.GT.0) READ(EDIT4,*) REALBOX4 ! WRITE(*,*) 'NUMBER 4 =',REALBOX4 END SELECT ! ...... ..... SUBROUTINE FILTERSTRING(STRING,LEN) CHARACTER*(LEN) STRING CHARACTER*256 TEMP INTEGER LEN,ICOUNT, I ! ! COPY A NON-ZERO LENGTH STRING TO ITSELF, REMOVING ! NON-NUMERIC CHARACTERS EXCEPT '-' (IF FIRST CHARACTER) ! AND '.' IF IT IS THE FIRST OCCURRENCE OF '.' ! ! FILL TEMP WITH BLANKS ! IF(LEN.EQ.0)RETURN TEMP=' ' TEMP=ADJUSTR(ADJUSTL(TEMP)) ICOUNT=0 ! INITIALISE FLAG USED TO DETECT FIRST OCCURRENCE OF A DECIMAL POINT IDOT=0 DO I=1,LEN IF(ICHAR(STRING(I:I)).GT.47.AND.ICHAR(STRING(I:I)).LT.58)THEN ICOUNT=ICOUNT+1 IF(ICOUNT.LT.256+1)TEMP(ICOUNT:ICOUNT)=STRING(I:I) ENDIF IF(ICHAR(STRING(I:I)).EQ.45.AND.I.EQ.1)THEN ICOUNT=ICOUNT+1 IF(ICOUNT.LT.256+1)TEMP(ICOUNT:ICOUNT)=STRING(I:I) ENDIF IF(ICHAR(STRING(I:I)).EQ.46.AND.IDOT.EQ.0) THEN ICOUNT=ICOUNT+1 IF(ICOUNT.LT.256+1)TEMP(ICOUNT:ICOUNT)=STRING(I:I) ! SET FLAG TO SHOW DECIMAL POINT DETECTED - MAYBE MAKE ! USE OF IT SOME OTHER TIME... IDOT=1 ENDIF ENDDO STRING=ADJUSTL(ADJUSTR(TEMP)) LEN=LEN_TRIM(STRING) END SUBROUTINE FILTERSTRING
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page