Hi
I'm very new to ASP.NET and VB so I'm working through a book (Beginning ASP.NET 3.5 with VB2008 from Novice to Professional. There's an error in the code the book provides and I have no idea how to fix it. its driving me crazy so would really appreciate it if someone could tell me what the problem is with the below vb code. Line 46 is the problem where I specify 'handles ShowGraph'. The 'ShowGraph appears to be the issue, please can anyone tell me what the issue is here. The forum wont allow me to upload the vb file or the xhtml (axpx) file.
If you can help I'd really appreciate it, this is driving me crazy and is stopping me from learning anything new!!
Many thanks
Here's the vb code, I've shown the error part in red:
Partial Public Class Currency
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
' Currency.Items.Add (Euro") would have added Euro to the <select> tab i.e. drop down
' Stating its a New ListItem and adding , "0.85" means that the code knows how much
' to multiply the user entry amount by if Euro selected
Currency.Items.Add(New ListItem("Euros", "0.85"))
Currency.Items.Add(New ListItem("Japanese Yen", "110.33"))
Currency.Items.Add(New ListItem("Canadian Dollar", "1.2"))
Currency.Items.Add(New ListItem("Sterling", "2.2"))
Currency.Items.Add(New ListItem("Australian Dollar", "1.1"))
Currency.Items.Add(New ListItem("Welsh Pounds", "2.1"))
' the html aspx file states that an image will be inserted but doesnt say what image
' the line below is to stop the image 'graph' as its referred to in the html from being
' shown because we only want the image to appear when the user clicks the 'show graph'
' button thats included as an input on the html.
Graph.Visible = False
End If
End Sub
Protected Sub Convert_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Convert.ServerClick
Dim oldAmount As Double = Val(US.Value)
' Retrieves the selected ListItem, i.e. whatever the user selects from the drop down
' Dim means retireve, ListItem is the <select> drop down, Currency.items (Currency is the name of
' the dropdown, the items are the contents of the dropdown. Currency.SelectedIndex means the
' item actuall' selected by the user from the drop down
Dim item As ListItem = Currency.Items(Currency.SelectedIndex)
' Dim newAmount means retrieve the new amount as a 'double, i.e. decimal floating number and
' then =oldAmount * Val(itemValue) means the new amount is the old amount (i.e. amount user
' entered into the field and multiply it by the value held for the item (i.e. the drop down
' option thats been selected like Euros holds a value of 0.85
Dim newAmount As Double = oldAmount * Val(item.Value)
'below means add the result of the above to a string so the resulting string of 275 added to the
' input field by the user is '275 U.S. dollars = 233.75 Euros' when euros is the selected drop-down
'the & " " & item.TEXT means that the item from the drop down (in this case Euros) is added to the string
' as is the resulting calculation (i.e. newAmount)
Result.InnerText = oldAmount.ToString() & " U.S. dollars = "
Result.InnerText &= newAmount.ToString() & " " & item.Text
End Sub
Protected Sub ShowGraph_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowGraph.ServerClick
Graph.Src = "Pic" + Currency.SelectedIndex.ToString() + ".png" Graph.Visible = True
End Sub
End Class
I'm very new to ASP.NET and VB so I'm working through a book (Beginning ASP.NET 3.5 with VB2008 from Novice to Professional. There's an error in the code the book provides and I have no idea how to fix it. its driving me crazy so would really appreciate it if someone could tell me what the problem is with the below vb code. Line 46 is the problem where I specify 'handles ShowGraph'. The 'ShowGraph appears to be the issue, please can anyone tell me what the issue is here. The forum wont allow me to upload the vb file or the xhtml (axpx) file.
If you can help I'd really appreciate it, this is driving me crazy and is stopping me from learning anything new!!
Many thanks
Here's the vb code, I've shown the error part in red:
Partial Public Class Currency
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
' Currency.Items.Add (Euro") would have added Euro to the <select> tab i.e. drop down
' Stating its a New ListItem and adding , "0.85" means that the code knows how much
' to multiply the user entry amount by if Euro selected
Currency.Items.Add(New ListItem("Euros", "0.85"))
Currency.Items.Add(New ListItem("Japanese Yen", "110.33"))
Currency.Items.Add(New ListItem("Canadian Dollar", "1.2"))
Currency.Items.Add(New ListItem("Sterling", "2.2"))
Currency.Items.Add(New ListItem("Australian Dollar", "1.1"))
Currency.Items.Add(New ListItem("Welsh Pounds", "2.1"))
' the html aspx file states that an image will be inserted but doesnt say what image
' the line below is to stop the image 'graph' as its referred to in the html from being
' shown because we only want the image to appear when the user clicks the 'show graph'
' button thats included as an input on the html.
Graph.Visible = False
End If
End Sub
Protected Sub Convert_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Convert.ServerClick
Dim oldAmount As Double = Val(US.Value)
' Retrieves the selected ListItem, i.e. whatever the user selects from the drop down
' Dim means retireve, ListItem is the <select> drop down, Currency.items (Currency is the name of
' the dropdown, the items are the contents of the dropdown. Currency.SelectedIndex means the
' item actuall' selected by the user from the drop down
Dim item As ListItem = Currency.Items(Currency.SelectedIndex)
' Dim newAmount means retrieve the new amount as a 'double, i.e. decimal floating number and
' then =oldAmount * Val(itemValue) means the new amount is the old amount (i.e. amount user
' entered into the field and multiply it by the value held for the item (i.e. the drop down
' option thats been selected like Euros holds a value of 0.85
Dim newAmount As Double = oldAmount * Val(item.Value)
'below means add the result of the above to a string so the resulting string of 275 added to the
' input field by the user is '275 U.S. dollars = 233.75 Euros' when euros is the selected drop-down
'the & " " & item.TEXT means that the item from the drop down (in this case Euros) is added to the string
' as is the resulting calculation (i.e. newAmount)
Result.InnerText = oldAmount.ToString() & " U.S. dollars = "
Result.InnerText &= newAmount.ToString() & " " & item.Text
End Sub
Protected Sub ShowGraph_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowGraph.ServerClick
Graph.Src = "Pic" + Currency.SelectedIndex.ToString() + ".png" Graph.Visible = True
End Sub
End Class