The information in this article applies to:
Microsoft Visual Basic Professional Edition for Windows 6.0
Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q183631
SUMMARY
This article demonstrates how to create a simple DHTML application in Visual Basic 6.0 and add a text file from the user's hard drive to the end of the page.
MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
The following sample code takes a text file from the local hard drive on the client and appends it to the current DHTML page:
Start a new Visual Basic project and select DHTML Application.
Open DHTMLPage1 under Designers (Project Explorer).
Add a TextField to the page, and set its value property to nothing.
Add a Button to the page, and set its value property to "Add File."
In the Properties window, select DispIHTMLBodyElement, and set its Id property to "test."
For the Button1_OnClick event, add the following code:
Private Function Button1_onclick() As Boolean
Dim f As Integer ' File Handle
Dim txt As String ' Holds text of file for
' processing
Dim strLoc As Long ' Holds current location for
' INSTR
f = FreeFile
If Len(Dir$(TextField1.Value)) > 0 Then
Open TextField1.Value For Input As #f
txt = Input$(LOF(f), f)
Close #f
else
test.innerHTML = test.innerHTML & "<BR><BR>File Not Found."
Exit Function
End If
' Convert CR/LF to HTML line break (<BR>) tags.
strLoc = InStr(txt, vbCrLf)
Do While strLoc <> 0
txt = Mid$(txt, 1, (strLoc - 1)) & "<BR>" _
& Mid$(txt, strLoc + 2)
strLoc = InStr(strLoc + 1, txt, vbCrLf)
Loop
' Add Contents of Text file to end of DHTML page.
test.innerHTML = test.innerHTML & "<BR><BR>" & txt
End Function
Run the code and type the name of a text file in the text box.
|