作者dx0789111 (神奇小红豆)
看板Visual_Basic
标题[.NET] 请问不同的sub里面的值能够读的到吗?
时间Wed Jun 4 01:44:02 2014
请问各位大大
我目前正在做一个考英文单字的程式
我现在有一个button7 里面会记录回答错误的选项(我是用矩阵a()as boolean来记录)
那我在button3中 却读不到我button7中有回答错的题目a()
请问我该打甚麽才能让button3中可以读的到button7的东西呢>_<?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.42.213.55
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1401817445.A.007.html
1F:→ GoalBased:你的问题描述太不清楚了= = 06/04 08:42
2F:→ dx0789111:我的button7程式码 if combobox2.selectedindex=0 then 06/04 09:45
3F:→ dx0789111:A(1)=true 这样子第一题a(1)就变true if combobox2. 06/04 09:46
4F:→ dx0789111:Selectedindex=1 then a(1)=false 这样子第二题就变成 06/04 09:47
5F:→ dx0789111:False 但是我在button3里面打 for i=1 to 1000 a(i)= 06/04 09:48
6F:→ dx0789111:False then y = y + 1 却都读不到a阵列的值 请问要在 06/04 09:49
7F:→ dx0789111:Button3中打什麽才能让button7里跑出来的阵列a读的到呢 06/04 09:54
8F:→ dx0789111:抱歉 我第三个回的应该是第一题a(1) 不是第二题 06/04 10:00
9F:→ cf1064:看来是要把a()定义在全域变数中 06/04 11:37
10F:→ cf1064:把a() as boolean放在class里,sub外 06/04 11:41
11F:→ dx0789111:我把a放在最外面欸 就是全部程式码的第一行下面a(0to100 06/04 13:14
12F:→ dx0789111:0)as boolean 应该是全域才对 06/04 13:15
13F:→ putumaxally:贴一下程式码吧,全域变数应该是没有问题才对 06/04 14:36
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
14F:→ dx0789111:喔 我懂了 原来a()的初始值是false 我以为读不到 抱歉 06/04 19:08
15F:推 naruto861214: 太感谢cf1064大大了!!!!!!!! 06/08 23:19