Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 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 8th, 2004, 07:29 PM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chap#3/<asp:listbox>Control p.83

I need some help people!
I typed the code on p. 83 exactly as it is and I get the same error msg every time:
Compiler Error Message: BC30451: Name 'msg' is not declared
<%@ Page Language="vb" %>
<script runat="server">

    Sub Page_Load()
        If Page.IsPostBack Then Dim msg As String
            If list1.Items(0).Selected Then msg = msg & list1.Items(0).Text & "<br />";
                If list1.Items(1).Selected Then msg = msg & list1.Items(1).Text & "<br />"
                If list1.Items(2).Selected Then msg = msg & list1.Items(2).Text & "<br />"
                If msg <> "" then
                    Message.Text = "You have selected: <bt />" & msg
                    Else
                    message.text = ""
            End if
        End if
    End Sub

</script>
<html>
<head>
    <title>List Box Example</title>
</head>
<body>
    <asp:Label id="Message" runat="server"></asp:Label>
    <br />
    Which city do you wish to look at hotels for?<br />
    <form runat="server">
        <asp:listbox id="list1" runat="server" selectionmode="multiple">
            <asp:listitem>Madrid</asp:listitem>
            <asp:listitem>Oslo</asp:listitem>
            <asp:listitem>Lisabon</asp:listitem>
        </asp:listbox>
        <br />
        <input type="submit" value="Submit Query" />
    </form>
</body>
</html>

Now, I have a vague idea what it means but I have no clue how to fix it. I checked my code, retyped it three times, and still the same error msg. When I click on the Design/Preview tab in ASP.NET Web Matrix everything looks normal and I can see the drop down box and everything else but when I try to open the file through the browser the compiler brings the compilation error. Any ideas?



 
Old September 8th, 2004, 11:02 PM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gkelley091565 Send a message via MSN to gkelley091565 Send a message via Yahoo to gkelley091565
Default

Found two things wrong, syntax errors both.

1.) Move 'Dim msg As String' down from line 5 to 6:
If Page.IsPostBack Then
        Dim msg As String

2.) Remove the semicolon (;) from line 7 (line 6 if you haven't already performed step 1 above! )

Your complete working code is:

<%@ Page Language="vb" %>
<script runat="server">

    Sub Page_Load()
        If Page.IsPostBack Then
        Dim msg As String
            If list1.Items(0).Selected Then msg = msg & list1.Items(0).Text & "<br />"
                If list1.Items(1).Selected Then msg = msg & list1.Items(1).Text & "<br />"
                If list1.Items(2).Selected Then msg = msg & list1.Items(2).Text & "<br />"
                If msg <> "" then
                    Message.Text = "You have selected: <bt />" & msg
                    Else
                    message.text = ""
            End if
        End if
    End Sub

</script>
<html>
<head>
    <title>List Box Example</title>
</head>
<body>
    <asp:Label id="Message" runat="server"></asp:Label>
    <br />
    Which city do you wish to look at hotels for?<br />
    <form runat="server">
        <asp:listbox id="list1" runat="server" selectionmode="multiple">
            <asp:listitem>Madrid</asp:listitem>
            <asp:listitem>Oslo</asp:listitem>
            <asp:listitem>Lisabon</asp:listitem>
        </asp:listbox>
        <br />
        <input type="submit" value="Submit Query" />
    </form>
</body>
</html>






Gene Kelley
BizFlowDesigns.com
Arlington, Texas, USA
 
Old September 8th, 2004, 11:06 PM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gkelley091565 Send a message via MSN to gkelley091565 Send a message via Yahoo to gkelley091565
Default

.... also, on line 11: try <br /> instead of <bt />.:)

Gene Kelley
BizFlowDesigns.com
Arlington, Texas, USA
 
Old September 9th, 2004, 08:59 PM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gkelley091565 Send a message via MSN to gkelley091565 Send a message via Yahoo to gkelley091565
Default

Well, I'll have to be quite honest with you and say that "I don't know why." it doesn't like it being on the same line. I just know that when you do, the code doesn't run correctly. When and if I find a better answer for us, I will certainly post it here.



Gene Kelley
BizFlowDesigns.com
Arlington, Texas, USA
 
Old September 6th, 2005, 10:54 AM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem appears to be that if you put arguments on the same line as the if...then statement, it treats it as a one line declaration instead of a multiple line if...then. Really, if the form is not a postback, then it should skip to the last end if statement. That is why there are two end if's at the end of the sub, one for [If Page.IsPostBack] and one for [If msg <> ""].






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
a problem in book<<beginning asp.net using vb>> luoware ASP.NET 1.0 and 1.1 Basics 3 December 8th, 2003 09:32 PM
HELP HELP ODBC<->ASP <-> XML moon Wrox Book Feedback 1 November 9th, 2003 12:42 PM
<<ASP.NET Security>>,download files in chapter 8 alaix All Other Wrox Books 1 July 24th, 2003 10:29 AM





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