Last active
August 27, 2015 20:58
-
-
Save ochilab/ea45639d7a66b0fea019 to your computer and use it in GitHub Desktop.
VBAにて正誤判定する処理のサンプル(講義資料)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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