DOCUMENT:Q183631 13-AUG-1998 [vbwin]
TITLE :INFO: Add a Text File to a VB6 DHTML Page Dynamically
PRODUCT :Microsoft Visual Basic for Windows
PROD/VER:
OPER/SYS:WINDOWS
KEYWORDS:
======================================================================
---------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual Basic Professional and Enterprise Editions for
Windows, version 6.0
---------------------------------------------------------------------
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:
1. Start a new Visual Basic project and select DHTML Application.
2. Open DHTMLPage1 under Designers (Project Explorer).
3. Add a TextField to the page, and set its value property to nothing.
4. Add a Button to the page, and set its value property to "Add File."
5. In the Properties window, select DispIHTMLBodyElement, and set its Id
property to "test."
6. 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 & "
File Not Found."
Exit Function
End If
' Convert CR/LF to HTML line break (
) tags.
strLoc = InStr(txt, vbCrLf)
Do While strLoc <> 0
txt = Mid$(txt, 1, (strLoc - 1)) & "
" _
& 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 & "
" & txt
End Function
7. Run the code and type the name of a text file in the text box.
REFERENCES
==========
For more information on DHTML, please refer to the Developing DHTML
Applications topic in the Microsoft Visual Basic product documentation.
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by
Jeremy Earp, Microsoft Corporation
Additional query words: web internet ie explorer kbdsi kbDSupport kbVBp
kbVBp600 kbHTML kbDHTML
======================================================================
Platform : WINDOWS
Issue type : kbinfo
=============================================================================
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION
OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1998.