明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1393|回复: 1

请教数组的两个问题

[复制链接]
发表于 2004-11-16 17:07:00 | 显示全部楼层 |阅读模式
1,一个是定义数组mData的时候,如果不指定大小,提示未将对象引用设置到对象的实例
2,把aData中从右边取5个放入mData(k)z中,结果mData为空
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim myStream As FileStream
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim tso As TextStream
Dim tsM As TextStream
'Dim sr As StreamReader = New StreamReader(TextBox1.Text)
ts = fso.CreateTextFile(TextBox2.Text)
tsM = fso.CreateTextFile(TextBox3.Text)
tso = fso.OpenTextFile(TextBox1.Text)
Dim iStr, jStr, kStr As String
'Dim Len As Long
Dim i As Long
Dim k As Integer = 0
Dim aData
Dim mData(100) '如果不设置大小,提示未将对象引用设置到对象的实例 '/如果选择了源文件,
If Not (TextBox1.Text Is Nothing) Then
If Not (TextBox2.Text Is Nothing) Then
aData = Split(tso.ReadAll, vbCrLf)
For i = 39 To 65 Step 13

ts.WriteLine(aData(i))
ts.WriteLine(aData(i + 1))
ts.WriteLine(aData(i + 2))
Dim dlen As Integer
dlen = Len(aData(i))
MsgBox(dlen)
'主要是这里
mData(k) = Microsoft.VisualBasic.Right(aData(i), 5)
mData(k + 1) = Microsoft.VisualBasic.Right(aData(i + 1), 5)
mData(k + 2) = Microsoft.VisualBasic.Right(aData(i + 2), 5)
k = k + 3
MsgBox(mData(k)) ‘空白的
tsM.WriteLine(mData(k))
tsM.WriteLine(mData(k + 1))
tsM.WriteLine(mData(k + 2)) Next
End If
End If
发表于 2004-11-16 18:43:00 | 显示全部楼层
VB.Net的? 这是我以前编过的程序里的函数,你看看吧 Private Sub OpenFile()
'读取函数文件
Dim i As Object
Dim ts As StreamReader
Dim Data As String
Dim allSub As Object
Dim aSub As Collection
Dim FileName As String
For i = 1 To pSubs.Count
pSubs.Remove(1)
Next i
Try
ts = File.OpenText(Directory.GetCurrentDirectory & "\TlsCad.Sub")
allSub = Split(ts.ReadToEnd, vbCrLf)
For i = 0 To UBound(allSub)
Data = allSub(i)
If InStr(Data, "(Sub") = 1 Then
'向函数集合加入新函数
aSub = New Collection
pSubs.Add(aSub, CutStr(Data)(3).sData)
pSubs(pSubs.Count).Add(Data)
Else
pSubs(pSubs.Count).Add(Data)
End If
Next i
Catch ex As Exception
Finally
ts.Close()
End Try
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 23:57 , Processed in 0.192865 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表