發問時間: 電腦與網際網路程式設計 · 1 0 年前

請各位程式設計高手~~~解讀小弟的困難=__=”

我有一個VBㄉ程式是要把if then 的程式改寫為select case 的條件敘述

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim figure1, figure2 As Single

figure1 = CInt(TextBox1.Text)

figure2 = CInt(TextBox2.Text)

Dim a As Integer

Select Case a

Case RadioButton1.Checked

a = (figure1) + (figure2)

Case RadioButton2.Checked

a = figure1 - figure2

Case RadioButton3.Checked

a = figure1 * figure2

Case RadioButton4.Checked

a = figure1 / figure2

Label3.Text = a

End Select

End Sub

End Class

我試了很多次我的算式都無法算出來有大大可以跟我說一下我哪裡打錯ㄌ嗎><?

1 個解答

評分
  • 水月
    Lv 6
    1 0 年前
    最佳解答

    你改成如下就可以了。

    Public Class Form1

    Dim a As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim figure1, figure2 As Single

    figure1 = CInt(TextBox1.Text)

    figure2 = CInt(TextBox2.Text)

    Select Case a

    Case 1

    Label3.Text = figure1 + figure2

    Case 2

    Label3.Text = figure1 - figure2

    Case 3

    Label3.Text = figure1 * figure2

    Case 4

    Label3.Text = figure1 / figure2

    End Select

    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

    a = 1

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

    a = 2

    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged

    a = 3

    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged

    a = 4

    End Sub

    End Class

還有問題?馬上發問,尋求解答。