0

我正在编写一个程序,让用户选择他们的星座和另一个人的星座。一旦进入,我想使用标志来衡量它们的兼容性,其结果分为 3 类。我的程序可以让用户选择两个标志,程序可以将它们吐出来告诉用户他们选择了什么(我不需要这个消息框,我只是为了检查我的代码是在职的)。我遇到问题的部分是制作“兼容性”功能并使用选择案例,我不知道是否需要声明新变量,或者如果我将它们公开它们是否会起作用。显然我的代码不起作用,或者我不会寻求帮助。对于选择的情况,我目前只有一个白羊座,但需要对所有 12 个星座进行处理。

这是新代码:

公开课形式1

Public Sub btnBegin_Click(sender As Object, e As EventArgs) Handles btnBegin.Click
    lblMySign.Visible = True
    lblYourSign.Visible = True
    cbMySign.Visible = True
    cbYourSign.Visible = True
    btnBegin.Visible = False

    Dim MySign As String
    Dim YourSign As String

    MySign = cbMySign.Text
    YourSign = cbYourSign.Text

    Call Compatibility(Me.cbMySign.Text, Me.cbYourSign.Text)
End Sub

Public Sub cbMySign_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbMySign.SelectedIndexChanged

End Sub

Public Sub cbYourSign_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbYourSign.SelectedIndexChanged
    'Dim MySign As String
    'Dim YourSign As String

    'MySign = cbMySign.Text
    'YourSign = cbYourSign.Text


End Sub
Function Compatibility(cbMySign As String, cbYourSign As String) As String
    Dim strCompat As String

    Select Case cbMySign
        Case "Aries"
            Select Case cbYourSign
                Case "Taurus", "Cancer", "Virgo", "Pisces"
                    strCompat = "NC"
                Case "Gemini", "Libra", "Scorpio", "Capricorn", "Aquarius"
                    strCompat = "N"
                Case "Aries", "Leo", "Sagittarius"
                    strCompat = "C"
            End Select
    End Select

    If strCompat = "NC" Then
        MsgBox("You're not compatible")
    ElseIf strCompat = "N" Then
        MsgBox("You're neutral")
    Else
        MsgBox("You're compatible")
    End If
End Function

结束类

4

1 回答 1

0

Updated 3:10 PM Sorry about the late reply, need to attend a series of meetings...

I tried to run your whole code, copy-pasted it and run, it works perfectly...

I tried:

My Sign = Aries Your Sign = Virgo

Result: "You're not compatible"

My question is, when you clicked the BtnBegin when will it become visible again?

lblMySign.Visible = True 
lblYourSign.Visible = True 
cbMySign.Visible = True 
cbYourSign.Visible = True 
btnBegin.Visible = False '--- here it is?

I think you need to reset this one upon clicking cbMySign or cbYourSign

-Strider (Yahoo! Answers)

于 2014-02-19T07:20:19.407 回答