I need to better understand my if statement

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 

At the moment I get this error

expression is a value and therefore cannot be the purpose of assignment

on lines elem.GetAttribute(" ") . Along with this, he says he expects the statement to end on some of Then s. Can I define specific methods inside if statements to include specific text fields? I am trying to get RadioButtons to send specific text fields, depending on which RadioButton selected.

Any suggestions or resources would be helpful.

+4
source share
2 answers

You need to make sure that each of them has a corresponding answer. If also, you really need to use AndAlso and ElseIf to do what you want. The reason you get the expression "expression is a value and therefore cannot be the target of the assignment" is because you are trying to set the value to GetAttribute due to the lack of an If statement.

See if this works best for you.

 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 
+2
source

There are some syntax errors. You must have an If before each Then , as in the first. I'm not sure what the logic is, but you can use and or or between expressions if you need, or you can insert an If End If block inside another.

0
source

Source: https://habr.com/ru/post/1445686/


All Articles