VB學習心得8.整合類別庫

摘要:VB學習心得8.整合類別庫

參考書籍:Visual Basic 2008程式設計學習教本

 

這是運用14-24頁,取得特定範圍的亂數所做的簡易猜數字
用Label承接答案,把Label背景設為黑色,也可以試著用丟進副程式的方法,我用的這個是最簡易的方法,如果有別的方法麻煩說一下,謝謝

Public Class Form1
    Public rdm As New Random
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not IsNumeric(TextBox1.Text) Or Not IsNumeric(TextBox2.Text) Then
            Exit Sub
        End If
        Dim a As Integer = CInt(TextBox1.Text)
        Dim b As Integer = CInt(TextBox2.Text)
        Dim num As Integer = rdm.Next(a, b)
        Label1.Text = num
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim c As Integer = CInt(TextBox3.Text)
        Dim rresult As Integer = CInt(Label1.Text)
        If (c > rresult) Then
            MsgBox("比正確數字大")
        ElseIf (c < rresult) Then
            MsgBox("比正確數字小")
        ElseIf (c = rresult) Then
            MsgBox("正確數字")
        End If
    End Sub
End Class