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

How to extract real figures from a dialog control?

reidar_tyssen
Beginner
883 Views

I want my programto read a user-specified real number for example 3.1415 from a character*6 TVAR

I use the control GetDlgItemText to read the textstring from the control, and everything is fine.

The variables in question are decalered as Character*6 TVAR, and real*4 RDIG

I then use the internal read:

read(string,'(F6.4)',err=xx))RDIG ( the textstring TVAR looks like "3.1415")

This read statement always fails, and I think it is the decimalpoint in the user-written textstring TVAR that

causes the error. Can anyone tell me the reason for this, and,is there a better way to do this

Regards

Reidar

0 Kudos
1 Solution
Jugoslav_Dujic
Valued Contributor II
883 Views
Quoting - gvautier

I think that the read fail can be caused by the trailing char(0).

Indeed it is -- you have to be careful to convert between C-style and Fortran-style strings when doing Windows programming:

[cpp]!C to Fortran
string = string(1 : index(string,char(0))-1)
!Fortran to C
string = trim(string)//char(0)[/cpp]

View solution in original post

0 Kudos
4 Replies
onkelhotte
New Contributor II
883 Views

We use
read(string,*) x
to convert the number in string into the real number x. I dont know if this is good fortran programming style, but it works ;-)

Markus

0 Kudos
GVautier
New Contributor III
883 Views

I think that the read fail can be caused by the trailing char(0).

Something like that can be safer

[cpp]l=getdlgitemtext(...,loc(string))
read(string(1:l),*,iostat=ioerr) x[/cpp]

0 Kudos
Jugoslav_Dujic
Valued Contributor II
884 Views
Quoting - gvautier

I think that the read fail can be caused by the trailing char(0).

Indeed it is -- you have to be careful to convert between C-style and Fortran-style strings when doing Windows programming:

[cpp]!C to Fortran
string = string(1 : index(string,char(0))-1)
!Fortran to C
string = trim(string)//char(0)[/cpp]

0 Kudos
GVautier
New Contributor III
883 Views

I have a function to do that job

[cpp]function cstring(string)
character*(*) string
character*(len_trim(string)+1) cstring

cstring=trim(string)//char(0)

end function
[/cpp]

0 Kudos
Reply