Salut à tous, j'ai du mal à trouver le bon flux pour un formulaire de question. Disons que j'ai 6 questions. Je les ai définis comme ceci:Poser des questions dans un tableau
Dim firstStart As Boolean = True
Dim totalQs As Integer = 0
Dim currentQ As Integer = 0
Dim theAnswers() As String
Dim theQuestions() As String = {"Please scan barcode 1 then press NEXT", "" & _
"Please scan barcode 1 then press NEXT", "" & _
"Please scan barcode 1 then press NEXT", "" & _
"Please scan barcode 1 then press NEXT", "" & _
"Please scan barcode 1 then press NEXT", "" & _
"Please scan barcode 1 then press COMPLETE"}
suivant/code du bouton complet ressemble à ceci:
Private Sub cmdNextFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNextFinish.Click
Call theQs(currentQ)
End Sub
Le form_load ressemble à ceci:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call theQs(0)
End Sub
Et maintenant la configuration de question ressemble ce:
Private Sub theQs(ByRef theQNum As Integer)
If firstStart = True And theQNum = 0 Then
firstStart = False
totalQs = (theQuestions.Length)
ReDim theAnswers(totalQs)
lblQ.Text = theQuestions(0)
cmdNextFinish.Enabled = True
cmdNextFinish.Text = "NEXT"
Call buttons(theQNum)
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
ElseIf theQNum = 0 Then 'ANSWERING THE FIRST QUESTION
theAnswers(currentQ) = "-" & txtNumber.Text
If currentQ <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
ElseIf theQNum = 1 Then 'ANSWERING THE SECOND QUESTION
theAnswers(currentQ) = txtNumber.Text
If theQNum <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
ElseIf theQNum = 2 Then 'ANSWERING THE THIRD QUESTION
theAnswers(currentQ) = txtNumber.Text
If theQNum <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
ElseIf theQNum = 3 Then 'ANSWERING THE FORTH QUESTION
theAnswers(currentQ) = txtNumber.Text
If theQNum <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
ElseIf theQNum = 4 Then 'ANSWERING THE FIFTH QUESTION
theAnswers(currentQ) = txtNumber.Text
If theQNum <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
ElseIf theQNum = 5 Then 'ANSWERING THE SIXTH QUESTION
theAnswers(currentQ) = txtNumber.Text
If theQNum <> totalQs Then
currentQ = currentQ + 1
lblQ.Text = theQuestions(currentQ)
If (totalQs - currentQ) = 0 Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
txtNumber.Text = ""
txtNumber.MaxLength = theQuestionTextboxLimits(theQNum)
txtNumber.Focus()
Call buttons(currentQ)
Else
'Call writeXMLFile()
MsgBox("exited")
End If
End If
End Sub
Je semble être confus parce que quand il arrive à la question 5, il me donne une erreur de Index était en dehors des limites de la matrice. sur la ligne de
lblQ.Text = theQuestions(currentQ)
pour theQNum = 5
Je sais que le 5 question, mais le tableau ne va pas jusqu'à 6.
ce que je fais mal ici (ou overthinking quelque chose de simple)
Merci,
David
MISE A JOUR GOT IT
Private theQNum As Integer
Sub Start
theQNum =0
SetupNextQuestion
End Sub
Sub SetupNextQuestion
txtNumber.Text = ""
lblQuestion.Text = theQuestions(theQNum)
If theQNum = (theQuestions.Length - 1) Then
cmdNextFinish.Text = "Complete"
Else
cmdNextFinish.Text = "NEXT"
End If
End Sub
Sub cmdNextFinish_Click
theAnswers(theQNum) = txtNumber.Text
'Check if this is a finish
theQNum += 1
If theQNum >= theQuestions.Length Then
'Call writeXMLFile()
MsgBox("exited")
Else
SetupNextQuestion
End If
End Sub
David
Toujours l'erreur de ** L'index était en dehors des limites du tableau ** Ce nombre doit être 1 en avance puisque le QNum son sur (disons 0) doit charger la question suivante (1) après que l'utilisateur appuie sur NEXT . – StealthRT
pourquoi augmentez-vous la valeur de currentQ. La valeur de currentQ deviendra 6.Le tableau commence à partir de 0, ce qui signifie que la sixième question est theQuestions (5) – Harsh
Parce que c'est ce qui est rempli lorsque le bouton est appuyé, le bouton NEXT sera incrémenté de 1 chaque tour jusqu'à ce qu'il obtienne la dernière question où COMPLETE serait sur le bouton. – StealthRT