【问题标题】:How to open a file and put its contents In a TextField?如何打开文件并将其内容放入 TextField?
【发布时间】:2012-05-08 21:55:54
【问题描述】:

我正在尝试学习如何打开文件,并将其内容放入 TextField,使用通用对话框,在 Visual Basic 6 中只有一个命令对话框。

我只需要一个通用对话框,因为我试图在 eVB 中做同样的应用程序,而 eVB 不支持这样的事情,这使得 VB6 开发更加简单:

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

【问题讨论】:

  • "...并将 他的 内容放入 TextField..." - 谁的内容?这是 Bob Dole 的文件吗?您将他的内容放在文本字段中?
  • 性别歧视!打电话给律师。

标签: file-io vb6 evb


【解决方案1】:

查看eVB File Access through the WinCE API。文章中的示例代码(假设您已经从通用对话框中获得了文件名 (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

【讨论】:

  • Nathan,我在上面的代码示例中添加了一些 cmets。基本上,一旦您知道需要打开的文件(存储在 myFileName 中的文件名/路径),4 行代码将获取数据(CreateFile、GetFileSize、String 和 ReadFile)。复制代码并试一试。
猜你喜欢
  • 2020-03-24
  • 1970-01-01
  • 2023-02-23
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 1970-01-01
  • 2015-09-21
  • 1970-01-01
相关资源
最近更新 更多