[.NET] 陣列為何是空的

看板Visual_Basic作者 (我的笑點真的很低~)時間19年前 (2005/05/31 14:43), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/2 (看更多)
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

192.83.195.244 05/31, , 1F
我不會用NET!!不過我用同樣的方式寫在VB
192.83.195.244 05/31, 1F

192.83.195.244 05/31, , 2F
會出錯咧!!不知道是不是相同的道理
192.83.195.244 05/31, 2F

192.83.195.244 05/31, , 3F
陣列好像不行這樣子宣告,裡面一定要常數運算式
192.83.195.244 05/31, 3F

192.83.195.244 05/31, , 4F
或著是數字吧!!等會VB.NET的人再解答吧
192.83.195.244 05/31, 4F
文章代碼(AID): #12d0UWQl (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #12d0UWQl (Visual_Basic)