Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 2 decades ago

關於..亂數猜題...

題目:

1. 按一下"出題",標籤上亂數顯示一個中文國名。

2. 使用者在答案區內按鈕按一下,出現英文國名

假如等於則用msgbox "BINGO!" 不等於則用msgbox "Try again!"

使用者介面如下:

 _label1_    _答案區_   註: label1 空白 Command1 出題

 _出題_   _Command2(0)_    label2 答案區

       _Command2(1)_ ←這5個都是Command2

       _Command2(2)_  會自動隱藏文字,選完換下題會消失

       _Command2(3)_

       _Command2(4)_

※我最大的問題就是當我用 if 的時候,

它會一下子出現全部的英文國名,連續跑12個"BINGO!"

一直測都測不出來...

Command2_Click那邊有點誤...可以幫解一下嗎?

亂數以OK~設定好了~

Private Sub Command1_click()

Dim a(12) As String

a(0) = "中國"

a(1) = "英國"

a(2) = "加拿大"

a(3) = "台灣"

a(4) = "法國"

n = Fix((5 - 0 + 1) * Rnd) + 0 '亂數選出題目

Label1.Caption = a(n)

End Sub

Private Sub Command2_Click(Index As Integer)

Dim a(5) As String

a(0) = "中國"    'a(5)從label1的中文國名對應到b(5)中文國名

a(1) = "英國"    答對就"BINGO!",答錯就"Try again!"

a(2) = "加拿大"

a(3) = "台灣"

a(4) = "法國"

Dim b(5) As String

b(0) = "china"

b(1) = "England"

b(2) = "Canada"

b(3) = "Taiwan"

b(4) = "France"

If a(0) = b(0) Then

Command2(0).Caption = a(0)

MsgBox "BINGO!"

Else

MsgBox "Try again!"

End If

If a(1) = b(1) Then

Command2(1).Caption = a(1)

MsgBox "BINGO!"

Else

MsgBox "Try again!"

End If

If a(2) = b(2) Then

Command2(2).Caption = a(2)

MsgBox "BINGO!"

Else

MsgBox "Try again!"

End If

If a(3) = b(3) Then

Command2(3).Caption = a(3)

MsgBox "BINGO!"

Else

MsgBox "Try again!"

End If

If a(4) = b(4) Then

Command2(4).Caption = a(4)

MsgBox "BINGO!"

Else

MsgBox "Try again!"

End If

EndSub

Private Sub Form_Load()

Command2(0).Caption = ""

Command2(1).Caption = ""

Command2(2).Caption = ""

Command2(3).Caption = ""

Command2(4).Caption = ""

End Sub

Update:

你只做對了一點點

當我要執行程式的時候

我還沒開始選亂數,直接按Command2(0)

卻會出現"BINGO!",其他按鈕卻是"Try again!"

而且我按了亂數之後選到了"中國"

點了Command2(0),卻全部按鈕的英文都跑出來了。

5 Answers

