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

real values in spin controls

Intel_C_Intel
Employee
1,244 Views
hi,
i want to assign a real value for a spin. and so i will do some calculation.is that possible to change spin with a real interval, such a step that is 0.0004 ?

...
lret = DlgSetSub(dlg, IDC_SPIN1, Win3Spin)
lret = DlgSetSub(dlg, IDC_EDIT1, Win3Edit, DLG_LOSEFOCUS)
lret = DlgSet(dlg, IDC_SPIN1, 0.25)
lret = DlgSet(dlg, IDC_SPIN1, 0, DLG_RANGEMIN)
lret = DlgSet(dlg, IDC_SPIN1, 50, DLG_RANGEMAX)
...

!****************************************************************************

SUBROUTINE Win3Spin( dlg, id, callbacktype )
...
real pos1
character*30 text1

if (callbacktype == dlg_change) then
status = dlgget(dlg, id, pos1)
write(text1, *) pos1
status = dlgset(dlg, IDC_EDIT1, text1)
endif

END SUBROUTINE Win3Spin

!****************************************************************************

SUBROUTINE Win3Edit( dlg, id, callbacktype )
...
real pos1
character*30 text1

if (callbacktype == dlg_losefocus) then
status = dlgget(dlg, id, text1)
read(text1, *) pos1
status = dlgset(dlg, IDC_EDIT1, text1)
status = dlgset(dlg, IDC_SPIN1, pos1)
endif

END SUBROUTINE Win3Edit
0 Kudos
8 Replies
Jugoslav_Dujic
Valued Contributor II
1,244 Views
Well... maybe, but not automatically. You can try the following code (untested). The idea is to read the contents of the edit control and add/subtract 0.004 manually, then write the contents back. To test whether the spin was moved up or down, the position is reset to the middle each time:

SUBROUTINE Win3Spin( dlg, id, callbacktype )

integer:: ipos, iErr
character*30:: text1
real:: pos, add

if (callbacktype == dlg_change) then
status = DlgGet(dlg, IDC_EDIT1, text1)
read(text1, *, IOSTAT=iErr) Pos
if (iErr.ne.0) pos = 0.
status = DlgGet(dlg, ID, iPos)
if (iPos < 25) then
Pos = Pos-0.04
else
Pos = Pos+0.04
end if
write(text1, *) pos
status = DlgSet(dlg, IDC_EDIT1, text1)
!Reset back to middle position
status = DlgGet(dlg, ID, 25)
endif
END SUBROUTINE Win3Spin[/pre]
Note that you'll lose the feature of "acceleration" of spin button (the longer you hold the button, the step increases).

Alternatively, you could try to convert your real range by multiplying/dividing by, say, 10**n. E.g. map range of allowed reals of (0.1...0.0001) into spin positions of (10000...1); each time the spin changes, divide its position by 10000. and set the edit control appropriately. However, if I recall correctly, the maximal allowed range of spin button is 65536 (but I'm not sure) so you can't cover wide ranges. Try it.

Jugoslav
0 Kudos
Intel_C_Intel
Employee
1,244 Views
hello again,
as you said i tried to divide/multiply the values when they overflow. for example i have a value that starts from 2e+12. and i want to put a spin control that will start from 1e+12 to 1e+14. so i did that code...

0 Kudos
durisinm
Novice
1,244 Views
I'm lost. What's a spin?

Mike
0 Kudos
Steven_L_Intel1
Employee
1,244 Views
A spin control has up and down buttons for selecting a number (usually displayed in an adjacent control.) For example, in a print dialog, the number of copies is usually a spin control.

Steve
0 Kudos
Intel_C_Intel
Employee
1,244 Views
dear steve,
if you know anything about my problem, could you help me? it is about putting exponential and real values in a spin control. check my win11 file, so you find where i need help. thank you...
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,244 Views
Well, your example almost works -- you just have to use the same control as a storage, and add logic for up/down:
SUBROUTINE Spin3( dlg, id, callbacktype )

  use dflogm
  use datas

  implicit none

  include 'resource.fd'

  type (dialog) dlg
  integer id, callbacktype

  logical status

  integer*4 iErr, iPos
  character*20 text
  real*4 pos

  pos = na 

if (callbacktype == dlg_change) then

   status = DlgGet(dlg, IDC_EDIT3, text)
   read(text, *, IOSTAT=iErr) pos

   if (iErr.ne.0)    pos = 0.
   pos = pos / 1e+12

   !Todo add logic to check min/max value.
   status = DlgGet(dlg, ID, iPos)
   if (iPos>50) then
      pos = pos + 1
   else if (iPos<50) then
      pos = pos - 1
   end if
   status = DlgSet(dlg, ID, 50)

   pos = pos * 1e+12
   write(text, *) pos
   status = DlgSet(dlg, IDC_EDIT3, text)
   status = DlgSet(dlg, IDC_STATIC_NA, adjustl(text))


endif

END SUBROUTINE Spin3

How you want the spin to behave is up to you. For example, you could increase the step if the value is bigger.

Note that your range is just about 1000. If I were you, I'd place a static box on the right side, wrote, "GHz" or "Giga" or "*10^12" or whatever, and place a normal edit box with integer value -- it is much more readable.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,244 Views
shiptar,

I don't know anything about this other than what a spin control is - I have never written code to use one. Jugoslav knows much more about dialog boxes than I do.

Steve
0 Kudos
Intel_C_Intel
Employee
1,244 Views
hi...
this morning i got your reply. i will try it,Jugoslavdujic. thank you again...
0 Kudos
Reply