[VB2008] 如何正確呼叫,寫在類別庫的陣列

看板Visual_Basic作者 (小志)時間16年前 (2009/08/02 14:32), 編輯推噓2(208)
留言10則, 2人參與, 最新討論串1/1
想請問大家一個問題 我在類別庫中寫了一個陣列,類別庫的namespace為studyhost,程式碼如下: Public Class math Private _buffername as String Private _idx as integer Private _xaxis() As Single Private _yaxis() As Single Private _fname() as string Property buffername() As String Get Return _buffername End Get Set(ByVal value As String) value = _buffername End Set End Property Property fname() As String() Get Return _fname End Get Set(ByVal value() As String) value = _fname End Set End Property Property idx() As Integer Get Return _idx End Get Set(ByVal value As Integer) If IsNumeric(value) = False Then Exit Property End If value = _idx End Set End Property Property xaxis() As Single() Get Return _xaxis End Get Set(ByVal value As Single()) value = _xaxis End Set End Property Property yaxis() As Single() Get Return _yaxis End Get Set(ByVal value As Single()) value = _yaxis End Set End Property 而主程式如下 Public Class Form1 Dim buffer As String = "" Dim mytool As New studyhost.math Sub open() mytool.idx = 0 Me.OpenFileDialog1.Filter = "文字檔(*.txt)|*.txt" If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then For Each record As String In Me.OpenFileDialog1.FileNames mytool.fname(mytool.idx) = record ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^在這邊出現"使用new關鍵字建立 物件值型個體" mytool.idx = mytool.idx + 1 mytool.buffername = mytool.buffername +_ mytool.fname(mytool.idx) & vbNewLine Next Me.TextBox1.Text = mytool.buffername End If 曾經也試過加入redim 語法去修正這個錯誤,不過還是無法正確的解決問題,希望大家 可以提醒一下,要怎樣去修正,謝謝!! -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.43.86

08/02 14:36, , 1F
為什麼math沒看到fname這個成員@@
08/02 14:36, 1F

08/02 14:36, , 2F
而且fname也指定為Nothing 要如何存取?
08/02 14:36, 2F

08/02 14:36, , 3F
對不起我漏貼了
08/02 14:36, 3F
※ 編輯: jonsen 來自: 140.114.43.86 (08/02 14:38)

08/02 14:41, , 4F
nothing是後來才加的,我是想要先初始化陣列
08/02 14:41, 4F

08/02 14:41, , 5F
不過就算是把它拿掉 還是會出現一樣的問題@@
08/02 14:41, 5F
※ 編輯: jonsen 來自: 140.114.43.86 (08/02 14:44)

08/02 14:49, , 6F
重點是重點沒有初始化@@
08/02 14:49, 6F

08/02 14:50, , 7F
陣列
08/02 14:50, 7F

08/02 14:55, , 8F
恩,原來是這樣,謝謝您:),不過我拿掉nothing,還是會出現
08/02 14:55, 8F

08/02 14:56, , 9F
一樣的問題
08/02 14:56, 9F

08/02 17:14, , 10F
拿不拿都一樣是nothing...
08/02 17:14, 10F
文章代碼(AID): #1ATJBodK (Visual_Basic)