Rating
  • Anonymous
    2 decades ago
    Favorite Answer

    Dim a(12) As String

    Dim b(5) As String

    Dim n As Integer

    Private Sub Command1_click()

    a(0) = "中國"

    a(1) = "英國"

    a(2) = "加拿大"

    a(3) = "台灣"

    a(4) = "法國"

    b(0) = "china"

    b(1) = "England"

    b(2) = "Canada"

    b(3) = "Taiwan"

    b(4) = "France"

    n = Fix((5 - 0 + 1) * Rnd) + 0 '亂數選出題目

    Label1.Caption = a(n)

    Command2(0).Caption = b(0)

    Command2(1).Caption = b(1)

    Command2(2).Caption = b(2)

    Command2(3).Caption = b(3)

    Command2(4).Caption = b(4)

    End Sub

    Private Sub Command2_Click(Index As Integer)

    If n = Index Then

    Label2.Caption = b(n)

    MsgBox "BINGO!"

    Else

    MsgBox "Try again!"

    End If

    End Sub

    Private Sub Form_Load()

    Command2(0).Caption = ""

    Command2(1).Caption = ""

    Command2(2).Caption = ""

    Command2(3).Caption = ""

    Command2(4).Caption = ""

    End Sub

    '你比較一下有何不同 , 這個可以執行

  • Anonymous
    6 years ago

    * ***** http://*****

    [電子遊戲]

    拉霸、水果盤、7PK、5PK

    [運彩遊戲]

    棒球、籃球、足球、網球、冰球、各種體育經典賽事

    [真人遊戲]

    百家樂、21點、骰寶、輪盤、牌九、三公、輪盤、翻攤、牛牛、二八杠

    [對戰遊戲]

    台灣麻將、德州撲克、骰盅吹牛、四支刀、鬥地主、十三支、二八槓、暗棋、接龍

    [彩球遊戲]

    香港六合、台灣樂透、今彩539、樂合彩、大陸時時彩、基諾彩、北京賽車、賽狗、賽馬、指數

    [優惠活動]

    1. 新舊會員儲值就送500點

    2. 真人百家樂彩金等你拿

    ***** http://*****

    歡迎免費體驗試玩!!

    線上影片直播、正妹圖、討論區免費註冊 ~

  • Anonymous
    2 decades ago

    Dim Questions(100, 1) As String '(x,0) 中文, (x,1) 英文 ; 最多100題組.

    Dim QFlag As Integer '記錄題組編號

    Dim QTotal As Integer '記錄出題總數

    Private Sub Form_Load()

    Questions(0, 0) = "中國": Questions(0, 1) = "China"

    Questions(1, 0) = "英國": Questions(1, 1) = "England"

    Questions(2, 0) = "加拿大": Questions(2, 1) = "Canada"

    Questions(3, 0) = "台灣": Questions(3, 1) = "Taiwan"

    Questions(4, 0) = "法國": Questions(4, 1) = "France"

    'TextAlign=2 文字置中... 應該沒錯...屬性名稱不太記得了.. @.@

    Label1.TextAlign = 2: Label1.Caption = "???"

    Label1.Font.Bold = True: Label1.ForeColor = RGB(128, 128, 0)

    Label2.TextAlign = 2: Label2.Caption = "答案區"

    Label2.Font.Bold = True: Label2.ForeColor = RGB(0, 0, 255)

    QTotal = 0

    Command1.Caption = "出題 (" & QTotal & ")"

    For i = 0 to 4

    Command2(i).Caption = Questions(i, 1)

    Command2(i).Enabled = False

    Next

    End Sub

    Private Sub Command1_Click()

    Randomize

    QFlag = Int(Rnd * 5) '隨機選出題目

    Label1.Caption = Questions(QFlag, 0)

    QTotal = QTotal + 1

    Command1.Caption = "出題 (" & QTotal & ")"

    For i = 0 to 4

    Command2(i).Enabled = True

    Next

    End Sub

    Private Sub Command2_Click(Index As Integer)

    If Index = QFlag Then

    MsgBox "BINGO!"

    Else

    MsgBox "Try again!"

    End If

    For i = 0 to 4

    Command2(i).Enabled = False

    Next

    End Sub

    Source(s): 東抄西抄
  • Anonymous
    2 decades ago

    Dim a(5) As String

    Dim b(5) As String

    Dim n As Integer

    Private Sub Command1_click()

    n = Fix((5 - 0 + 1) * Rnd) + 0 '亂數選出題目

    Label1.Caption = a(n)

    Label2.Caption = ""

    End Sub

    Private Sub Command2_Click(Index As Integer)

    If n < 0 Then

    MsgBox "請先點選出題鈕"

    Exit Sub

    End if

    If n = Index Then

    Label2.Caption = b(n)

    MsgBox "BINGO!"

    Else

    MsgBox "Try again!"

    End If

    End Sub

    Private Sub Form_Load()

    Command2(0).Caption = ""

    Command2(1).Caption = ""

    Command2(2).Caption = ""

    Command2(3).Caption = ""

    Command2(4).Caption = ""

    a(0) = "中國"

    a(1) = "英國"

    a(2) = "加拿大"

    a(3) = "台灣"

    a(4) = "法國"

    b(0) = "China"

    b(1) = "England"

    b(2) = "Canada"

    b(3) = "Taiwan"

    b(4) = "France"

    Label1.Caption = ""

    Label2.Caption = ""

    n = -1

    End Sub

    Source(s): 加冰不加糖 大大的解答
  • How do you think about the answers? You can sign in to vote the answer.
  • 世賢
    Lv 7
    2 decades ago

    Dim a(12) As String

    Dim b(5) As String

    Dim n As Integer

    Private Sub Command1_click()

      a(0) = "中國"

      a(1) = "英國"

      a(2) = "加拿大"

      a(3) = "台灣"

      a(4) = "法國"

      b(0) = "china"

      b(1) = "England"

      b(2) = "Canada"

      b(3) = "Taiwan"

      b(4) = "France"

      n = Int(Rnd * 5) '亂數選出題目

      Label1.Caption = a(n)

      For i = 0 To 4

        Command2(i).Caption = b(i)

      Next

    End Sub

    Private Sub Command2_Click(Index As Integer)

      If Command2(Index).Caption <> "" Then

        If n = Index Then

          Label2.Caption = b(n)

          MsgBox "BINGO!"

        Else

          MsgBox "Try again!"

        End If

      Else

        MsgBox "請先點選「出題」再做答"

      End If

    End Sub

    Private Sub Form_Load()

      For i = 0 To 4

        Command2(i).Caption = ""

      Next

    End Sub

Still have questions? Get your answers by asking now.