作者googookevin (我的笑點真的很低~)
看板Visual_Basic
標題[.NET] 陣列為何是空的
時間Tue May 31 14:46:15 2005
Dim no As Integer = 0
Dim num As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Label5.Visible = False
num = Val(InputBox("請輸入學生數目", ""))
Label1.Text = "請輸入" & num & "筆學生姓名和成績!"
Label2.Text = "第" & no + 1 & "筆"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s_score(num - 1) As Single
Dim s_name(num - 1) As String
Dim i As Integer
Dim tt As String
Dim ss As String
s_name(no) = TextBox1.Text
s_score(no) = TextBox2.Text
no += 1
Label2.Text = "第" & no + 1 & "筆"
Label5.Text = "編號 姓名 分數" + vbNewLine
TextBox1.Text = ""
TextBox2.Text = ""
If no = num Then
Label5.Visible = True
For i = 0 To num - 1 Step 1
Label5.Text &= i & " " & s_name(i) & " " & "
" & s_score(i) & vbNewLine
Next i
End If
End Sub
這程式是希望最後能列出所有資料~但為何最後都只能顯示出最後一筆輸入的資料
呢?其他前面輸入的資料都會成為0~好奇怪喔!
是不是存取陣列出了問題阿?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.239.213
1F:推 BearWu:我不會用NET!!不過我用同樣的方式寫在VB 192.83.195.244 05/31
2F:→ BearWu:會出錯咧!!不知道是不是相同的道理 192.83.195.244 05/31
3F:→ BearWu:陣列好像不行這樣子宣告,裡面一定要常數運算式 192.83.195.244 05/31
4F:→ BearWu:或著是數字吧!!等會VB.NET的人再解答吧 192.83.195.244 05/31