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

发布于 2024-07-27 22:54:39 字数 244 浏览 5 评论 0原文

我正在尝试学习如何使用公共对话框(Visual Basic 6 中的命令对话框)打开文件,并将其内容放入文本字​​段中。

我需要仅使用公共对话框,因为我正在尝试在eVB中做同样的应用程序,而eVB不支持这样的东西,这使得VB6开发更加简单:

Dim objFSO As New Scripting.FileSystemObject
Dim objStream As Scripting.TextStream

I'm trying to learn how to open a file, and put its contents in a TextField, using a Common Dialog, only a command dialog in Visual Basic 6.

I need this using a only a common dialog, because I'm trying to do the same application in eVB, and eVB does not support things like these, that makes the VB6 development more simple:

Dim objFSO As New Scripting.FileSystemObject
Dim objStream As Scripting.TextStream

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生路 2024-08-03 22:54:39

查看通过 WinCE API 访问 eVB 文件。 本文中的示例代码(假设您已经从通用对话框中获取了文件名 (myFileName)):

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

Check out eVB File Access through the WinCE API. Sample code from the article (assuming you already got your filename (myFileName) from the Common Dialog):

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文