Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2006, 07:56 AM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to automate selection of radio button using vb


Imports mshtml
Imports SHDocVw
Imports Automation
Imports InternetMacros



Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(552, 341)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim wbbrowser As New SHDocVw.InternetExplorer

        wbbrowser.Visible = True
        wbbrowser.Navigate("http://elf.meterpower.co.uk/login.asp", Nothing, Nothing, Nothing, Nothing)
        Do
        Loop Until Not wbbrowser.Busy
        LoginIntoSite(wbbrowser)
        Dim iim As New InternetMacros.Apps


    End Sub
    Public Sub LoginIntoSite(ByRef wbBrowser As SHDocVw.InternetExplorer)

        Dim HTMLDoc As mshtml.HTMLDocument

        Do
        Loop Until Not wbBrowser.Busy

        HTMLDoc = wbBrowser.Document

        Dim iHTMLCol As IHTMLElementCollection
        Dim iHTMLEle As IHTMLElement
        Dim str, groupid, password, userid As String


        iHTMLCol = HTMLDoc.getElementsByTagName("input")

        'Type Groupid
        For Each iHTMLEle In iHTMLCol
            If Not iHTMLEle.getAttribute("name") Is Nothing Then
                str = iHTMLEle.getAttribute("name").ToString
                If str = "groupid" Then
                    iHTMLEle.setAttribute("value", "TGPL/Orange")
                    Exit For
                End If
            End If
        Next

        ' Type the userid in the password text box
        For Each iHTMLEle In iHTMLCol
            If Not iHTMLEle.getAttribute("name") Is Nothing Then
                str = iHTMLEle.getAttribute("name").ToString
                If str = "userid" Then
                    iHTMLEle.setAttribute("value", "Orange")
                    Exit For
                End If
            End If
        Next
        'Type the password in the password textbox provided
        For Each iHTMLEle In iHTMLCol
            If Not iHTMLEle.getAttribute("name") Is Nothing Then
                str = iHTMLEle.getAttribute("name").ToString
                If str = "password" Then
                    iHTMLEle.setAttribute("value", "Mobile")
                    Exit For
                End If
            End If
        Next

        ' Press the submit button
        For Each iHTMLEle In iHTMLCol
            If Not iHTMLEle.getAttribute("name") Is Nothing Then
                str = iHTMLEle.getAttribute("name").ToString
                If str = "Enter" Then
                    'If iHTMLEle.outerHTML = "<INPUT type=Submit" & _
                    '" height=21 width=26 " & _
                    ' "border = 0 > " Then
                    iHTMLEle.click()
                    Exit For
                End If
            End If
        Next

        Do
        Loop Until Not wbBrowser.Busy



    End Sub
    Public Sub OpenDownloadDataPage(ByRef wbBrowser As SHDocVw.InternetExplorer)

        Dim HTMLDoc1 As mshtml.HTMLDocument
        Dim iHtmlCol As IHTMLElementCollection
        Dim iHtmlEle As IHTMLElement

        Do
        Loop Until Not wbBrowser.Busy

        HTMLDoc1 = wbBrowser.Document
        iHtmlCol = HTMLDoc1.getElementsByTagName("a")

        ' Press the anchor tag to open DownloadData page
        For Each iHtmlEle In iHtmlCol
            If Not iHtmlEle.outerText Is Nothing Then
                If iHtmlEle.outerText.ToUpper = "Download Data".ToUpper Then
                    iHtmlEle.click()
                    Exit For
                End If
            End If
        Next

        Do
        Loop Until Not wbBrowser.Busy
    End Sub


End Class


 
Old September 27th, 2006, 08:28 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What are you trying to achieve? Where is the problematic code? What isnt the application doing?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 27th, 2006, 09:08 AM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

boss,
I don't want to hire anybody.
If u can help then u can or else I can find a solution myself


 
Old September 27th, 2006, 09:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

@satish...

What Doug said is just a little joke on his signature... but he is asking valid question about your problem... what we are supossed to do with your code?? you have a problem with radio button (that works by itself, usually you just throw then on the form) but we have no info of what are we looking for...

please when you have a problem be a lot more specific and only put code if we can do something with it...



HTH

Gonzalo
 
Old September 27th, 2006, 03:15 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Wow satish: a little testy, aren't you?

Usually, in communicating a question, there is a modicum of elements, such a premise, ("how do I", "can I", "have you ever"), a verb ({in bold} "How do I open..."), a nouun ({in bold} "How do I open a file...").

You should give up being so testy when you fail to communicate, and then curry a question appropriately seeking clarification. Though your subject line at least sets the premise, being a little more forthcoming is highly recommended—by me and Gonzalo at the minimum, it appears.
 
Old September 28th, 2006, 04:04 AM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imports mshtml
Imports SHDocVw



Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(552, 341)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wbbrowser As New SHDocVw.InternetExplorer

wbbrowser.Visible = True
wbbrowser.Navigate("http://elf.meterpower.co.uk/login.asp", Nothing, Nothing, Nothing, Nothing)
Do
Loop Until Not wbbrowser.Busy
LoginIntoSite(wbbrowser)
OpenDownloadDataPage(wbbrowser)
Dim iim As New InternetMacros.Apps


End Sub
Public Sub LoginIntoSite(ByRef wbBrowser As SHDocVw.InternetExplorer)

Dim HTMLDoc As mshtml.HTMLDocument

Do
Loop Until Not wbBrowser.Busy

HTMLDoc = wbBrowser.Document

Dim iHTMLCol As IHTMLElementCollection
Dim iHTMLEle As IHTMLElement
Dim str, groupid, password, userid As String


