Results 1 to 4 of 4

Thread: [RESOLVED] Radio box

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Resolved [RESOLVED] Radio box

    I'm having a bit of a problem in a VB script. The assignment is the following: Get a form filled in with pressing 1 button.
    In this form I can get everything correct, except for the radiobutton. As html sais, the first option is selected by default. Now when you press a button, ghi should get checked.

    The html of this radiobox is the following:
    Code:
    <input type="radio" class="radio" name="c" value="2" checked="checked">abc
    <br>
    <input type="radio" class="radio" name="c" value="3">def
    <br>
    <input type="radio" class="radio" name="c" value="4">ghi
    I saw this topic which sais, and made a bit of my own variant to this:
    Code:
    Public Class Form1
        Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
            Try
                Return DirectCast(WebBrowser1.Document, mshtml.HTMLDocument)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
        'SAME AS THE ABOVE FUNCTION, EXCEPT IT GRABS A WEBFORM. I ASSUME HERE THERE IS ONLY 1 FORM
        'IF YOU WERE DEALING WITH A PAGE WITH MULTIPLE FORMS, SIMPLY USE ITS INDEX (THEY ARE IN AN ARRAY)
        'THIS IS A USEFUL METHOD BECAUSE OFTEN TIMES WHEN MANIPULATING A WEBPAGE, ITS TO GET/SET DATA IN A FORM
        Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
            Try
                If GetCurrentWebDoc.forms.length > 0 Then
                    Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
        'SET THE RADIO BUTTONS CHECKED. NOTICE THEY ARE BOTH CALLED THE SAME THING, BUT THE INDEX IS DIFFERENT.
        Private Sub SetRadioYesChecked()
            If x.Checked Then
                DirectCast(GetCurrentWebForm.item("c", 3), mshtml.HTMLOptionButtonElement).checked = True
            Else
                DirectCast(GetCurrentWebForm.item("c", 4), mshtml.HTMLOptionButtonElement).checked = True
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Select Case True
    
                Case x.Checked, y.Checked : SetRadioYesChecked()
    
            End Select
    
        End Sub
    End Class
    in this project I have 2 radiobuttons, a webbrowser(which has the html), and a button. When the 1st option(in application) is selected and the button is pressed it should select the 2nd option(in browser), if the 2nd option(in application) is selected, and the button gets pressed it should select the 3rd option(in browser). But when I press the button it sais: 'Object reference not set to an instance of an object.' So why did it work at the other application, but why won't it work with mine?

    I'm not asking for a ready script I can copy and paste, just some hints so I can solve it myself. It's a assignment, so I should learn something from it

    I'm using visual studio if this might make a difference.

    Greetings,
    Ray
    Last edited by brue; Jan 2nd, 2012 at 03:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width