我有下面的代碼。通過其中一個'elseif'語句,我不斷收到錯誤,指出''elseif'必須在前面匹配'if'或'elseif'語句「。我以前使用過這個語法,所以我不確定爲什麼這個錯誤出現了,如果任何人都可以提供一些提示。我已經看過其他例子,比如將「當時」分解爲一個新行,但它們似乎並不奏效。「否則必須在匹配if語句之前」 - 不清楚的錯誤
當我只是放置「If..then」語句時,它不會顯示出錯誤,但我相信我需要一個「else if」語句來做出決策。
Private Sub btnDeal_Click(sender As Object, e As EventArgs) Handles btnDeal.Click
Dim suit As Double
Dim cardval As Double
Dim num As String
Dim house As String
For i = 0 To 50 Step 2 ' player 1
suit = Math.Floor(list(i) \ 13)
cardval = list(i) Mod 13
If suit = 0 Then house = "Clubs"
elseIf suit = 1 Then house = "Diamonds"
elseIf suit = 2 Then house = "Hearts"
else suit = 3 Then house = "Spades"
End if
If cardval = 0 Then num = "Ace"
If cardval = 1 Then num = "two"
If cardval = 2 Then num = "three"
If cardval = 3 Then num = "four"
If cardval = 4 Then num = "five"
If cardval = 5 Then num = "six"
If cardval = 6 Then num = "seven"
If cardval = 7 Then num = "eight"
If cardval = 8 Then num = "nine"
If cardval = 9 Then num = "ten"
If cardval = 10 Then num = "jack"
If cardval = 11 Then num = "queen"
If cardval = 12 Then num = "king"
ListBox1.Items.Add("num" & " of " & "house")
Next
末次
凡提到C++? – stryku
您正在使用單行'If'語句。爲了添加'Else'或'ElseIf',你必須在同一行輸入所有內容,或者用Visual Basic的_line continuation character_(下劃線'_')分隔它。 –
看看這種邏輯類型的Select Case。 – Blackwood