vb.net - 如何获得一系列值 - Visual basic
问题描述
我做了一个测验,在测验结束时,用户会根据他们的表现获得反馈。这是代码:
Private Sub btnFinalScore_Click(sender As Object, e As EventArgs) Handles btnFinalScore.Click
lblScore11.Text = Val(lblScore10.Text)
If lblScore11.Text = 100 Then 'Deals if the user gets full marks
txtFinalFeedback.AppendText("CONGRATULATIONS! - You have achieved full marks!")
ElseIf lblScore11.Text = 90 Or 80 Or 70 Then 'Deals if the user gets between 70% to 90%l marks
txtFinalFeedback.AppendText("CONGRATULATIONS! - You only got a few questions wrong")
ElseIf lblScore11.Text = 60 Or 50 Or 40 Then 'Deals if the user gets between 40% to 60%l marks
txtFinalFeedback.AppendText("You got a fair few questions wrong, remember to go over these topics and repeat the quiz later")
ElseIf lblScore11.Text = 30 Or 20 Or 10 Then 'Deals if the user gets between 10% to 30%l marks
txtFinalFeedback.AppendText("You got a a lot of questions wrong, remember to go over these topics and repeat the quiz later")
Else
lblScore11.Text = 0 'Deals if the user gets no marks
txtFinalFeedback.AppendText("You got all the questions wrong, make sure to go over all the topics and repeat the quiz later")
End If
End Sub
如果用户得到 100,第一行代码可以正常工作,但如果用户有任何错误,总是会给出第二个反馈。我该如何解决?
解决方案
您应该将分数处理为数值,而不是文本。
然后你只需要检查分数是否大于或等于每个括号中的最低分数:
Private Sub btnFinalScore_Click(sender As Object, e As EventArgs) Handles btnFinalScore.Click
lblScore11.Text = lblScore10.Text
Dim score As Integer = CInt(lblScore10.Text)
If score = 100 Then 'Deals if the user gets full marks
txtFinalFeedback.AppendText("CONGRATULATIONS! - You have achieved full marks!")
ElseIf score >= 70 Then 'Deals if the user gets between 70% to 90%l marks
txtFinalFeedback.AppendText("CONGRATULATIONS! - You only got a few questions wrong")
ElseIf score >= 40 Then 'Deals if the user gets between 40% to 60%l marks
txtFinalFeedback.AppendText("You got a fair few questions wrong, remember to go over these topics and repeat the quiz later")
ElseIf score >= 10 Then 'Deals if the user gets between 10% to 30%l marks
txtFinalFeedback.AppendText("You got a a lot of questions wrong, remember to go over these topics and repeat the quiz later")
Else
txtFinalFeedback.AppendText("You got all the questions wrong, make sure to go over all the topics and repeat the quiz later")
End If
End Sub
推荐阅读
- javascript - 部署在 GitHub 页面上的 ReactJS 应用程序不适用于自定义域集
- c++ - 从邻接表 C++ 中删除元素
- sql - 按不同列值(时间戳)的 SQL 累积平均值
- laravel - 带有承载认证的 Laravel Json 测试
- javascript - 如何从 Firebase 以及 React Native 中的数组中删除数据
- audio - FFMPEG - 多轨、多通道文件到离散单声道文件
- python - 卡住未定义的变量,但找不到任何拼写错误或其他可能导致它的原因?
- postman - 从 Postman 调用受护照推特策略保护的 Passport API 端点
- swift - SwiftUI:启动时检查用户身份验证
- swift - PHAssetResource.assetResources() 调用的内存使用问题