- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please, someone could explain me how to get a real data from an edit box, when working with Windows Applications.
Sincerely,
Carlos Santos
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is code to read text from an EditBox control, and extract a REAL value. This is the WinAPI version, where the control's window handle (hwnd) and the id of the EditBox control (controlID) are known to the caller.
SUBROUTINE EditBoxReadText (hwnd, controlId, text, textLen) IMPLICIT NONE INTEGER(HANDLE), INTENT(IN) :: hwnd INTEGER, INTENT(IN) :: controlID INTEGER, INTENT(IN) :: textLen CHARACTER(LEN=textLen), INTENT(OUT) :: text INTEGER :: rval text = "" rval = SendControlMessage (hwnd, controlId, WM_GETTEXT, & textLen, LOC(text)) ! return value is number of characters copied IF (rval < 0) THEN CALL ControlError ("EditBoxReadText", controlId, "WM_GETTEXT") END IF END SUBROUTINE EditBoxReadText SUBROUTINE EditBoxGetReal (hwnd, controlID, argval, nulldefault) IMPLICIT NONE INTEGER(HANDLE), INTENT(IN) :: hwnd INTEGER, INTENT(IN) :: controlID REAL,INTENT(IN),OPTIONAL :: nulldefault REAL,INTENT(INOUT) :: argval INTEGER, PARAMETER :: maxchars = 40 CHARACTER(LEN=maxchars) :: contents REAL :: valu INTEGER :: status INTEGER :: pos, hour, minute CALL EditBoxReadText (hwnd, controlId, contents, maxchars) ! stop now if no data to convert pos = INDEX(contents, CHAR(0)) IF (is_empty(contents, pos)) THEN IF (PRESENT(nulldefault)) argval = nulldefault RETURN END IF CALL CStringToFortran (contents) contents = ADJUSTL(contents) ! allow ":" as a timefield delimiter pos = INDEX(contents, ':') status = 1 IF (pos > 0) THEN contents(pos:pos) = ' ' IF (pos == 1) THEN hour = 0 READ (contents, *, IOSTAT = status, END=5) minute ELSE READ (contents, *, IOSTAT = status, END=5) hour, minute END IF IF (status == 0) THEN SELECT CASE (minute) CASE (0:59) argval = FLOAT(hour) + FLOAT(minute)/60. END SELECT END IF RETURN ! regular real value ELSE IF (INDEX(contents, '.') == 0) THEN pos = INDEX(contents, ' ') contents(pos:pos) = '.' END IF READ (contents, '(F)', IOSTAT=status, END=5) valu IF (status == 0) argval = valu END IF 5 RETURN END SUBROUTINE EditBoxGetReal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Paul,
Thank you so much for your support! It helped me a lot.
Sincerely,
Carlos Santos.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Paul,
About your suggestion, I had doubt about the subroutines ControlError and CStringToFortran. They weren´t presented in your message. Please, could you explain me what they do? Could you send them for me?
Thank you in advance.
Carlos Santos.

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