- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, when I read an edit box into a dialog box how can I force the reading only for real number?
if I write into the edit box "87m", how can I read it and tell the user that there is a character in the string and not a number???
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to get in the character string from the edit box a parse the string yourself. If you want to ignore non-numeric characters but keep decimal point and + and - signs, you have to search through the string for characters with ASCII codes that do not corespond to the digits 0-9, the decimal point and both of the signs. I have a routine to do this, but I am away from my office at present, so cannot help. Others here could probably help. If it is just a case of ignoring every thing except the digits 0 to 9, you can select 'number only' as a property of the edit box in the resource editor and anything entered other than those digits will be ignored automatically with no intervention from your program required. As you realise, wanting floating-point numbers with the correct syntax is rather more work, since you have to foresee cases where the -ve sign is not at the start and you may have more than one decimal point by mistake, and so on. Even more work is involved if you want to permit exponents!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I only need to write floating point and + and- signs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are in luck, I found the attached on my home workstation!
SUBROUTINE NORMAL(STRING,LEN)
CHARACTER*(LEN) STRING
CHARACTER*256 TEMP
INTEGER*4 LEN,ICOUNT
!
! 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
TEMP(ICOUNT:ICOUNT)=STRING(I:I)
ENDIF
IF(ICHAR(STRING(I:I)).EQ.45.AND.I.EQ.1)THEN
ICOUNT=ICOUNT+1
TEMP(ICOUNT:ICOUNT)=STRING(I:I)
ENDIF
IF(ICHAR(STRING(I:I)).EQ.46.AND.IDOT.EQ.0) THEN
ICOUNT=ICOUNT+1
TEMP(ICOUNT:ICOUNT)=STRING(I:I)
! SET FLAG TO SHOW DECIMAL POINT DETECTED
IDOT=1
ENDIF
ENDDO
STRING=ADJUSTL(ADJUSTR(TEMP))
LEN=LEN_TRIM(STRING)
END SUBROUTINE NORMAL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you very much!!!!!!!!!! it's perfect!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page