作者jonsen (小志)
看板Visual_Basic
標題[VB2008] 如何正確呼叫,寫在類別庫的陣列
時間Sun Aug 2 14:32:15 2009
想請問大家一個問題
我在類別庫中寫了一個陣列,類別庫的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
1F:推 fumizuki:為什麼math沒看到fname這個成員@@ 08/02 14:36
2F:推 fumizuki:而且fname也指定為Nothing 要如何存取? 08/02 14:36
3F:→ jonsen:對不起我漏貼了 08/02 14:36
※ 編輯: jonsen 來自: 140.114.43.86 (08/02 14:38)
4F:→ jonsen:nothing是後來才加的,我是想要先初始化陣列 08/02 14:41
5F:→ jonsen:不過就算是把它拿掉 還是會出現一樣的問題@@ 08/02 14:41
※ 編輯: jonsen 來自: 140.114.43.86 (08/02 14:44)
6F:→ fumizuki:重點是重點沒有初始化@@ 08/02 14:49
7F:→ fumizuki: 陣列 08/02 14:50
8F:→ jonsen:恩,原來是這樣,謝謝您:),不過我拿掉nothing,還是會出現 08/02 14:55
9F:→ jonsen:一樣的問題 08/02 14:56
10F:→ fumizuki:拿不拿都一樣是nothing... 08/02 17:14