Skip to content

Instantly share code, notes, and snippets.

@ochilab ochilab/judgeSample.vba
Last active Aug 27, 2015

Embed
What would you like to do?
VBAにて正誤判定する処理のサンプル(講義資料)
Private Sub CommandButton1_Click()
'正誤判定
Dim judge As Integer
'解答番号
Dim answer As Integer
'正解番号
Dim collect As Integer
With Worksheets("Sheet1")
collect = .Cells(MyNum + 1, 6)
End With
'どの選択肢が押されたか?
If OptionButton1.Value = True Then
answer = 1
ElseIf OptionButton2.Value = True Then
answer = 2
ElseIf OptionButton3.Value = True Then
answer = 3
ElseIf OptionButton4.Value = True Then
answer = 4
End If
'正解と比較
If collect = answer Then
judge = 1
Else
judge = 0
End If
'正解なら「正解」と表示
If judge = 1 Then
MsgBox "正解"
Else
MsgBox "残念"
End If
MyNum = MyNum + 1
showProblem (MyNum)
End Sub
UserForm2でのプロパティ設定
Dim MyID As String
Public Property Let id(v_id As String)
MyID = v_id
End Property
Public Property Get id() As String
id = MyID
End Property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.