T
Tim Daim
Since 3 days I'm fighting with a percentage calculation.
I have a combo box that shows values from "10%" - "200%".
The device I'm going to control (an automated machine) accepts values of
let's say Speed Min 35 and Speed Max 249.
I am also given a default speed which could be 85.
Yes, the speed really has no value (like operations/ second or something
like that), it's only some made up value!
My boss wants me to give the user a choice to select the robot's speed.
So I am offering the user a combo box with values from 10% to 200%
percent, and 100% should be the robot's default speed (=85). I wanted to
use a slider but my boss didn't want it.
I tried to make a sensefull calculation to which speed values some
percentage values might point, but I haven't found the correct formula yet.
The one I have is really faulty. Can somebody help? I am totally desperate.
Thank you!
Tim
Private Function PercentToSpeed(ByVal uPercent As Integer, ByVal
uMinSpeed As Long, ByVal uMaxSpeed As Long, ByVal uDefaultSpeed As Long,
ByVal uMinPercent As Long, ByVal uMaxPercent As Long) As Long
Dim lMiddle& '/100%
lMiddle = uDefault
Dim lAvail&
If uPercent = 100 Then
PercentToSpeed= lMiddle
ElseIf uPercent < 100 Then
lAvail = lMiddle - uMin
PercentToSpeed = uMin + ((uPercent * lAvail) \ 100)
ElseIf uPercent > 100 Then
lAvail = uMax - lMiddle
PercentToSpeed= lMiddle + ((uPercent * lAvail) \ 100) \ 2 '/* 2
because our max percent is 200%.
End If
End Function
I have a combo box that shows values from "10%" - "200%".
The device I'm going to control (an automated machine) accepts values of
let's say Speed Min 35 and Speed Max 249.
I am also given a default speed which could be 85.
Yes, the speed really has no value (like operations/ second or something
like that), it's only some made up value!
My boss wants me to give the user a choice to select the robot's speed.
So I am offering the user a combo box with values from 10% to 200%
percent, and 100% should be the robot's default speed (=85). I wanted to
use a slider but my boss didn't want it.
I tried to make a sensefull calculation to which speed values some
percentage values might point, but I haven't found the correct formula yet.
The one I have is really faulty. Can somebody help? I am totally desperate.
Thank you!
Tim
Private Function PercentToSpeed(ByVal uPercent As Integer, ByVal
uMinSpeed As Long, ByVal uMaxSpeed As Long, ByVal uDefaultSpeed As Long,
ByVal uMinPercent As Long, ByVal uMaxPercent As Long) As Long
Dim lMiddle& '/100%
lMiddle = uDefault
Dim lAvail&
If uPercent = 100 Then
PercentToSpeed= lMiddle
ElseIf uPercent < 100 Then
lAvail = lMiddle - uMin
PercentToSpeed = uMin + ((uPercent * lAvail) \ 100)
ElseIf uPercent > 100 Then
lAvail = uMax - lMiddle
PercentToSpeed= lMiddle + ((uPercent * lAvail) \ 100) \ 2 '/* 2
because our max percent is 200%.
End If
End Function