Time to get our hands dirty with a bit of programming. There's no putting it off any longer, I'm afraid! We'll create a new project for this section.
So, if you already have you VB NET software open, you can get rid of the current project by clicking File from the menu bar. From the drop down menu, choose Close Solution. You will be returned to the Start Page. Click the "New Project" button at the bottom. When you get the dialogue box popping up, choose Windows Application at the top. Then change the name from WindowsApplication to Variables. You can keep the location set at the default.
When you click the OK button, a new form will appear.
If you look at the Solution Explorer at the top, you'll see the name of the project has changed to the Name you gave it.
The name of the Project is now Variables - the same name as the folder that is created for you to hold all your project files.
Before we get started, it's worth exploring an oddity of the VB Net software.
Click on your Form to select it. Then change the Name property to frmVariables. Press the return key on your keyboard to confirm the name change, or just click back on the form:
The Name property of your Form has now been changed from Form1 to one of your own choosing (well, ours).
Now press F5 to run the project, or click Debug > Start from the menu.
Instead of the programme running, you'll probably get this message box:
Click the No button to return to the Design Environment. You might now have Task List screen displaying at the bottom of your screen:
A rather cryptic message appears: "Sub Main was not found in Variables Form1". You can get rid of the Task List by clicking the X, or the Pin symbol.
The reason you got that message is that VB is still trying to run a form called Form1. Even though you changed it's name, it still tries to do something with it. But you no longer have a form called Form1, so VB gives you the error message. Hopefully, Microsoft will correct this in the next version.
But here's the solution to the problem.
In the Solution Explorer window, right click on the name of your project (Variables). A menu should appear. Click Properties right at the bottom:
Notice that we've clicked on "Variables", and not on "Solution Variables". When you click Properties, you get this dialogue box popping up:
The Startup Object, as you can see, is still set to Form1. Click the down arrow to reveal the following:
The name you gave your form is on the list. Select frmVariables and click the OK button. Now run your programme again. You should get no error messages this time, and the form will load properly.
0 comments:
Post a Comment