在VB中怎样做到打开文本文件,象是用windows一样打开?
在编程中excel转换成文本文件后,需要看一下转换的结果,需要在VB中打开文本文件浏览.请帮忙了
[解决办法]
shell "notepad.exe 123.txt"
[解决办法]
先读取到数组中,然后对数组操作:
Public Sub OpenGain(strFile As String)
On Error GoTo errhandler
Dim fso, txtfile, fil1, ts, i, s, data
Dim aa() As String
Dim find As Single
Set fso = CreateObject("Scripting.FileSystemObject")
Set fil1 = fso.GetFile(strFile)
Set ts = fil1.OpenAsTextStream(1)
i = 0
While ts.AtEndOfLine <> True
''''''''''''''''''''''数据入库
' 读取文件的内容。
s = ts.ReadLine
Select Case find
Case 1
aa = Split(s, vbTab)
Case 2
aa = Split(s, " ")
Case 3
aa = Split(s, " ")
Case 4
aa = Split(s, " ")
Case Else
If InStr(1, s, vbTab) <> 0 Then '这里检查TAL or " "
aa = Split(s, vbTab)
find = 1
End If
If InStr(1, s, " ") <> 0 Then '这里检查TAL or " "
aa = Split(s, " ")
find = 2
End If
If InStr(1, s, " ") <> 0 Then '这里检查TAL or " "
aa = Split(s, " ")
find = 3
End If
If InStr(1, s, " ") <> 0 Then '这里检查TAL or " "
aa = Split(s, " ")
find = 4
End If
End Select
FrequencyArr(i) = aa(0)
Sd_Voltage(i) = aa(1)
Sd_Gain(i) = aa(2)
i = i + 1
Wend
OpenTxtData = 1
ts.Close
Exit Sub
errhandler:
If err.Number = 3021 Or err.Number = 62 Then
Exit Sub
End If
MsgBox err.Description
End Sub