如何将数据从VB6导出到HTML TextBox

时间:2013-08-21 12:07:21

标签: html vb6

我想知道如何将数据从VB6文本框导出到HTML文本框?它可以是一个简单的html页面或一个asp页面。

例如,在我的VB6表单上,我有一个名称字段。单击VB6表单上的按钮后,名称字段中的数据将导出到html页面上的文本框中。

感谢大家的帮助和时间阅读本文。

1 个答案:

答案 0 :(得分:0)

要查看此演示的实际操作,并能够了解如何从中获取所需内容:

在文本框上创建一个带有标签的表单,并在表单上粘贴1个命令按钮。不要重命名它们 - 程序需要text1,command1

以下CODE是要复制/粘贴到其中的完整FORM CODE。

从(Project => References)Microsoft Internet Controls,Microsoft HTML Object Library

添加对项目的引用
Option Explicit

Public TargetIE As SHDocVw.InternetExplorer

Private Sub Command1_Click()  ' Send text to first IE-document found
    GetTheIEObjectFromSystem
    SendTextToActiveElementWithSubmitOptionSet (False)
End Sub

Private Sub Form_Load()

    Me.Text1 = "This is a sample text message set and submitted programmatically"  'make text1 multiline in design
    Me.Command1.Caption = "Text to the first IE browser document found"
End Sub

Public Sub GetTheIEObjectFromSystem(Optional ByVal inurl As String = ".") '  "." will be found in ALL browser URLs
   Dim SWs As New SHDocVw.ShellWindows
   Dim IE As SHDocVw.InternetExplorer
   Dim Doc As Object
   For Each IE In SWs
        If TypeOf IE.Document Is HTMLDocument Then ' necessary to avoid Windows Explorer
            If InStr(IE.LocationURL, inurl) > 0 Then
                Set TargetIE = IE
                Exit For
            End If
      End If
   Next
   Set SWs = Nothing
   Set IE = Nothing
End Sub

Private Sub SendTextToActiveElementWithSubmitOptionSet(ByVal bSubmitIt As Boolean)
    Dim TheActiveElement As IHTMLElement
    Set TheActiveElement = TargetIE.Document.activeElement
    If Not TheActiveElement.isTextEdit Then
        MsgBox "Active element is not a text-input system"
    Else
        TheActiveElement.Value = Me.Text1.Text
        Dim directParent As IHTMLElement
        If bSubmitIt Then
            Dim pageForm As IHTMLFormElement
            Set directParent = TheActiveElement.parentElement
            ' find its parent FORM element by checking parent nodes up and up and up until found or BODY
            Do While (UCase(directParent.tagName) <> "FORM" And UCase(directParent.tagName <> "BODY"))
                Set directParent = directParent.parentElement
            Loop
            If UCase(directParent.tagName) = "FORM" Then
                Set pageForm = directParent
                pageForm.submit  'intrinsic Form-element Method
            Else
                MsgBox ("Error: No form unit for submitting the text on this page!")
            End If
        End If
        Set pageForm = Nothing
        Set directParent = Nothing
    End If
    Set TheActiveElement = Nothing
    Set TargetIE = Nothing
End Sub