Form not defined

ADiecidue

Member
Joined
Jun 3, 2008
Messages
13
Programming Experience
10+
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.Appointments.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
 
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"?
 
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?
 
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.
 
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
 

Attachments

  • Image2.jpg
    Image2.jpg
    199.6 KB · Views: 39
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.
 
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?
 

Attachments

  • Image1.jpg
    Image1.jpg
    41.8 KB · Views: 36
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? ;)
 
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.
 
Back
Top