2014-11-24 181 views
0
Private Sub cmdplay_click() 

    LblGameName.Caption = "Hello! And welcome to Unicorn Adventure Extream! Are you excited?" 
    CmdExit.Caption = "no" 
    CmdPlay.Caption = "yes" 
    If CmdPlay = True Then 
     LblGameName.Caption = "As you should be!! Welcome to Unicopitopia! Will you please enjoy your stay?" 
    ElseIf CmdExit = True Then 
     LblGameName.Caption = "You have angered the unicorn!! She ripped out your heart and devoured it! Bad Luck! Much Blood!" 
    End If 

End Sub 

我不明白爲什麼我的標籤沒有改變,當我按是或否?VBA簡單代碼

+0

在你的cmdPlay子句中,你引用了「lblnamegame」。你的意思是「LblGameName」? – Tmdean 2014-11-24 21:21:13

+0

哦..哎呀!是!謝謝!我已經搞亂了很多,它仍然沒有工作後,我已經修復,雖然 – Sphyrna 2014-11-24 21:23:59

+0

沒有更多的細節很難解決問題。您應該描述表格的外觀,您正在做什麼,您期望發生什麼以及實際發生的情況。否則,我們能做的最好的就是尋找錯別字。 – Tmdean 2014-11-24 21:34:52

回答

1

你的例子有幾個問題。

你會想讓你的按鈕命名並讓它們中的文本保持不變。一個可能是cmdYes,另一個是cmdExit。然後點擊與這些按鈕關聯的點擊事件。爲了實現這一點,只需雙擊表單對象設計器模式中的按鈕,它將調出代碼並生成一個單擊事件。

根據你以前的命名,你肯定有東西被誤稱。

我想你已經命名了類似txtMessage的Lbl,並將其作爲鎖定文本框。您可以設置文本框的背景顏色以匹配UserForm顏色。然後只需設置它的文本以更新您想要實現的任何打印輸出。

Private Sub UserForm_Activate() 

    txtMessage.Text = "Hello! And welcome to Unicorn Adventure Extreme! Are you excited?" 

End Sub 

然後爲您的按鈕分開事件。

Private Sub cmdExit_click() 

    Dim exitMessage As String 

    exitMessage = "You have angered the unicorn!! She ripped out your heart and devoured it! Bad Luck! Much Blood!" 
    txtMessage.Text = exitMessage 

    MsgBox("Game Over, Goodbye") ' or whatever else you want to have happen. 
    Unload Me  'You could unload the form here. 

End Sub 

每個按鈕的單獨事件。

Private Sub cmdYes_click() 

    Dim YesMessage As String 

    YesMessage = "As you should be!! Welcome to Unicopitopia! Will you please enjoy your stay?" 
    txtMessage.Text = YesMessage 

    'Call some other subroutine that launches your game. 
End Sub