tags:

views:

133

answers:

1

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  A: 

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
C-Pound Guru
Nathan, I added some comments to the code sample above. Basically, once you know the file you need to open (filename/path stored in myFileName), the 4 lines of code will get the data (CreateFile, GetFileSize, String, and ReadFile). Copy the code and give it a whirl.
C-Pound Guru
Thanks very very much!!!!!!!!
Nathan Campos