[.NET] 請問不同的sub裡面的值能夠讀的到嗎?

看板Visual_Basic作者 (神奇小紅豆)時間11年前 (2014/06/04 01:44), 11年前編輯推噓1(1014)
留言15則, 5人參與, 最新討論串1/1
請問各位大大 我目前正在做一個考英文單字的程式 我現在有一個button7 裡面會記錄回答錯誤的選項(我是用矩陣a()as boolean來記錄) 那我在button3中 卻讀不到我button7中有回答錯的題目a() 請問我該打甚麼才能讓button3中可以讀的到button7的東西呢>_<? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.42.213.55 ※ 文章網址: http://www.ptt.cc/bbs/Visual_Basic/M.1401817445.A.007.html

06/04 08:42, , 1F
你的問題描述太不清楚了= =
06/04 08:42, 1F

06/04 09:45, , 2F
我的button7程式碼 if combobox2.selectedindex=0 then
06/04 09:45, 2F

06/04 09:46, , 3F
A(1)=true 這樣子第一題a(1)就變true if combobox2.
06/04 09:46, 3F

06/04 09:47, , 4F
Selectedindex=1 then a(1)=false 這樣子第二題就變成
06/04 09:47, 4F

06/04 09:48, , 5F
False 但是我在button3裡面打 for i=1 to 1000 a(i)=
06/04 09:48, 5F

06/04 09:49, , 6F
False then y = y + 1 卻都讀不到a陣列的值 請問要在
06/04 09:49, 6F

06/04 09:54, , 7F
Button3中打什麼才能讓button7裡跑出來的陣列a讀的到呢
06/04 09:54, 7F

06/04 10:00, , 8F
抱歉 我第三個回的應該是第一題a(1) 不是第二題
06/04 10:00, 8F

06/04 11:37, , 9F
看來是要把a()定義在全域變數中
06/04 11:37, 9F

06/04 11:41, , 10F
把a() as boolean放在class裡,sub外
06/04 11:41, 10F

06/04 13:14, , 11F
我把a放在最外面欸 就是全部程式碼的第一行下面a(0to100
06/04 13:14, 11F

06/04 13:15, , 12F
0)as boolean 應該是全域才對
06/04 13:15, 12F

06/04 14:36, , 13F
貼一下程式碼吧,全域變數應該是沒有問題才對
06/04 14:36, 13F
Public Class Form1 Dim A(0 To 1000) As Boolean Public Property DataSource As Object Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click Dim k, s As Integer 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 'AABCCBCAAB喔>_< '0012212001 k = ComboBox1.SelectedIndex If ComboBox2.SelectedIndex = 0 Then A(10 * k + 1) = True 'true If ComboBox2.SelectedIndex = 1 Then A(10 * k + 1) = False If ComboBox2.SelectedIndex = 2 Then A(10 * k + 1) = False If ComboBox3.SelectedIndex = 0 Then A(10 * k + 2) = True 'true If ComboBox3.SelectedIndex = 1 Then A(10 * k + 2) = False If ComboBox3.SelectedIndex = 2 Then A(10 * k + 2) = False If ComboBox4.SelectedIndex = 1 Then A(10 * k + 3) = True 'true If ComboBox4.SelectedIndex = 0 Then A(10 * k + 3) = False If ComboBox4.SelectedIndex = 2 Then A(10 * k + 3) = False If ComboBox5.SelectedIndex = 2 Then A(10 * k + 4) = True 'true If ComboBox5.SelectedIndex = 0 Then A(10 * k + 4) = False If ComboBox5.SelectedIndex = 1 Then A(10 * k + 4) = False If ComboBox6.SelectedIndex = 2 Then A(10 * k + 5) = True 'true If ComboBox6.SelectedIndex = 0 Then A(10 * k + 5) = False If ComboBox6.SelectedIndex = 1 Then A(10 * k + 5) = False If ComboBox7.SelectedIndex = 1 Then A(10 * k + 6) = True 'true If ComboBox7.SelectedIndex = 0 Then A(10 * k + 6) = False If ComboBox7.SelectedIndex = 2 Then A(10 * k + 6) = False If ComboBox8.SelectedIndex = 2 Then A(10 * k + 7) = True 'true If ComboBox8.SelectedIndex = 0 Then A(10 * k + 7) = False If ComboBox8.SelectedIndex = 1 Then A(10 * k + 7) = False If ComboBox9.SelectedIndex = 0 Then A(10 * k + 8) = True 'true If ComboBox9.SelectedIndex = 1 Then A(10 * k + 8) = False If ComboBox9.SelectedIndex = 2 Then A(10 * k + 8) = False If ComboBox10.SelectedIndex = 0 Then A(10 * k + 9) = True 'true If ComboBox10.SelectedIndex = 1 Then A(10 * k + 9) = False If ComboBox10.SelectedIndex = 2 Then A(10 * k + 9) = False If ComboBox11.SelectedIndex = 1 Then A(10 * k + 10) = True 'true If ComboBox11.SelectedIndex = 0 Then A(10 * k + 10) = False If ComboBox11.SelectedIndex = 2 Then A(10 * k + 10) = False 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' For i = 1 To 1000 If A(i) = True Then s = s + 1 Next Label14.Text = "目前得分" & s & "/1000" If s = 1000 Then MsgBox("你好棒喔>_<") Label13.Text = "達成目標了~好厲害喔~" End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim x As Integer 'xxxxxx有無錯誤單字檢查xxxxxx For i = 1 To 1000 If A(i) = 0 Then x = x + 1 If A(i) = True Then x = x + 1 Next i If x = 1000 Then MsgBox("你目前沒有錯誤單字喔") Exit Sub End If 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx If A(1) = False Then Label1.Text = Label1.Text & vbCrLf & "1.a (an):一 個" If A(2) = False Then Label1.Text = Label1.Text & vbCrLf & "2.a few:一 些" Label1.Visible = True Button1.Visible = False Button2.Visible = False Button3.Visible = False Button8.Visible = True End Sub End Class ※ 編輯: dx0789111 (114.42.213.55), 06/04/2014 16:07:47

06/04 19:08, , 14F
喔 我懂了 原來a()的初始值是false 我以為讀不到 抱歉
06/04 19:08, 14F

06/08 23:19, , 15F
太感謝cf1064大大了!!!!!!!!
06/08 23:19, 15F
文章代碼(AID): #1JZWbb07 (Visual_Basic)
文章代碼(AID): #1JZWbb07 (Visual_Basic)