请教数组的两个问题
1,一个是定义数组mData的时候,如果不指定大小,提示未将对象引用设置到对象的实例<BR>2,把aData中从右边取5个放入mData(k)z中,结果mData为空<BR> Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim myStream As FileStream<BR> Dim fso As New FileSystemObject<BR> Dim ts As TextStream<BR> Dim tso As TextStream<BR> Dim tsM As TextStream<BR> 'Dim sr As StreamReader = New StreamReader(TextBox1.Text)<BR> ts = fso.CreateTextFile(TextBox2.Text)<BR> tsM = fso.CreateTextFile(TextBox3.Text)<BR> tso = fso.OpenTextFile(TextBox1.Text)<BR> Dim iStr, jStr, kStr As String<BR> 'Dim Len As Long<BR> Dim i As Long<BR> Dim k As Integer = 0<BR> Dim aData<BR> <FONT color=#ee1111>Dim mData(100) '如果不设置大小,提示未将对象引用设置到对象的实例</FONT>
'/如果选择了源文件,<BR> If Not (TextBox1.Text Is Nothing) Then<BR> If Not (TextBox2.Text Is Nothing) Then<BR> aData = Split(tso.ReadAll, vbCrLf)<BR> For i = 39 To 65 Step 13<BR> <BR> ts.WriteLine(aData(i))<BR> ts.WriteLine(aData(i + 1))<BR> ts.WriteLine(aData(i + 2))<BR> Dim dlen As Integer<BR> dlen = Len(aData(i))<BR> MsgBox(dlen)
<BR><FONT color=#d54d2b> '主要是这里<BR> mData(k) = Microsoft.VisualBasic.Right(aData(i), 5)<BR> mData(k + 1) = Microsoft.VisualBasic.Right(aData(i + 1), 5)<BR> mData(k + 2) = Microsoft.VisualBasic.Right(aData(i + 2), 5)<BR> k = k + 3<BR> MsgBox(mData(k)) ‘空白的</FONT>
tsM.WriteLine(mData(k))<BR> tsM.WriteLine(mData(k + 1))<BR> tsM.WriteLine(mData(k + 2))
Next<BR> End If<BR> End If<BR> VB.Net的?
这是我以前编过的程序里的函数,你看看吧
Private Sub OpenFile()<BR> '读取函数文件<BR> Dim i As Object<BR> Dim ts As StreamReader<BR> Dim Data As String<BR> Dim allSub As Object<BR> Dim aSub As Collection<BR> Dim FileName As String<BR> For i = 1 To pSubs.Count<BR> pSubs.Remove(1)<BR> Next i<BR> Try<BR> ts = File.OpenText(Directory.GetCurrentDirectory & "\TlsCad.Sub")<BR> allSub = Split(ts.ReadToEnd, vbCrLf)<BR> For i = 0 To UBound(allSub)<BR> Data = allSub(i)<BR> If InStr(Data, "(Sub") = 1 Then<BR> '向函数集合加入新函数<BR> aSub = New Collection<BR> pSubs.Add(aSub, CutStr(Data)(3).sData)<BR> pSubs(pSubs.Count).Add(Data)<BR> Else<BR> pSubs(pSubs.Count).Add(Data)<BR> End If<BR> Next i<BR> Catch ex As Exception<BR> Finally<BR> ts.Close()<BR> End Try<BR> End Sub<BR>
页:
[1]