Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

reading an edit box

diana_g_1
Beginner
959 Views

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???

0 Kudos
5 Replies
Anthony_Richards
New Contributor I
959 Views

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!

0 Kudos
diana_g_1
Beginner
959 Views

I only need to write floating point and + and- signs. 

0 Kudos
Anthony_Richards
New Contributor I
959 Views

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

0 Kudos
diana_g_1
Beginner
959 Views

thank you very much!!!!!!!!!! it's perfect!!!!!

0 Kudos
SergeyKostrov
Valued Contributor II
959 Views
Hi Diana, This is a short follow up. Even if Windows EDIT control has a dedicated style ES_NUMBER it doesn't solve the problem. Here is what MSDN says about that style: ... ES_NUMBER Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control. ... It is very strange and I really surprised that Microsoft did not change it for a long time. It is good that Anthony's solution works for you.
0 Kudos
Reply