iHTMLCol = HTMLDoc.getElementsByTagName("input")

'Type Groupid
For Each iHTMLEle In iHTMLCol
If Not iHTMLEle.getAttribute("name") Is Nothing Then
str = iHTMLEle.getAttribute("name").ToString
If str = "groupid" Then
iHTMLEle.setAttribute("value", "")
Exit For
End If
End If
Next

' Type the userid in the password text box
For Each iHTMLEle In iHTMLCol
If Not iHTMLEle.getAttribute("name") Is Nothing Then
str = iHTMLEle.getAttribute("name").ToString
If str = "userid" Then
iHTMLEle.setAttribute("value", "")
Exit For
End If
End If
Next
'Type the password in the password textbox provided
For Each iHTMLEle In iHTMLCol
If Not iHTMLEle.getAttribute("name") Is Nothing Then
str = iHTMLEle.getAttribute("name").ToString
If str = "password" Then
iHTMLEle.setAttribute("value", "")
Exit For
End If
End If
Next

' Press the submit button
For Each iHTMLEle In iHTMLCol
If Not iHTMLEle.getAttribute("name") Is Nothing Then
str = iHTMLEle.getAttribute("name").ToString
If str = "Enter" Then
' If iHTMLEle.outerHTML = "<=href" & _
' " height=21 width=26 " & _
'"border = 0 > " Then
iHTMLEle.click()
Exit For
End If
End If
Next

Do
Loop Until Not wbBrowser.Busy



End Sub
Public Sub OpenDownloadDataPage(ByRef wbBrowser As SHDocVw.InternetExplorer)

Dim HTMLDoc1 As mshtml.HTMLDocument
Dim iHtmlCol As IHTMLElementCollection
Dim iHtmlEle As IHTMLElement
Dim iHtmlIn As mshtml.HTMLInputElement
Dim str1 As String


Do
Loop Until Not wbBrowser.Busy

HTMLDoc1 = wbBrowser.Document
iHtmlCol = HTMLDoc1.getElementsByTagName("a")

' Press the anchor tag to open DownloadData page
For Each iHtmlEle In iHtmlCol
If Not iHtmlEle.outerText Is Nothing Then
If iHtmlEle.outerText.ToLower = "Download Data".ToLower Then
iHtmlEle.click()
Exit For
End If
End If
Next
'Select Radio Buttons . I am using this code to select radio button
'by name demcons and value is kwh. The html code for radio button is as
'follows<input type="radio" name="demcons" value="KWH" class="datainput"></td>)

For Each iHtmlEle In iHtmlCol
If Not iHtmlEle.getAttribute("name") Is Nothing Then
str1 = iHtmlEle.getAttribute("name").ToString
If str1 = "demcons" Then

If iHtmlEle.outerHTML = "<input type=radio" & _
" name=demcons value=kwh" & _
"> " Then
iHtmlEle.click()



Exit For
End If

End If

End If
Next

' iHtmlCol = HTMLDoc1.getElementsByTagName("input")
' For Each iHtmlIn In iHtmlCol
' If iHtmlIn.name = "demcons" And iHtmlIn.value = "KWH" Then
'iHtmlIn.select()
' End If

' Next

Do
Loop Until Not wbBrowser.Busy

End Sub



End Class


Anyone out there to help me .



Satishk



 
Old September 28th, 2006, 07:20 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Look, all of us can sit here and read your source code all day but the fact remains that we still don't know what your problem is! All we know is it relates to: "How to automate selection of radio button using vb ".

Automate how? When a user preforms a specific task? When a form loads? Do you think you could explain yourself a little bit?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 28th, 2006, 07:54 AM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the code it is mentioned that it is in the form load event.
If u don't know the basics then plz go and learn first.

Satish

 
Old September 28th, 2006, 09:34 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Oh wow, that is certainly NOT the attitude I would take if I was having a problem with source code and wanted someone to correct it for me.

Simple fact of the matter is, I am not here to read through your source code without a reason as to why I am reading through the code; e.g. X Line is producing an error, etc etc etc.

In the future, if you intend to get an answer to a question, post the pertient information about the source code not just the code itself and be a little be more curitous to people that are trying to help YOU for no other reason then we are members of this forum.

BTW, you said: "In the code it is mentioned that it is in the form load event"

I see no comments in your code (besides the ones generated by VS) that state anything to this effect.

(Just an FYI, I am well beyond the basics of programming ;] )

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 28th, 2006, 11:51 PM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now the code used for selecting the radio button is


ihtmlcol1 = HTMLDoc1.getElementsByTagName("input")
        For Each iHtmlIn In ihtmlcol1
            If iHtmlIn.name = "demcons" Then
                If iHtmlIn.value = "KWH" Then
                    iHtmlIn.checked = True
                End If
            End If

the html for radio button is

The html code for radio button is as
'follows<input type="radio" name="demcons" value="KWH" class="datainput"></td>).
I just want to select radio button . Also check the checkbox.


Satish







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to automate selection of radio buttons using v satish_k VB.NET 2002/2003 Basics 1 September 28th, 2006 12:11 PM
how to automate selection of radio buttons using v satish_k Pro VB.NET 2002/2003 1 September 28th, 2006 09:46 AM
how to automate selection of radio buttons using v satish_k Excel VBA 0 September 27th, 2006 07:03 AM
Form changes with radio button selection jekel13 PHP How-To 16 February 17th, 2006 04:56 PM
Display based on radio button selection Mekala Javascript 4 August 5th, 2004 11:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.