text integer conversion

text integer conversion

This is a newbie question, have the following code, which works acceptably but am wondering if there is a simpler way to do it? I want to have a list box with a selection of integers or real numbers available as choices. I want to read the operators selection, do some calculations with this choice and then output them back to a different dialog box. If there is a way I would store the originals in the intput box as integers or reals, rather than strings. As it is I read a string, convert it to and integer, do the calculations, convert back to an string and then send it back to the other dialog box.

I'm sure this is trivial, let me know if there is a more straight forward way.

Thanks

Jim

  logical retlog 
 
! read input from dialog box  
    retlog = DlgGet( dlg, idc_input, index ) 
 
!  convert string to integer 
    read(index,*) value 
!  perform calculations 
    value3=value*3 
!  convert integer value back to string 
    write(index2,'(I4)') value3 
!  send output as string back to different dialog box 
    retlog = DlgSet( dlg, IDC_OUTPUT, index2 )
2 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

That's the only sure way. There are Win32 APIs GetDlgItemInt and SetDlgItemInt (use Dlg%hWnd as the first argument) but I'm not sure whether they'd work correctly in conjunction with DFLOGM (I foresee problems with updating of edit box contents).

I usually use a home-brew helper library for working with strings. That will avoid necessity for having a character dummy variable for writing (but not for reading),
something along these lines:

MODULE STRINGS 
INTERFACE STRING 
   MODULE PROCEDURE FSTRING 
   MODULE PROCEDURE ISTRING 
END INTERFACE 
 
CONTAINS 
 
FUNCTION FSTRING(fValue, iWid, iPrec) RESULT(s) 
!Writes fValue into string of length iWid with iPrec decimals 
CHARACTER(LEN=iWid):: s 
REAL, INTENT(IN):: fValue 
INTEGER, INTENT(IN):: iWid, iPrec 
CHARACTER(10):: sFormat 
INTEGER:: iErr 
WRITE(sFormat, "('f', i3.3,'.', i3.3)") iWid, iPrec 
WRITE(s, sFormat, IOSTAT=iErr) fValue 
END FUNCTION FSTRING 
!ISTRING is for your excercise :-) 
END MODULE STRINGS

So, your last line would look like retlog = DlgSet( dlg, IDC_OUTPUT, STRING(index2, 4) )

HTH

Jugoslav

Jugoslav
www.xeffort.com

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi