- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please,
Someone could explain me how to convert a character variable get from an edit box to a real variable, using just a command? I am developing a Win32 program.
Thank you in advance.
Carlos Santos
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not know how you get the character string from an edit box, but you can convert the character string to a real value by using an internal read:
character(len=20) :: string
real :: value
read( string, * ) value
(You will probably want to add some error handling code here)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear arjenmarkus,
This kind of procedure doesn´t work in Win32 programs. I tried it but it didn´t work.
Thank you for your suggestion.
Carlos Santos.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You did not say what you tried, so there is not much to say about it. However, you seem to be unaware of a rather important principle. Fortran neither knows nor cares about an "edit box", just as it does not know about "black holes". A string is a string, whether it is engraved on a tombstone or is input through an edit box. A READ statement such as the one that Arjen Showed will work as long as the contents of string are suitable for being read as a real value. Whether the program is a Win32 program, a VMS program or one that controls a diesel engine is completely immaterial.
How you place the text that a user typed into an edit box into a string variable is specific to the OS and the API that you use. That, however, is not a Fortran question per se.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How is the edit box created?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Paul Burkardt has assembled a huge library of Fortran subroutines (http://people.sc.fsu.edu/~jburkardt/f_src/chrpak/chrpak.html) for converting characters and character strings to all kinds of variables and vice versa. Have a look at the descriptions and the sources. Internal read of a character string is widely used, also in Paul's routines, but he added a few error checks to analyse weird strings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
assuming your dialog edit box was made with the windows api and not quickwin: use IFWIN, only: dword, SetDlgItemText, GetDlgItemText, handle integer(handle) :: hDlg integer :: ID_of_editbox_control integer(DWORD) :: ret character(80) :: gout, gin ! to set gout='my text'//achar(0) ! null terminated string ret = SetDlgItemText (hDlg, ID_of_editbox_control, gout ) !dialog handle and control ID !to get text ret = GetDlgItemText(hDlg, ID_of_editbox_control, gin,len(gin))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adding to app4619's are the comments made earlier:
The data obtained in gin is the text of what was in the edit box. In the #7 example, this edit box is assumed to not have more than 80 characters of data. The data you type into the edit box must be convertible per-Fortran data representation:
Valid: 123456.78
Not valid: $123,456.78
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page