[.NET] 關於VB2005全域變數看不大懂

看板Visual_Basic作者 (放羊的橘子)時間17年前 (2009/01/08 11:32), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
Dim rate As Single = 0.05 Dim amout As Integer Dim total As Single = 0 Sub show() If CheckBox1.Checked Then total += 5500 * TextBox1.Text End If If CheckBox2.Checked Then total += 3500 * TextBox2.Text End If total += total * rate TextBox3.Text = total Private Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged If RadioButton1.Checked Then rate = 0.05 Else rate = 0.1 End If show() End Sub我想問大大們 Dim total As Single = 0 如果宣告在sub show()這格副程式裡面...跟宣告在全域變數有什麼差?? 執行局果不ㄧ樣 那如果是rate呢 如果宣告在副程式裡會有什麼差嗎 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.73.185

01/08 15:10, , 1F
那樣Total將沒有累加效果
01/08 15:10, 1F

01/08 21:31, , 2F
rate宣告在副程式裡,RadioButton1_CheckedChanged這裡會
01/08 21:31, 2F

01/08 21:32, , 3F
rate這個變數宣告
01/08 21:32, 3F

01/08 21:32, , 4F
會找不到
01/08 21:32, 4F
文章代碼(AID): #19PNFAQE (Visual_Basic)