在我开始之前,如果有些事情可能不清楚,我想道歉,但我会尽力而为。我使用 vb net 制作了一个使用列表框(和文本框)和案例语句的程序。我试图创建一个类,稍后允许我将用户输入发送到访问数据库。我遇到的问题是我无法将包含 case 语句的变量值发送到数据库。
这是代码,可能有人可以帮助我解决问题:
这就是我接受用户输入的形式(它还包含文本框,但我已经弄清楚了):
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Fill Listbox with items
Me.Controls.Add(ListBox1)
ListBox1.Items.Add("Shoot in-laws")
ListBox1.Items.Add("Become a paparazzi")
ListBox1.Items.Add("Drive 5 mph over speed limit")
ListBox1.Items.Add("Treat for rabies once a week")
ListBox1.Items.Add("Cheat on income taxes")
ListBox1.Items.Add("Breathe uder water")
ListBox1.Items.Add("Recite the Gettysburg Address")
ListBox1.Items.Add("Smile while being staked")
ListBox1.Items.Add("Stay calm while getting help on C#")
ListBox1.Items.Add("Day dream about playing chess")
ListBox1.Items.Add("Take candy from a baby")
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Select Case ListBox1.SelectedIndex
Case 0
dblTestScore = 50
Case 1
dblTestScore = 15
Case 2
dblTestScore = 25
Case 3
dblTestScore = 55
Case 4
dblTestScore = 10
Case 5
dblTestScore = 20
Case 6
dblTestScore = 40
Case 7
dblTestScore = 65
Case 8
dblTestScore = 30
Case 9
dblTestScore = 35
Case 10
dblTestScore = 45
End Select
End Sub
现在下面的代码在类中:
Public Class ClsWriteRecord
Public Sub addNewRecordMore(ByVal listTestScore As ListBox, ByVal listTEST As ListBox,
'declare variables
Dim dblTestScore As Double
Dim strTEST As String
'Get values
strTEST = listTEST.GetItemText(listTEST.SelectedItem)
dblTestScore = listTEST.GetItemText(listTEST.SelectedIndex)
End Sub
End Class
strTEST 正常工作并获取列表框项目并将其发送到数据库(例如“Shoot in-laws”),但 dblTestScore 没有。取而代之的是值,例如 50,15, 25 等,它发送 0,1,2 这是案例编号。
谁能帮我弄清楚?我搜索互联网但找不到答案。提前致谢。