1

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

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

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

4

1 回答 1

0

要查看此演示,并能够跟进并学习如何从中获取您需要的内容:

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

以下代码是复制/粘贴到其中的完整表单代码。

从 (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
于 2013-08-22T07:16:27.690 回答