How to automate selection of items from list using vb.net

FYI . I am pasting the code from the code behind form

Imports mshtml
Imports SHDocVw
Imports Automation
Imports InternetMacros
Imports System.Threading

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)
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 ihtmlcol1 As IHTMLElementCollection
Dim iHtmlEle As IHTMLElement
Dim iHtmlEle1 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
' For Each iHtmlEle In iHtmlCol
'If Not iHtmlEle.getAttribute("name") Is Nothing Then
' str1 = iHtmlEle.getAttribute("name").ToString
'If str1 = "demcons" Then
'MsgBox("hi")
' If iHtmlEle.outerHTML = "<input type=radio" & _
' " name=demcons value=kwh" & _
'"> " Then
'iHtmlEle.click()
' MsgBox("hi")


' Exit For
'End If

'End If

' End If
' Next

Thread.Sleep(7000)

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
If iHtmlIn.name = "Consolidate" Then
If iHtmlIn.value = "YES" Then
iHtmlIn.checked = True
End If
End If
If iHtmlIn.name = "allmpans" Then
iHtmlIn.checked = True
End If
Next
' Press the Download button
Thread.Sleep(800)
If iHtmlIn.name = "download" Then

iHtmlIn.click()

End If

'Here I want the selection of items to beautomated
Do
Loop Until Not wbBrowser.Busy

End Sub

my requirement has been highlighted in bold.

End Class

html source is as given

<select NAME="MPAN" tabIndex="0" size="15" onClick="uncheckallbox(this)" multiple>
<option value="1014568057864">1014568057864 </option><option value="1014568661619">1014568661619 </option><option value="1014568985910">1014568985910 </option><option value="1014570901353">1014570901353 </option><option value="1014571493140">1014571493140 </option><option value="1014571814914">1014571814914 </option><option value="1023480020587">1023480020587 </option>

The java script function used to select all the items is

function uncheckallbox()
{
document.Form1.allmpans.checked = false;
}

function checkforMPANs()
{
//document.Form1.MPAN.selected = false;
//alert('You cannot select this option!');
for (i=0;i<Form1.MPAN.length;i++)
document.Form1.MPAN.selected = true;
//alert('You cannot select this option!');

}

How can I acheive automatic selection of items using vb.net shdocvw.dll and mshtml .dll

[7487 byte] By [satish_k] at [2008-3-5]