2015-10-05 51 views
0

我在製作故障排除程序。到目前爲止,我有以下代碼:如何在視覺基礎知識中製作故障排除程序?

Public Class speakers 

    Dim currentq As Integer 
    Dim Q1 As String = "Does sound play?" 
    Dim Q2 As String = "Has the sound got too much bass or treble?" 
    Dim Q3 As String = "Is the sound too loud or quiet?" 
    Dim Q4 As String = "Is sound distorted?" 
    Dim Q5 As String = "" 
    Dim Q6 As String = "" 
    Dim Q7 As String = "" 
    Dim Q8 As String = "" 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     If currentq = 0 Then 
      Label1.Text = Q1 
      currentq = 1 
     ElseIf currentq = 1 Then 
      Label1.Text = Q2 
      currentq = 2 
     ElseIf currentq = 2 Then 
      Label1.Text = Q3 
      currentq = 3 
     ElseIf currentq = 3 Then 
      Label1.Text = Q4 
      currentq = 4 
     ElseIf currentq = 4 Then 
      Label1.Text = Q5 
      currentq = 5 
     ElseIf currentq = 5 Then 
      Label1.Text = Q6 
      currentq = 6 
     ElseIf currentq = 6 Then 
      Label1.Text = 
      currentq = 7 
     End If 
    End Sub 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     currentq = currentq + 1 
    End Sub 

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 
     Controls.Clear() 
     InitializeComponent() 
     Me.Hide() 
     Form1.Show() 
    End Sub 

End Class 

你會如何做一個標籤改變一個問題到另一個當你點擊是或否按鈕

回答

0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    'currentq = 0 here , so it shows the next question   
    LoadNextQuestion() 
End Sub 


Public Sub LoadNextQuestion() 
    If currentq = 0 Then 
     Label1.Text = Q1    
    ElseIf currentq = 1 Then 
     Label1.Text = Q2 
    ElseIf currentq = 2 Then 
     Label1.Text = Q3 
    ElseIf currentq = 3 Then 
     Label1.Text = Q4 
    ElseIf currentq = 4 Then 
     Label1.Text = Q5 
    ElseIf currentq = 5 Then 
     Label1.Text = Q6 
    ElseIf currentq = 6 Then 
     Label1.Text = Q7 
    End If 
End Sub 
現在

在無/有按鈕:

沒有按鈕:

'Loads next question 
currentq += 1 
LoadNextQuestion() 

是按鈕:

Controls.Clear() 
InitializeComponent() 
Me.Hide() 
Form1.Show() 
+0

是的,我是新來的吧。感謝您的建議 –

+0

代碼可以在許多方面進行修改,將做同樣的工作,也歡迎^^ – bigworld12

0

嘗試更多的東西像這樣...

Public Class speakers 

    Dim currentq As Integer 
    Dim questions() As String = { 
     "Does sound play?", 
     "Has the sound got too much bass or treble?", 
     "Is the sound too loud or quiet?", 
     "Is sound distorted?", 
     "a", 
     "b", 
     "c", 
     "d" 
    } 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Button4.PerformClick() 
    End Sub 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     currentq = currentq + 1 
     If (currentq < questions.Length) Then 
      Label1.Text = questions(currentq) 
     Else 
      MessageBox.Show("End of questions reached.") 
     End If 
    End Sub 

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 
     currentq = -1 
     Button1.PerformClick() 
    End Sub 

End Class