ASP.NET with VB2008 really need help!!

A Novice

Member
Joined
Nov 18, 2009
Messages
5
Programming Experience
Beginner
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:confused:

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
 
Whats the error? I'm guessing

VB.NET:
Graph.Src = ...

Needs to be

VB.NET:
ShowGracph.Src = ...
 
Hi
Thanks for replying. I changed Graph.src = etc etc to be ShowGraph.Src = etc etc as you've suggested. I even tried changing it to ShowGracph.Src = etc etc which mirrored your reply but I'm still getting the same error. The error appears to be with the code beforehand 'ShowGraph.ServerClick', it doesnt like ShowGraph there, Visual Studio underlines it as an error.

If you're abkle to tell me what I need to resolve this I'd really appreciate it, is driving me nuts!! :confused:

Many thanks
 
Try the reverse?

Turn
VB.NET:
Protected Sub ShowGraph_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowGraph.ServerClick

Into

VB.NET:
Protected Sub Graph_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Graph.ServerClick


What is the error message?
 
Hi
I tried that but then a get a different error telling me that ServerClick cannot be found. Putting the code back to its original state of the following...

'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'

....gives the error 'Handles clause requires a WithEvents variable defined in the containing type or one of its base types.'

In case it helps, here's the accompanying html code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Currency.aspx.vb" Inherits="Currency" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Currency Converter</title>
</head>
<body>
<form runat="server">
<div style="border-right: thin ridge; padding-right: 20px; border-top: thin ridge;
padding-left: 20px; padding-bottom: 20px; border-left: thin ridge; width: 531px;
padding-top: 20px; border-bottom: thin ridge; font-family: Verdana; height: 211px;
background-color: #FFFFE8">
Convert: 
<input type="text" id="US" runat="server" />
  U.S. dollars to  
<select id="Currency" runat="server"></select>
<br /><br />
<input type="submit" value="OK" id="Convert" runat="server" />
<input type="submit" value="Show Graph" runat="server" />
<br /><br />
<img id="Graph" src="" alt="Currency Graph" runat="server" />
<div style="font-weight: bold" ID="Result" runat="server"></div>
</div>
</form>
</body>
</html>

I appreciate your help, thanks.:confused:
 
Back
Top