vb输入输出的简单问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 14:12:40
我想要把c:\temp.txt中的字符保存到变量abc中去,这在c语言中很容易实现,但在vb中中不知如何实现,请高手帮忙,谢谢

dim abc as string
dim x as string
abc=""
x=""
open "c:\temp.txt" for input as #1
do while not eof(1)
input #1,x
abc=abc & x & " " '这里的空格根据需要取舍!!
loop

一眼的啊。就是打开文件,读文件。

Dim abc As String
Open "c:\temp.txt" For Input As #1
Do While Not EOF(1) '逐行读取
Input #1, abc
Debug.Print abc
Loop
Close #1

一次将文本文件的全文读取到变量中

Private Sub Command1_Click()
Dim abc As String
abc = OpenF("c:\temp.txt")
End Sub

Public Function OpenF(F As String) As String
'返回文本文件的全文
Dim H As Long, S As Long, B() As Byte

On Error GoTo Cuo
S = FileLen(F)
ReDim B(1 To S)

H = FreeFile
Open F For Binary As #H
Get #H, , B
Close H

OpenF = B
OpenF = StrConv(OpenF, vbUnicode)
Exit Function
Cuo:<