我制作了一個抽認卡應用程式,用戶可以在其中編輯每個抽認卡的難度。
Private Sub btnHard_Click(sender As Object, e As EventArgs) Handles btnHard.Click
Dim sqlstring As String = "select * from flashcards where Difficulty = 3" 'Select from flashcard table where difficulty = 3
dataadapter = New OleDb.OleDbDataAdapter(sqlstring, connection)
dt.Clear() 'Clears datatable
dataadapter.Fill(dt) 'Fills datatable
Dim index = rand.Next(dt.Rows.Count) ' generates index in the range 0 .. Count - 1
If txtBack.Visible = True Then
txtFront.Text = dt.Rows(index)(2).ToString()
txtBack.Visible = False
txtBack.Text = dt.Rows(index)(3).ToString()
Else
MsgBox("Please first reveal the back of the flashcard")
End If
End Sub
此按鈕選擇難度等于 3 的所有抽認卡,但如果沒有記錄,則系統會產生錯誤。那么,如果沒有具有該難度的記錄,我將如何獲得它以便系統生成一條訊息?
uj5u.com熱心網友回復:
Private Sub btnHard_Click(sender As Object, e As EventArgs) Handles btnHard.Click
Dim sqlstring As String = "select * from flashcards where Difficulty = 3" 'Select from flashcard table where difficulty = 3
dataadapter = New OleDb.OleDbDataAdapter(sqlstring, connection)
dt.Clear() 'Clears datatable
dataadapter.Fill(dt) 'Fills datatable
If dt.Rows.Count = 0 Then 'If record is not found in the database
MsgBox("There are no more flashcards inside this deck")
Exit Sub 'Code continus running if record is found
End If
Dim index = rand.Next(dt.Rows.Count) ' generates index in the range 0 .. Count - 1
If txtBack.Visible = True Then 'If the back of the flashcard is shown
txtFront.Text = dt.Rows(index)(2).ToString() 'Displays a random record in the third column (front of flashcard)
txtBack.Visible = False 'Does not display the back of the flashcard
txtBack.Text = dt.Rows(index)(3).ToString() 'Displays a random record in the fourth column ()
Else 'If the user has not pressed the reveal button before
MsgBox("Please first reveal the back of the flashcard")
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/362717.html
標籤:网络
上一篇:無法弄清楚基于類制作陣列
下一篇:k在C中的矩陣乘法中如何作業?
