How to open a file and put its contents In a TextField?

301 Views Asked by At

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
1

There are 1 best solutions below

1
On BEST ANSWER

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