Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

visual studio - Is there a way to indicate an if-then statement based on a value range in a TrackBar? (VB.NET)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...