Microsoft KB Archive/183631

= INFO: Add a Text File to a VB6 DHTML Page Dynamically =

Article ID: 183631

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



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

</li></ol>


 * 1) Run the code and type the name of a text file in the text box.

<div class="references_section">