Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spinner 1

Status
Not open for further replies.

cslawtom

MIS
Sep 3, 2001
161
HK
Hi All,

I would like to have a spinner starting from 0.5 with increment 0.5 for first and 1 for the rest.
That is

0.5 -> 1.0 -> 2.0 -> 3.0 and

3.0 -> 2.0 -> 1.0 -> 0.5

Is it possible? Many Thanks.
 
Not sure if it is possible with a spinner but it could be carried out using a drop down LISTBOX. Depends how many values you are to allow the user to select as to whether it is practical.
Keith
 
CSLAWTOM

Here is an example of that (by using a textbox instead of using the spinner's entry box). Copy the following in a program to see how it works.:
Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	ADD OBJECT spinner1 AS spinner WITH ;
		Height = 25, ;
		Left = 216, ;
		SpinnerHighValue = 100.00, ;
		SpinnerLowValue =   0.00, ;
		TabIndex = 2, ;
		Top = 72, ;
		Width = 20, ;
		Name = "Spinner1"
	ADD OBJECT text1 AS textbox WITH ;
		Alignment = 3, ;
		Value = 0, ;
		Height = 23, ;
		Left = 120, ;
		TabIndex = 1, ;
		Top = 73, ;
		Width = 97, ;
		Name = "Text1"
	PROCEDURE spinner1.DownClick
		DO CASE
		  CASE THISFORM.TEXT1.Value = 0
		      CASE THISFORM.TEXT1.Value = 0
		  CASE THISFORM.TEXT1.Value = .5
		    THISFORM.TEXT1.Value = 0
		  CASE THISFORM.TEXT1.Value = 1
		      THISFORM.TEXT1.Value = .5
		  OTHERWISE
		   THISFORM.TEXT1.Value = THISFORM.TEXT1.Value -1
        	ENDCASE
	ENDPROC
	PROCEDURE spinner1.UpClick
		DO CASE
		  CASE THISFORM.TEXT1.Value = 100
		     THISFORM.REXR1.VALUE = 100
		  CASE THISFORM.TEXT1.Value = 0
		    THISFORM.TEXT1.Value = .5
		  CASE THISFORM.TEXT1.Value = .5
		      THISFORM.TEXT1.Value = 1
		  OTHERWISE
		   THISFORM.TEXT1.Value = THISFORM.TEXT1.Value +1
		ENDCASE
	ENDPROC
ENDDEFINE
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
You can use a spinner. After dropping the control on the form, use the following values:

Increment: 0.5
SpinnerLowValue: 0.5
SpinnerHighValue: whatever

Then put this code in the InteractiveChange event:
Code:
IF This.Value < 1
   This.Increment = .5
ELSE
   This.Increment = 1
ENDIF
Dave S.
 
Thanks Keith. It works well.

Thanks Dave. It works but 1.0 back to 0.5 has problem. Anyway I will try to solve the problem by following your advice.
 
Using Keith's method is better in my case. Thanks Keith again.
 
Dave S

IF This.Value < 1
This.Increment = .5
ELSE
This.Increment = 1
ENDIF


The problem is, is that the spinner increments before it hit the interactive change of the spinner.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
You can use a spinner. After dropping the control on the form, use the following values:

Increment: 0.5
SpinnerLowValue: 0.5
SpinnerHighValue: whatever
value=0.5

Then put this code in the InteractiveChange event:

IF this.Value>0.5
this.Increment=1
ENDIF
IF this.Value=0.5
this.Increment=0.5
endif
 
738262

IF this.Value>0.5
this.Increment=1
ENDIF
IF this.Value=0.5
this.Increment=0.5
endif


Do you test this before posting it? In my experience this will not work.
[ol][li]You cannot set the value .5 in a spinner, and if you set it by code (which you can do), when you go from 3,2,1 it never reaches .5.[/li][/ol] Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Mike,

I tested before I posted, and it worked. You can set the Increment property to .5, but you have to use 0.5 instead of just .5. Please note though, that I initially tested it using VFP 7. It didn't work properly using VFP 6 until I added this line in the Init event:

This.Value = 0.5
Dave S.
 
DSummZZZ

I tested before I posted, and it worked. You can set the Increment property to .5, but you have to use 0.5 instead of just .5. Please note though, that I initially tested it using VFP 7. It didn't work properly using VFP 6 until I added this line in the Init event:

This.Value = 0.5


Have you tried to go from 0.5 (which you set as a default value) to 3 and back down to 0? Notice on the way back down you cannot get to 0.5.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 

Here's my settings:

SpinnerHighValue = 10
SpinnerLowValue = 0.50
Value = 0.50

In the InteractiveChange event:

IF this.Value < 1 && ... in this case it would be 0
This.Increment = .5
ELSE
This.Increment = 1
ENDIF

So yes, I have gone from 0.5 to 10, then back from 10 to 0.5. Repeatedly.
Now, I also saved that control as a class, and opened it using the class browser. Here is the class code generated by VFP:

Code:
**************************************************
*-- Class:        sp1 (c:\program files\microsoft visual foxpro 7\sp1.vcx)
*-- ParentClass:  spinner
*-- BaseClass:    spinner
*-- Time Stamp:   11/21/02 08:00:00 AM
*
DEFINE CLASS sp1 AS spinner


	Height = 24
	Increment =   0.50
	Left = 492
	SpinnerHighValue =  10.00
	SpinnerLowValue =   0.50
	Top = 168
	Width = 69
	Value = 0.5
	Name = &quot;Spinner1&quot;


	PROCEDURE InteractiveChange
		IF this.Value < 1
		   This.Increment = .5
		ELSE
		   This.Increment = 1
		ENDIF
	ENDPROC


ENDDEFINE
*
*-- EndDefine: sp1
**************************************************

Granted, without a little more tweaking, you can't get to 0 but that would be doable too I'm sure.
Dave S.
 

Granted, without a little more tweaking, you can't get to 0 but that would be doable too I'm sure.

I guess that would be a concern. Although the original poster did not specify it.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Hi Mike,

738262's suggestion worked properly. I had tried but as I have more code required to add in, I used your method.

Thanks.

 
I took this one step farther and it does work. This has a triple increment, plus up and down now works.

DO case
Case this.Value < 5 and this.Increment = 5
this.Increment = 1
this.value = 4.00
Case this.Value < 3 and this.Increment = 1
this.Increment = .5
this.value = 2.50
Case this.Value < 1 and this.Increment = .5
this.Increment = .25
this.value = .75
Case this.value < 1
thisform.spinner1.Increment = .25
Case this.value >= 1 and this.value < 3
thisform.spinner1.Increment = .5
Case this.value >= 3 .and. this.Value < 5
thisform.spinner1.Increment = 1
Case this.Value >= 5
this.Increment = 5

EndCase
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top