Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 April 22nd, 2005, 06:40 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Namespace

I keep getting compilation errors on the code below, I believe it to be in my namespace.
Can anyone please shed some light.

Code:
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="MyApplication" %>
<%@ import Namespace="MyApplication.Main" %>
<%@ import Namespace="MyApplication.MyForms" %>
<%@ import Namespace="MyApplication.MyForms.form1" %>
<%@ import Namespace="MyApplication.MyForms.form2" %>
<%@ import Namespace="MyApplication.ApplicationContext" %>
<%@ import Namespace="System.Windows.Forms.Form" %>

' ---------------------------------------------------------------------------------------------------------------------------

    Public Module MyApplication
        Public Enum MyForms
            form1 = 0
            form2 = 1
        End Enum

        Public Sub Main()
            Dim context As MyApplicationContext = New MyApplicationContext
            Application.Run(context)
        End Sub
    End Module

    ' ---------------------------------------------------------------------------------------------------------------------------

    Public Class MyApplicationContext
        Inherits ApplicationContext

        Public Sub New()
            MyBase.New()
            switchTo(Nothing, MyApplication.MyForms.form1)
        End Sub

        Private Sub switchTo(ByVal sender As Form, ByVal formName As MyForms)
            If Not (sender Is Nothing) Then
                sender.Dispose()
            End If
            Select Case formName
                Case MyApplication.MyForms.form1
                    Dim frm1 As form1 = New form1
                    AddHandler frm1.switchTo, AddressOf switchTo
                    AddHandler frm1.Closed, AddressOf OnFormClosed
                    frm1.Show()

                Case MyApplication.MyForms.form2
                    Dim frm2 As form2 = New form2
                    AddHandler frm2.switchTo, AddressOf switchTo
                    AddHandler frm2.Closed, AddressOf OnFormClosed
                    frm2.Show()

            End Select
        End Sub

        Private Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
            ExitThread()
        End Sub
    End Class

    ' ---------------------------------------------------------------------------------------------------------------------------

    Public Class form1
        Inherits System.Windows.Forms.Form

        Public Event switchTo(ByVal sender As Form, ByVal formName As myForms)

        Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click
            RaiseEvent switchTo(Me, MyApplication.myForms.form2)
        End Sub
    End Class


 
Old April 22nd, 2005, 09:58 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can't do what you are trying to do. You can't show a second web form from within one. Web forms don't work like windows forms. You can only see one form at a time. You have to open other forms from the client side using HTML and javascript.

You only need to import a namespace, not specific classes...

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="MyApplication" %>
<%@ import Namespace="MyApplication.Main" %> <-- Is this a form or namespace?
<%@ import Namespace="MyApplication.MyForms" %> <-- this is OK to import
<%@ import Namespace="MyApplication.MyForms.form1" %> <-- class: don't import
<%@ import Namespace="MyApplication.MyForms.form2" %> <-- class: don't import
<%@ import Namespace="MyApplication.ApplicationContext" %> <-- ok
<%@ import Namespace="System.Windows.Forms.Form" %> <-- You can import, but it's useless in ASP.NET

-Peter
 
Old April 22nd, 2005, 10:21 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Peter,

I’m mystified: I don’t see what it is in Dwizz’s code that made you mention web forms. What did you see that led you to that?
(I’m not disputing; rather, I’m confused.)



Dwizz,
Does the IDE tell you where it finds a problem?


I believe Peter is right
Code:
<%@ import Namespace="MyApplication" %>
<%@ import Namespace="MyApplication.Main" %>
<%@ import Namespace="MyApplication.MyForms" %>
<%@ import Namespace="MyApplication.MyForms.form1" %>
<%@ import Namespace="MyApplication.MyForms.form2" %>
<%@ import Namespace="MyApplication.ApplicationContext" %>
can be reduced to
Code:
<%@ import Namespace="MyApplication" %>
since all of these
Code:
<%@ import Namespace="MyApplication.Main" %>
<%@ import Namespace="MyApplication.MyForms" %>
<%@ import Namespace="MyApplication.MyForms.form1" %>
<%@ import Namespace="MyApplication.MyForms.form2" %>
<%@ import Namespace="MyApplication.ApplicationContext" %>
are all contained in that namespace.
 
Old April 22nd, 2005, 10:45 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Brian,

<s>I've never seen <% ... %> in webforms code. Granted, I don't do much webforms, but I'm pretty sure the <%%> is the clincher.</s>

-Peter
 
Old April 22nd, 2005, 10:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Sorry, typed too quick... meant to say:

I've never seen <% ... %> in WINforms code. Granted, I don't do much webforms, but I'm pretty sure the <%@ Page %> directive is the clincher.

-Peter
 
Old April 25th, 2005, 03:46 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey,
Sorry for not replying sooner,

Peter the answer to your question;
<%@ import Namespace="MyApplication.Main" %> <-- Is this a form or namespace?
the answer is that it is a namespace

Brian the answer to your question;
Does the IDE tell you where it finds a problem?
the answer is yes, see below for exact error

Compiler Error Message: BC30617: 'Module' statements can occur only at file or namespace level.

Source Error:
Line 97: ' -------------------------------------------------------------------------------
Line 98:
Line 99: Public Module MyApplication
Line 100: Public Enum MyForms
Line 101: form1 = 0

Thank you for your help

 
Old April 25th, 2005, 09:54 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Thanks for clarifying Peter. I'm still getting used to .NET syntax, and so was willing to believe that inclusion of a namespace was delimited by <% ... %>. My bad. .NET has far more clever little characters denoting context than I have yet been able to assimilate.

Dwizz,

Your declaration of module MyApplication is taking place "nested" within another something (another module, within a sub, within a function or class declaration, something like that).
If you have
Code:
Public Module Outer

    ...

    Public Module MyApp

        ...

    End Module

    ...

End Module
MyApp is not at the file level, it is at the module level (the module at whose level it finds itself being module “Outer”).

Inspect your code for what element might be at a higher level within the file and that is containing the declaration of your “MyApplication.”
 
Old April 29th, 2005, 07:33 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all your help guys






Similar Threads
Thread Thread Starter Forum Replies Last Post
Two namespace contain same name nir_pankaj C# 1 February 21st, 2007 12:30 PM
namespace Ibn_Aziz C# 2 December 25th, 2003 05:41 AM
namespace within namespace Bill Crawley XML 1 December 11th, 2003 10:59 AM
Namespace flute Pro VB.NET 2002/2003 2 October 21st, 2003 09:15 AM





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