Simple Steps in VB.NET. Part 5 - Approaching the End
Article source code: ssteps5_addressbook.zip
Today we will - F-I-N-A-L-L-Y! - finish our address book. The way we will do it might look a bit clumsy and funny. However, it's the fastest, safest, and most effective way for any beginner.
When we install a program, everything goes into one main folder and at least one subfolder. This means to us that we have to change the connection string to our database once more. I promise you, it will be the last time - with this project.
We won't use code to change the connection string because I didn't feel very comfortable with it. After I had finished my installer using code to change the connection string, I installed the program on my computer with the English version of Windows installed, and that worked just fine. Nevertheless, when I installed it on my laptop with the Portuguese version of Windows installed, the program came up with an error when I opened it. Why - I really don't know.
I looked in the VB.NET help files, and they suggest the use of dynamic properties and configuration files. But, boy, can help files be complicated! They link you from one page to another, and before you know it, you're back to where you started. Charles Dickens, Sir Walter Scott, James Fenimore Cooper and the like are much more readable. On the other hand, if you find those authors simple to understand, you won't have much trouble reading the help files either. The average Joe Blow and his mighty Windows will find many of those files difficult to go through, sometimes unclear, incomplete, and even confusing. That's probably the reason why many people post their questions here although the answers are in the help files. I guess they are called help files because after you have read them, you will definitely need help. But let's get back to what's important.
Creating the Folders
Most programs usually have a company folder and, at least, one subfolder. Create a folder and name it Address Book. Move the AddressBook.mdb file, the database, into this folder. Create another folder with your name; this will be the company folder. Move your previously created folder, the Address Book folder, into the company folder. Copy the company folder to your Program Files folder. Don't move the folder; just copy it in case something goes wrong later. If this happens, you won't have to do it all over again.
Let's check if we got it right: you now have a folder with your name. In this folder you have the Address Book folder. In the Address Book folder, you have the database. All this is now in your Program Files folder.
Change the Connection String
Open Visual Basic .NET and open the address book. When DataForm1 is design view, change the connection string to the new location. If you don't remember how to do this, feel free to review the article Simple Steps in VB.NET. Part 2 - Address Book where we started our address book. Run the program to see that everything's just fine.
Click on File, point to Add Project, and finally click New Project. When the Add New Project window has opened, click once on Setup and Deployment Projects. Change the name from Setup1 to something suitable, like Address Book 220.127.116.11. Just make sure it doesn't have the same name as you have already used for the project. When you're done, click on OK.
If this is the first time you do this, everything will look a bit confusing. Don't worry, you'll get used to it. What you see should be something like Figure1.
Adding Folders to the Application Folder
Right-click the Application Folder and choose Add -> Folder. Type your name; it must be the same way you have typed it when you created your company folder. Add another folder with the same name of the subfolder (Address Book) you created inside the company folder.
Adding the Program Output
Right-click the Address Book folder and choose Add -> Project Output. The project output is the program. You will see Figure2.
The project should read Addresses, and Primary Output should be selected. The configuration should read Active. If this is so, click on OK; otherwise change the appropriate settings. After you have clicked the OK-button, the primary output will become visible in the window.
Adding the Database
Right-click the Address Book folder again and choose Add -> File. Navigate to the location where you have your AddressBook.mdb file and click to add it.
Adding the Icon
Right-click the Address Book folder once more and choose Add -> File. Navigate to the location where you have the program icon stored and click to add it.
Add the Program to the Program Menu
Right-click the User's Programs Menu folder and repeat the steps you did to add the program output.
The Default Location
Click the application folder once and go to the properties window. In the default location property, you will see [ProgramFilesFolder][Manufacturer]\[ProductName]. Change this so that it looks like this: [ProgramFilesFolder][YOURNAME]\[Address Book]. So, if you were me, than it would look like this: [ProgramFilesFolder][George Poth]\[Address Book].
Now go to the solution explorer and click Address Book (v. 18.104.22.168) once. Change the Add/Remove Programs icon as you have already done before with the application folder and the desktop shortcut. You won't see the icon here because this icon is displayed in the Add/Remove Programs in the control panel. Later, if you want to uninstall your program using Add/Remove Programs, you will see your icon there.
You can change the remaining properties to what you think appropriate. You can pull out the panel with short explanations as I did in Figure3. Some properties are automatically generated, and it's not a good idea to change them. These properties are: Localization, Product Code, Product Name, Title, Upgrade Code, and Version.
Set the solution configurations to release mode and click the setup project in the solution explorer once. Click Build -> Build Address Book 22.214.171.124.
You might get an error message saying that the database could not be found. If this happens, close Visual Basic and reopen it. This happens when the database is open. The database will only close when you exit Visual Basic.
When you reopen, everything should run just fine. In the menu, click Project -> Install to test your installer. When the installation is complete, click Start -> All Programs -> Addresses and run your program.
Testing the Installer
If you want to install your program clicking on the installer - hey, I know it's much more interesting to see the real McCoy doing it - uninstall the program first from the IDE. Click Project -> Uninstall. After you have uninstalled the program, you can delete the folders you sent to the Program Files folder. If you don't, uninstalling the program will not remove the folders. Your installer is located in C:\Documents and Settings\YourUserName\My documents\Visual Studio Projects\Address Book (v. 126.96.36.199)\Release. If you want to install the program on another computer, just copy the installer (Address Book 188.8.131.52) to that computer and click it - no, no! The .NET Framework and the MDAC (Microsoft Data Access Component) must be installed on that computer. For further information, click the following links:
That completes our project. Throughout my previous articles, I promised to cover several points which I will do very soon. Those points include but are not limited to a prank program for All Fool's Day, decision structures (if ... then, elseif, select case), and using modules and classes. I hope you'll be back for this learning experience.
Related devCity.NET articles: