4
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim PageInput As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
    For Each elem As HtmlElement In PageInput
        If elem.GetAttribute("name") = "wdf_origin" Then
            elem.SetAttribute("value", FromTXT.Text)
        End If
        If elem.GetAttribute("name") = "wdf_destination" Then
            elem.SetAttribute("value", ToTXT.Text)
        End If
        If RadioButton1.Checked = True Then
            elem.GetAttribute("id") = "oneway" Then
            elem.SetAttribute("checked", RadioButton1.Checked) Then
            elem.GetAttribute("id") = "wdfdate1" Then
            elem.SetAttribute("value", DateTimePicker1.Text)
        End If
        If RadioButton2.Checked = True Then
            elem.GetAttribute("id") = "return" Then
            elem.SetAttribute("checked", RadioButton2.Checked) Then
            elem.GetAttribute("id") = "wdfdate1" Then
            elem.SetAttribute("value", DateTimePicker1.Text) Then
            elem.GetAttribute("id") = "wdfdate2" Then
            elem.SetAttribute("value", DateTimePicker2.Text)
        End If
    Next

    Dim PageInput2 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("select")
    For Each elem As HtmlElement In PageInput2
        If elem.GetAttribute("id") = "adults" Then
            elem.SetAttribute("value", AdultsTXT.Text)
        End If
        If elem.GetAttribute("id") = "children" Then
            elem.SetAttribute("value", ChildrenTXT.Text)
        End If
        If elem.GetAttribute("id") = "infants" Then
            elem.SetAttribute("value", InfantsTXT.Text)
        End If
        If RadioButton1.Checked = True Then
            elem.GetAttribute("id") = "wdftime1" Then
            elem.SetAttribute("value", Time1TXT.Text)
        End If
        If RadioButton2.Checked = True Then
            elem.GetAttribute("id") = "wdftime2" Then
            elem.SetAttribute("value", Time2TXT.Text) Then
            elem.GetAttribute("id") = "wdftime1" Then
            elem.SetAttribute("value", Time1TXT.Text)
        End If
    Next
End Sub

目前,我收到此错误

表达式是一个值,因此不能作为赋值的目标

线上elem.GetAttribute(" ")。连同它说,它预计该声明将在某些Thens 上结束。我不能在 if 语句中设置某些方法,以便它们包含某些文本框吗?我试图让RadioButtons发送某些文本框取决于RadioButton选择哪个。

任何建议或资源都会有所帮助。

4

2 回答 2

2

您需要确保每个 Then 都有一个对应的 If,看起来您实际上需要使用AndAlsoandElseIf运算符来执行您想要的操作。您收到“表达式是一个值,因此不能成为赋值目标”错误的原因是因为缺少 If 语句,您正试图将值分配给您的 GetAttribute。

看看这是否更适合您。

Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim PageInput As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
    For Each elem As HtmlElement In PageInput
        If elem.GetAttribute("name") = "wdf_origin" Then
            elem.SetAttribute("value", FromTXT.Text)
        End If
        If elem.GetAttribute("name") = "wdf_destination" Then
            elem.SetAttribute("value", ToTXT.Text)
        End If
        If RadioButton1.Checked then
            If elem.GetAttribute("id") = "oneway" Then
                elem.SetAttribute("checked", CStr(RadioButton1.Checked))
            ElseIf elem.GetAttribute("id") = "wdfdate1" Then
                elem.SetAttribute("value", DateTimePicker1.Text)
            End If
        End If

        If RadioButton2.Checked then
            If elem.GetAttribute("id") = "return" Then
                elem.SetAttribute("checked", RadioButton2.Checked.ToString)
            ElseIf elem.GetAttribute("id") = "wdfdate1" Then
                elem.SetAttribute("value", DateTimePicker1.Text)
            ElseIf elem.GetAttribute("id") = "wdfdate2" Then
                elem.SetAttribute("value", DateTimePicker2.Text)
            End If
        End If

    Next

    Dim PageInput2 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("select")
    For Each elem As HtmlElement In PageInput2
        If elem.GetAttribute("id") = "adults" Then
            elem.SetAttribute("value", AdultsTXT.Text)
        End If
        If elem.GetAttribute("id") = "children" Then
            elem.SetAttribute("value", ChildrenTXT.Text)
        End If
        If elem.GetAttribute("id") = "infants" Then
            elem.SetAttribute("value", InfantsTXT.Text)
        End If
        If RadioButton1.Checked AndAlso elem.GetAttribute("id") = "wdftime1" Then
            elem.SetAttribute("value", Time1TXT.Text)
        End If
        If RadioButton2.Checked Then
            If elem.GetAttribute("id") = "wdftime2" Then
                elem.SetAttribute("value", Time2TXT.Text)
            ElseIf elem.GetAttribute("id") = "wdftime1" Then
                elem.SetAttribute("value", Time1TXT.Text)
            End If
        End If
    Next

End Sub
于 2012-11-13T05:11:02.607 回答
0

有一些语法错误。你应该有一个Ifbefore every Then,就像你在第一个一样。我不确定您所追求的逻辑是什么,但是如果需要,您可以在表达式之间使用andor ,或者您可以将一个块嵌套在另一个块中。orIf End If

于 2012-11-13T04:59:46.380 回答