File io 如何打开文件并将其内容放入文本字段?

File io 如何打开文件并将其内容放入文本字段?,file-io,vb6,evb,File Io,Vb6,Evb,我试图学习如何打开一个文件,并将其内容放在一个文本字段中,使用一个通用对话框,仅使用VisualBasic6中的命令对话框 我只需要使用一个公共对话框就可以实现这一点,因为我正在尝试在eVB中执行相同的应用程序,而eVB不支持类似的操作,这使得VB6开发更加简单: Dim objFSO As New Scripting.FileSystemObject Dim objStream As Scripting.TextStream 退房。文章中的示例代码(假设您已经从公共对话框中获得了文件名(my

我试图学习如何打开一个文件,并将其内容放在一个文本字段中,使用一个通用对话框,仅使用VisualBasic6中的命令对话框

我只需要使用一个公共对话框就可以实现这一点,因为我正在尝试在eVB中执行相同的应用程序,而eVB不支持类似的操作,这使得VB6开发更加简单:

Dim objFSO As New Scripting.FileSystemObject
Dim objStream As Scripting.TextStream
退房。文章中的示例代码(假设您已经从公共对话框中获得了文件名(myFileName)):


“…并将其内容放入文本字段…”-谁的内容?这是鲍勃·多尔的文件,你把他的内容放在文本字段里?性别歧视!打电话给律师Nathan我在上面的代码示例中添加了一些注释。基本上,一旦知道需要打开的文件(myFileName中存储的文件名/路径),4行代码将获得数据(CreateFile、GetFileSize、String和ReadFile)。复制代码并尝试一下。
Public Const GENERIC_READ As Int32 = &H80000000 
Public Const OPEN_EXISTING As Int32 = 3

' CreateFile will open a file handle (hFile) to the file in the myFileName variable
hFile = CreateFile(myFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)

lFileSize = GetFileSize(hFile, 0)

' String(lFileSize, 0) will prepare the sContents string variable 
' to hold the contents of the file
sContents = String(lFileSize, 0)

' ReadFile actually reads the file we opened earlier and puts the contents
' into the sContents variable
ReadFile hFile, sContents, lFileSize, dwRead, 0

' Put the contents we read into the textbox
myTextBox.Text = sContents