作者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