SpinBar Precision

Post

Posted
Rating:
#1 (In Topic #1162)
Regular
PartierSP is in the usergroup ‘Regular’
Hey guys!  Hope all is well.  It's been a while since I was last here but today I am going to break down and finally ask this question that has been bugging me for the past year.

I have a project where I want to set the percision (number of decimal places) on a SpinBar to 4 (aka 0.0001).  No matter what I do I can't get it work.  It usually just gives me 3 places instead (0.001) or sometimes even resets it to zero places (0).

My end goal is to have the precision set at run time depending on the measuring units the user wants to use.  Thus if the user wants to enter the value in millimeters, the SpinBox will have a range of 0.000 to 0.400, or if using inches then the SpinBox will have a range of 0.0000 to 0.0160.

In my program I have tried setting the SpinBox directly with values for Max and Step without success.  Thinking it might be Gambas assuming I am using a different datatype, I tried the following:

Code (gambas)

  1. Public Sub CBUnits_Click()
  2.  
  3.   Dim fStep As Float
  4.   Dim fMax As Float
  5.  
  6.   If CBUnits.Index = 0 Then
  7.     fStep = 0.0001
  8.     fMax = 0.0160
  9.   Else
  10.     fStep = 0.001
  11.     fMax = 0.400
  12.  
  13.   SBMeasured.Step = fStep
  14.   SBMeasured.MaxValue = fMax
  15.  
  16.  
But again, no success.  Any ideas?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
I don't think you can do what you want with a SpinBar. So I suggest you create your own control. Try running the code below in a Graphical Application.

<IMG src="https://www.cogier.com/gambas/SpinBarReplacement.png"> </IMG>

Code (gambas)

  1. HBox1 As HBox
  2. LabelText As Label
  3. LabelValue As Label
  4. Slider1 As Slider
  5.  
  6. Public Sub Form_Open()
  7.  
  8.   BuildControl
  9.   LabelText.Text = "Select value "
  10.  
  11.  
  12. Public Sub BuildControl()
  13.  
  14.   With Me
  15.     .Arrangement = Arrange.Vertical
  16.     .Padding = 5
  17.     .W = 500
  18.     .H = 50
  19.  
  20.   With HBox1 = New HBox(Me)
  21.     .H = 28
  22.  
  23.   With LabelText = New Label(HBox1) As "LabelText"
  24.     .AutoResize = True
  25.     .Padding = 5
  26.  
  27.   With Slider1 = New Slider(HBox1) As "Slider1"
  28.     .Expand = True
  29.     .maxValue = 4000
  30.     .MinValue = 0
  31.  
  32.   With LabelValue = New Label(HBox1) As "LabelValue"
  33.     .W = 75
  34.     .Padding = 5
  35.     .Text = "0.0000"
  36.  
  37.  
  38. Public Sub Slider1_Change()
  39.  
  40.   LabelValue.Text = Format(Slider1.Value / 10000, "0.0000")
  41.  
  42.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
vuott is in the usergroup ‘Regular’

PartierSP said

a range of 0.0000 to 0.0160.
By manipulating the "SpinBar" Control a bit, I got :? this:

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.  
  4.   With SpinBar1
  5.     .W = 100
  6.     .H = 50
  7.     .X = 0
  8.     .MinValue = 0.0
  9.     .MaxValue = 16.0
  10.  
  11.   With da = New DrawingArea(SpinBar1.Children[0]) As "DASpin"
  12.     .W = SpinBar1.W - 19
  13.     .H = SpinBar1.H - 2
  14.     .X = 1
  15.     .Y = 1
  16.     .Font.Size = 11
  17.     .Background = Color.White
  18.  
  19.   System.Language = "en_US.UTF-8"
  20.  
  21.  
  22.  
  23. Public Sub DASpin_Draw()
  24.  
  25.   With Paint
  26.     .Brush = .Color(&2f8cc5)
  27.     .Rectangle(0, 0, (SpinBar1.W * SpinBar1.Value) / 16.0, da.H)
  28.     .Fill
  29.     tw = .Font.TextWidth("0.0000")
  30.     th = .Font.TextHeight("0.0000")
  31.     .Brush = .Color(Color.Black)
  32.     .DrawText(Format(SpinBar1.Value / 1000, "#.0000"), da.W - tw, (da.H / 2) - (th / 2), tw, th)
  33.     .End
  34.  
  35.  
  36.  
  37. Public Sub SpinBar1_Change()
  38.  
  39.   Me.Title = Format(SpinBar1.Value / 1000, "#.0000")
  40.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
PartierSP is in the usergroup ‘Regular’
Thanks guys.  I am going to try both of those to see which one I prefer.  :D

I have done very little work on custom controls so these techniques are little new to me.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
vuott is in the usergroup ‘Regular’
cogier's solution, suggest you create ex novo your own Control, is the most expedient and most appropriate.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.