Results 1 to 14 of 14

Thread: Form not defined

  1. #1
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82

    Form not defined

    I am trying to open a modal form with the code below, but the error that is being reported is that the form is not defined. I'm new to VB.Net, so I know this is probably a basic question, but what am I doing wrong and how do I "define" a form? ---Tony---

    Private Sub c1Schedule1_BeforeAppointmentCreate(ByVal sender As Object, ByVal e As CancelEventArgs) Handles C1Schedule1.BeforeAppointmentCreate
    ' Don't show built-in form
    e.Cancel = True
    ' Create new Appointment object with currently selected DateTime and default
    Dim app As Appointment = C1Schedule1.DataStorage.AppointmentStorage.Appoint ments.Add(C1Schedule1.CurrentDate, TimeSpan.FromMinutes(45))
    ' Create frmMakeAppt for the new appointment
    Dim f As New ExcerciseForm(C1Schedule1, app) <----Here is where the error occurs
    ' Show form
    If f.ShowDialog() <> DialogResult.OK Then
    ' If user closes form without saving, remove appointment
    app.Delete()
    End If
    End Sub

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    What is the exact error message? If it's something like "Type 'ExcerciseForm' is not defined." then that means that you've never added a type named "ExcerciseForm" to your project. Could it be because that's not how you spell "exercise"?

  3. #3
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Yes, that's exactly what the error is saying. I'm brand new at VB.net (coming from VB6). How do i add a type?

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    Right-click your project in the Solution Explorer, select Add and then the appropriate item template. You can also use the Project menu.

  5. #5
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Ok.. I know I'm being thick here, but when I right-click the solution my options are Add-New Item, Existing Item, Windows Form, etc.... I've tried all three and New Item simply adds a new form. The form already exists in the solution because I added it before. What am I supposed to select?

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    When you select any of those Add options it will display the Add New Item dialogue. If you choose something specific, like Add Windows Form, then the corresponding item template will be selected by default. If you choose Add New Item then just the first item template will be selected, whatever that happens to be. No matter how you got there, you can select any item template you want in the Add New Item dialogue.

    If you really have added a form with that name and the compiler tells you that it doesn't exist then something is corrupt; either your project or the IDE. Before assuming that that's the case I'd be interested to see a screen shot showing your Solution Explorer, including that class, and the code window showing the error message.

  7. #7
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Here is exactly what I did: I right-clicked the solution, selected Add-Existing Item and added the form ExcerciseForm.vb. I have attached the screen shot with the error and the solution explorer window. If you don't get the attachment you can go here: Image2.jpg
    Attached Images Attached Images

  8. #8
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    Hmmm... it certainly does look like something is amiss there. I will point out again that you have misspelled "Exercise", but you've misspelled it in both places. Is it possible that the name of the file and the name of the class are not the same? That's the only thing I can think of that would legitimately cause that error. Actually, as soon as I typed that I thought of something else too. Maybe the ExcerciseForm class is declared inside a different namespace. You could check that in the Class View window.

  9. #9
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    I know its misspelled, but I kept that spelling throughout. attached is the class view window and there is no mention of it there. Should there be? If so, how would I add it?
    Attached Images Attached Images

  10. #10
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Whoops! When I expanded TestSchedule, ExcerciseForm was in there. Is that a problem?

  11. #11
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    Quote Originally Posted by ADiecidue View Post
    Whoops! When I expanded TestSchedule, ExcerciseForm was in there. Is that a problem?
    Absolutely! If you haven't imported that namespace then you code doesn't know about it. By using "ExcerciseForm" unqualified you're implying that such a type exists in a namespace that has been imported, which it doesn't. You have to either import that namespace or else qualify the type name, i.e. "TestSchedule.ExcerciseForm".

    Also, can you please fix the spelling of that class name so I don't have to keep misspelling it myself?

  12. #12
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Thanks! That was it! I simply qualified it by using "TestSchedule.ExcerciseForm" because I don't know how to import a namespace.

  13. #13
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,140
    Reputation
    1652
    Quote Originally Posted by ADiecidue View Post
    I don't know how to import a namespace.
    Check it in the bottom half of the References page in the project properties to import it project-wide or else add an Imports statement to the top of a file to import it into that file only.

  14. #14
    ADiecidue is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2008
    Posts
    13
    Reputation
    82
    Thanks! There is certainly a steep learning curve between VB6 and VB.net!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking