I am wanting to utilize a TrackBar in my Visual Studio project. My goal is to have the user scroll the TrackBar's indicator, and based on which value range it is in, it will change the a label's text.
Here's an example of how I tried to accomplish this:
Private Sub ScrollBarProgress() Handles MyBase.Load
If SelfEvaluationReportBAR.Value = (0) Then
FeelingLBL.Text = "Please select a value."
End If
If SelfEvaluationReportBAR.Value = (1, 25) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
If SelfEvaluationReportBAR.Value = (26, 50) Then
FeelingLBL.Text = "I feel improvement in my ability to perform this task."
End If
If SelfEvaluationReportBAR.Value = (51, 75) Then
FeelingLBL.Text = "My confidence in my ability to perform this task is substantial."
End If
If SelfEvaluationReportBAR.Value = (76, 100) Then
FeelingLBL.Text = "I feel fully confident in my ability to efficiently and accurately perform the day to day tasks that are assigned to me."
End If
End Sub
The problem is that whenever I tried to set the range, it gives the following error:
Error BC30452 Operator '=' is not defined for types 'Integer' and '(Integer, Integer)'.
I think I have the formatting wrong. Does anyone have any ideas on how the range could/ should be formatted?
Here are my current settings for the TrackBar:
Private Sub SelfEvaluationReportBAR_Scroll(sender As Object, e As EventArgs) Handles MyBase.Load
SelfEvaluationReportBAR.Minimum = 0
SelfEvaluationReportBAR.Maximum = 100
SelfEvaluationReportBAR.SmallChange = 1
SelfEvaluationReportBAR.LargeChange = 5
SelfEvaluationReportBAR.TickFrequency = 5
End Sub
End Class
There are many ways to accomplish your task
First
If SelfEvaluationReportBAR.Value >= 1 AndAlso SelfEvaluationReportBAR.Value <= 25) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
Second
Select case SelfEvaluationReportBAR.Value
Case 0
....
Case 1 To 25
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
Case 26 To 50
...
' Other case follow
End Select
Third
If Enumerable.Range(1, 25).Contains(c) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
These are the ways that comes to mind, probably there are other.
The first two examples are the most basic approaches and with just five ranges I would stay with the simple If one. The third one is just to show how many ways exist but I don't really recommend to build an enumerable range only to check if a number is contained.