The most likely reason you are receiving these warning messages as errors would be if you had activated a setting in Visual Basic Express "Option Strict On". I would not recommend this option be turned on for anyone other than someone intending to create a fully featured application they intended to sell, and certainly not someone who is trying to learn to code.
- Visual Basic Express CLS-compliant error | Wiley.
- Wrox's visual C# 2005 Express edition starter kit.
- Wrox's Visual Basic Express Edition Starter Kit - PDF Free Download.
Develop Educate Discover. More Details Other Editions 3. Friend Reviews. To see what your friends thought of this book, please sign up. Lists with This Book. This book is not yet featured on Listopia. Community Reviews. Showing Rating details. All Languages. More filters. Sort order.
Dennis Mannon added it Jun 27, When you reach the last page, the wizard takes over and begins to build the new project by analyzing the forms and modules in the old project and converting the various design elements and code subroutines to run in Visual Basic Express. When the wizard is complete, it will close the wizard form and display an upgrade report. If the upgrade report is not shown by default, it usually means the upgrade worked completely.
This sample project should upgrade and build without any errors. Upgrading Visual Basic Visual Basic Express is part of the latest release of Visual Basic from Microsoft and can automatically convert projects developed in previous versions of Visual Basic, often with minimal human intervention required. The Visual Basic Upgrade Wizard does an enormous amount of work for you by converting the old language syntax to the new style of doing things, and replaces various controls and classes as much as it can.
However, many issues can arise when upgrading older Visual Basic 6 projects, and many require unique solutions to deal with the problems that the converter has encountered. These issues fall into two categories — the known and the unknown. The known issues are problems that the Upgrade Wizard encountered as it converted the code and design to the new format. For every single issue that the Upgrade Wizard finds, it will insert comments in the code to highlight the problem as well as a new entry in the Task List.
In both locations, you will also find a link to the appropriate place in the Microsoft help documentation that describes why the Upgrade Wizard was unable to convert the code and what steps you can do to fix the problem yourself.
While these can be a pain to fix, it is the unknown problems that are more of a concern. These are caused by the subtle differences between the ways in which the two different versions of Visual Basic work, and they are not found by the Upgrade Wizard. You will not encounter many of these, and rather than being strictly language-specific problems, they are usually related to the way the original code was written.
Fortunately, Microsoft has outdone itself in creating ways to customize the interface and your experience in using the IDE. As mentioned in the last chapter, menus and toolbars are dynamic depending on the context of your situation. From here, you can select which toolbars should be shown in the current situation, along with which commands are to be accessible from each toolbar. You can create your own toolbars, and add, delete, or move commands around in the menus to suit your own personal style of working. Moreover, the IDE can be changed in a number of other ways that will likely be new to you.
Not only can the various windows and panels that are situated around the main editing space be automatically displayed and hidden as described in the last chapter, they can also be moved to a more convenient location. To aid you in the process, as you drag one of these windows around the design surface, snap and alignment icons will appear. In Figure , the Code Definition window is being dragged over the main editor area. The Visual Basic Express IDE pops up snap buttons to move it automatically to one of the four sides of the editor space, or to the very edge of the entire window.
As it is dragged over another window, the icons change to enable it to piggyback the space used in a tabbed display. In here you can affect the view by something as simple as changing the font to a more legible typeface, showing a grid to more easily align controls when editing a form in Design view, or changing the style of the core IDE from the tabbed environment to a more recognizable MDI layout MDI stands for multiple document interface and is common in applications such as Microsoft Excel.
Some programmers prefer to use line numbers in their code, and Visual Basic Express allows for that kind of customizing, too, in the default view of the Options window see Figure However, numerous configurable settings are hidden in the normal view. Clicking the Show All Settings checkbox at the bottom of the Options dialog window will display these additional settings. Try It Out Customizing the Options 1. By default, you should see the basic view similar to Figure Change the Editor Font from Courier New to Lucida Console on some systems, this might already be selected, and on others the default font will be Courier New.
Lucida Console is a more modern font and is usually easier to read on higher-resolution displays. If you think the size is a little small, you can increase it using the combo box next to the font name list. Expand the Projects and Solutions group and then select VB Defaults to display default settings for any new projects you create.
Turn Option Strict on by checking the box. By default, Option Explicit is turned on, which means that any variables you use in your code must first be declared. While this is great protection from unexpected results, Option Strict is even better. With Option Strict, Visual Basic Express will not allow you to set one variable from another variable if they are different types.
This is known as implicit type conversion and is a common source of errors. Check the Show all settings box to display all of the available options. This gives you access to settings that are otherwise hidden from view. Expand the Projects and Solutions section and first click the General set of options. Set the Visual Studio projects location to a folder that you will be able to find later. Select the Build and Run set of options. Review the Before Building option and ensure it is set to one of the Save options.
Your Visual Basic Express environment is now set up in a way that will ensure you have cleaner programs that is, less bugs and easier code to follow. Not only do you get explanations of every control and every class in the. It incorporates a redesigned search engine that helps you identify the topics that are best suited to your needs. This contrasts with the old MSDN search capability, which would often return hundreds of obscure results that hid the one or two that actually answered your query.
Each result is listed with a brief paragraph and a set of icons representing the technologies covered by the article. Besides the normal table of contents on the left and the much improved search engine, the new documentation application also comes with a special How Do I section. This area provides quick links to common programming tasks, separated into intuitive categories. To access this enormous set of help documentation, simply press F1 anywhere within the Visual Basic Express development environment, or select from the various menu items in the Help menu.
Figure Summar y Although there are hardcore programmers out there who insist on writing every single line of code to achieve their goals, you can see from this chapter that getting some help from the development environment can make you a lot more efficient in reaching those same goals. Look up the documentation for an example of how to use the BackgroundImage property of a control. The program may need to know things before it can do its job.
Alternatively, you might need to keep track of data in between runs. Another possibility is that the program needs to save the information generated while it was executing so another application can use it. Regardless of the need, you have several ways of keeping track of the information a program uses. Database technology has been around for almost as long as computing, and fortunately for Visual Basic Express users, the language and development environment come with a number of tools that make it easy to use.
In fact, using a database to store information is so straightforward in Visual Basic Express that you might find yourself using databases instead of alternatives such as the Windows Registry or normal files that traditionally have been easier to access. Previously, SQL Server needed to run on a server operating system, and because of this, it includes a number of advanced technologies that enable it to run with a much better fail-safe approach than Access. MSDE stands for Microsoft SQL Desktop Edition or Microsoft Database Engine, depending on who you talk to, but either way it represents the same thing: a scaled-down version of SQL Server to enable developers to build those same robust and performance-based databound applications for standalone desktops.
It uses a simplified management environment that borrows from the functionality found in the main SQL Server environment, including a Computer Manager for checking the different services relating to SQL on the machine, and the Express Manager for maintaining the individual databases registered in the SQL Server engine. And SQL Server Express has borrowed a leaf from the Microsoft Access book, storing each database in its own easily accessible file, which can then be easily deployed as part of your application.
NET support the database component of. None of these restrictions prevents SQL Server Express from functioning as a web or database server engine, and in fact it can be used in either of these scenarios. However, the main purpose for it is exactly what this book is about — easily creating applications that run on a Windows desktop PC in a standalone environment. Data to Database Databases store information in a structured fashion. SQL Server Express is what is known as a relational database, meaning that each group of information is connected to another group through identified relationships.
Question About Wrox Book
For example, if you have a group of information about the buildings in a city and another group of people in the same city, you might have a relationship identifying which people are in which building. People have a name and a birth date, but should the names be split into first and last names? They might have an address indicating where they live — is it important that the address be split into different components — house number, street name, city, postal code, and so on? For each piece of data, the database needs to know how it should be stored and what kind of information will be kept in it.
If so, how many? At its simplest, a table has a name and a collection of pieces of information. These chunks of data are called columns or fields , and the preceding table would define the basic structure for a table of five fields. Tables and their corresponding fields are what structure the information kept within the database. When actual data is stored in a table, each discrete collection of information is kept in a separate row, the term SQL Server Express uses for each of the information records. In the preceding example, you have a table with five fields relating to a person.
If the database were to store information about a person named Trevor Greenstein, then his information would be kept in an individual row. If another person named Hayley Thomas were also to be stored in the table, her information would be saved in a separate row. The information can be easily represented in tabular form which comes in handy in Visual Basic Express because the editors for viewing the data within a database table use the same kind of format , so the sample data can be viewed like so.
In the Person table example, the primary key might be a combination of first name and last name. However, there is a chance you could have multiple people with the same name, so SQL Server Express enables you to define special Identifier fields that are used specifically to create a unique index for each row. The preceding table could be modified to include such an identifier. Using SQL, you can find individual rows of information by specifying the criteria you need to follow. Once you have the definition ready to go, you need to create the database and tables to store it. SQL Server Express has Manager applications that enable you to do this, but Visual Basic Express has its own components within its development environment so why go elsewhere?
The name field is used to specify the actual filename of the database see Figure Figure 36 Using Databases Once you have the database file, it can then be used in other applications by pointing them to the disk file that contains the database. Because this is useful only when the database has definitions within it, you can safely cancel the wizard at this point the wizard will be used in later chapters when you connect an existing database to an application.
The empty database file is then added to the Database Explorer. When you first add the database, it may appear in the Database Explorer window with a small red X to indicate it is currently disconnected. Just click the icon and Visual Basic Express will go through the process of connecting it to SQL Server Express and displaying the contents of the database. Figure To create a new table within the database, right-click the Tables folder and select the Add New Table menu command. The main part of the IDE will show a specialized editing form for database tables with three columns of information.
Each field is represented by a row in this editor, with the columns representing the main pieces of information that are required — the name of the field, the type of data that is to be stored in it, and whether the database should allow the field to store nothing, or null, for any given row. In addition to this basic information, a Properties window is displayed below the field list with more advanced settings that can be applied to each individual field. For identifier fields, the Properties window includes an Identity Specification group of properties.
The field that should uniquely identify the rows within the table should have the Is Identity field set to Yes. This will tell SQL Server Express to keep track of the data stored in this field, making sure each row stores a unique value. Creating a primary key is a matter of selecting the fields that make up the key, right-clicking the header button in the row, and selecting Set Primary Key from the context menu.
Figure illustrates how the preceding sample data definition could be represented in the table editor. At this point, Visual Basic Express will prompt you for the name of the table and add it to the list in the Database Explorer. When tables are available in the Database Explorer, you can take a look at the information stored within the table by right-clicking the list and selecting Show Table Data from the context menu. Visual Basic Express displays the rows within the table in a fashion very similar to the table you saw earlier in this chapter see Figure Figure 38 Using Databases The information returned from the database can be edited directly in this window, including creating new rows of data and deleting existing ones.
To create a new row, select the first editable field in the bottom row of the table that has all NULL values. Type the information required and tab to the next field. Repeat this process and then navigate off the row to save the information. Delete a row, or rows, by selecting the rows to be removed by clicking their row header buttons , rightclicking, and selecting Delete.
Additional tables can be created by repeating this process. As mentioned earlier, SQL Server Express is a relational database, which means you can tell the database how tables relate to each other. If there were another table called Pet that stored the information about various pets owned by people, you might want to show that the two tables are linked.
A person might own no, one, or many pets, so you need a way to connect this information. As you look through the definition for the Person table, the obvious choice is the ID field because you know this is unique. You can write SQL queries to retrieve the information in the Pet table for a specific Person record, but a potential issue exists — there is no database-defined relationship. Even though you can look at the database tables and see the connection between the two, SQL Server Express cannot do the same.
To solve this, you need to explicitly define a relationship between the two tables. A relationship is defined by specifying a field as a different kind of key — a foreign key. A foreign key indicates that this field is uniquely identified within a different table. To create a foreign key relationship, click the Relationships button on the Table Designer toolbar.
A list of relationships is displayed in the Foreign Key Relationships dialog box see Figure Click the Add button to add a new relationship and then click the ellipsis button on the Tables and Column Specification property to bring up the Tables and Columns dialog box. One table is designated as the Primary key table, which means the columns you are selecting define the key in that table that uniquely identifies the row. The other table is the Foreign key table, which specifies the table that will be linked to the primary table.
Each field specified in the Primary key table must map to a corresponding field in the Foreign key table. In Figure , the Person table is defined as the Primary table and the ID field has been selected as the identifier column. Figure 40 Using Databases Once this relationship is saved to the database definition, whenever a row is added to the Pet table, the PersonID value is checked against the rows of the Person table. If no row in the Person table with a matching ID value is found, an error is generated and the information is not saved to the database.
Relationship definitions can also include what action to take, if any, when certain events arise. For example, if a program deleted a row from the Person table, you can automatically delete any corresponding rows in the Pet table. In the Foreign Key Relationships dialog box, select the relationship you want to control and change the Update Rule and Delete Rule properties to tell SQL Server Express what to do to rows that are connected to the Primary key table row.
Cascade will automatically update or delete the connected rows, while Set Null and Set Default will not delete the rows, but set them to the respective values of Null or the default value for each type. It will store and maintain their names, addresses, phone numbers, birthdays, and other information to help you remember their likes and dislikes.
Try It Out Creating the Database 1. Select the Windows Application template from the New Project dialog. Having a separate project for the database design is nice because it enables you to work on the database structure without having the user interface and code in the way. Click Add to add the database to the project. Because the database is empty and this project is going to be used exclusively for editing the database structure, click the Cancel button in the Data Source Configuration Wizard. The core of the Personal Organizer application is the information about each family member and friend.
In addition, you will include fields related to finding gifts for the person, which will be used in Chapter 9. Breaking this down into workable chunks, you get the following table. Expand the PO-Data. Right-click the Tables folder and select Add New Table. In the table editor, select the first empty field in the Column Name column and enter the information in the following table.
Go to the next row in the table editor and repeat the process for each of the fields defined in the table in step 3. Text fields can use the nchar type, with the number of characters allowed being specified within the parentheses — for example, NameFirst would have a data type of nchar The DateOfBirth field should use a data type of datetime.
The normal text field type — nchar — can store only around 4K of information. This might not be enough for the Notes column, so use the text data type. The text data type requires more processing by SQL Server and so is not used unless necessary. The definition and the Person table entry in the Database Explorer will look like Figure Using Databases Figure 8.
Add another table to the database by right-clicking the Tables folder in Database Explorer and choosing Add New Table. Add the preceding columns, remembering to include an identifier column as well so they can be uniquely identified, and set it to be the primary key. While the System Name should actually be unique, the database will perform better if there is a numeric identifier. Remember to use nchar as the data type for Text fields, and datetime as the data type for Date fields. Save the table to the database and name it POUser.
Now you need to connect the two tables, so return to the Person table by right-clicking it in the Database Explorer and choosing the Open Table Definition command. Right-click the NameFirst row and select Insert Column from the context menu. Save the table definition. The tables are now set up, but no explicit relationship is specified. When the Foreign Key Relationships dialog is displayed, click the Add button to create a new relationship. Click the ellipsis button on the Tables and Columns Specification property to bring up the Tables and Columns dialog.
Select POUser as the Primary key table and notice that the Foreign key table is already set to Person, as that is the table you were editing when you clicked the Relationships button. Click Close to return to the table editing view. Click the Save button again to save the relationship to the database. Because this affects multiple tables, Visual Basic Express will display a confirmation dialog, as shown in Figure Click Yes to force it to save the relationship.
- NLP At Work: The Difference that Makes the Difference in Business;
- Similar titles?
- Question About Wrox Book?
Figure 44 Using Databases If you try to add a record to the Person table, it will enforce the relationship, not allowing any rows to be added without a corresponding entry in the POUser table with a matching ID to the POUserID. Go ahead and try to add a row to the Person table first, by right-clicking the Person table in the Database Explorer and selecting Show Table Data. Enter information in all the columns and navigate off the row. Visual Basic Express will display an error dialog informing you that it was unable to commit the information to the database because it conflicted with the foreign key definition see Figure Press Escape to cancel the changes.
Open the POUser table and enter a row there to identify yourself. For now, anything will do, but later in the book, the System Name will be used to compare to the currently logged on user in Windows. Take note of this number, return to the Person table, and re-enter all the information for a new Person row. Save the project so you can return to it later. The database file will be included in the project location, so note where you save the project for future chapter exercises and Try It Out examples.
This is the same wizard that you canceled out of when you added the empty database, but this time it begins with the Data Source Type page. Select the Database option and click Next. If the database is already in the project, it will be displayed in the existing data connection list. If you want to use this database or any other existing data connection, select it from the list and click Next. Visual Basic Express defaults to using SQL Server connections, so all you should need to do is specify the database filename.
Click the Browse button to navigate to the location of the database file and click Open to select it. Click the Test Connection button to ensure that the database is accessible and then click the OK button to return to the wizard. The next page of the wizard enables you to optionally save the connection string to your application settings.
This time, however, the Tables node will have children entries for each table defined and the Views, Stored Procedures, and Functions nodes will, too, if the database has those kinds of objects. Select the tables you want to include in the data connection and click Finish to finalize the wizard and add the data source to the project. The Data Sources window will be populated with the Dataset object, including the tables and the individual fields within each table in a tree view.
A sample of this can be seen in Figure Note that the POUser table in this example includes a child reference to the Person table because of a defined relationship between the two. Once the information is available in the Data Sources window, you can use it to bind user interface components to database elements, and write code to access the database through the Data Source objects. One very simple way of presenting the information to the user is by dragging the table directly onto a form.
Visual Basic Express will automatically add a tabular control known as a DataGridView to the form, along with a navigation bar with New, Delete, Save, and movement buttons. It will also define the required data objects for the form shown in the tray area below the main user interface design. Chapter 7 goes into a lot more detail about the various controls that you can use to automatically connect to the data sources you have defined in the project. For now, the following Try It Out uses the Personal Organizer Database project to illustrate how you can quickly view the data in the tables.
Show the Data Sources window by selecting its tab next to the Solution Explorer tab. Select Database and click Next to show the data connection page. By default, the wizard will detect that a database is defined in the project and populate the existing data connection list with the name of the database file. Click Next to go to the Save Connection String page. Be aware that when you add the database locally, Visual Basic Express creates a fresh copy of the database each time the program runs.
If you want to keep the changes between executions, you need to save the database file externally to the project. After a few moments, the Data Sources window will be populated similar to the one shown Figure Initially, the tables might not be expanded, so click the expand buttons to show the individual fields. Go to the Form1. Visual Basic Express will automatically add all the required objects and user interface controls. When the application starts, the form will be shown with the DataGridView control populated with the information you added to the database in the previous Try It Out see Figure Figure Stop the application by clicking the Close button on the form, and save the project so you can preview the data later.
ISBN 13: 9780764595738
Programs created in development environments such as Visual Basic Express can use OLE DB to access different database types without needing to know specific methods to do so. As long as the manufacturer of the database distributes an OLE DB interface to their database, you can access it using common commands, classes, and methods. The rest of the settings are the same, and once you add the database to the project, you can interact with it in a similar fashion to a SQL Server database.
Dragging the table or fields from the Data Source onto a form will automatically create the user elements needed to access the database, just as a SQL Server database will. The differences become apparent when writing code. OleDB classes. This is because the various methods and properties differ for each database type, and Microsoft has made a concerted effort to fine-tune the performance of SQL Server databases.
Summar y Storing and accessing information in a database is an essential part of programming. Visual Basic Express, with the aid of SQL Server Express, makes the process of creating a database straightforward, and then continues the ease of development by enabling you to add database information to a Visual Basic application through wizards and simple drag-and-drop functionality. With these tools at your fingertips, you can ensure that your application is synchronized with the data that drives it. Exercise 1. Create a database that uses the Person and Pet tables defined at the beginning of this chapter.
Make sure they are linked through a foreign key relationship so that each Pet record must be owned by a Person record. First is the data, which is the whole reason for the application. This is normally stored in a database and has tables and queries defined so that the program code can access the information in a logical manner. You saw how databases work in Visual Basic Express in Chapter 3. The second component is the program code that operates on the data and controls what the user can and cannot do. This programming logic will be the subject of the next chapter. This chapter deals with the third section of creating an application — designing the user interface.
This has happened on numerous occasions in the software industry. Companies release a version of their software with all new bells and whistles but overcomplicate the user interface design. As a result, their competitors release their own software with a more elegant interface, which helps their market share. Chapter 4 In some cases, the reverse is true. For example, an application released in Australia was designed for simplicity with no obvious buttons on the main window.
Instead, everything was done using keystrokes; and for those who tried it, it worked really well. However, the main competition was a piece of software that more closely resembled other commonly used programs such as Microsoft Excel. It was frustrating for the company that released the first product because they knew their application was better. Only when they implemented an optional add-on to the product that enabled users to customize the interface with buttons and commands did their sales pick up, and now the add-on is installed by default.
Documentation in the form of manuals and help files can be useful, but they should assume the role of supporting information, rather than being a required tool to use your application. First and foremost, think carefully before changing colors and fonts. By default, controls in Visual Basic Express incorporate the standard system colors of the operating system along with the fonts the user has chosen to use. If you leave these settings as is, users can customize their experience of your application by changing their system setup.
Forcing certain color schemes or fonts on users of your application may be detrimental to the usability of your program. Make the design of your objects uniform. If you set the height of the buttons on your main form to pixels, then make sure you set the height of the buttons on any other forms you might use to the same. If you use a TextBox control to display information instead of a label, then do the same for other informational panels you may add. When you need to display one particular element differently than the others, make sure you use enough contrast to distinguish it.
Consider the example shown in Figure ; the Bigger button has a slightly larger font — can you tell? The Italic button is obviously different from the Normal button but because of the screen it can be hard to read.
The Bold button is obviously different from the Normal style and so is the best option out of these three for contrast. If you choose to use color — which is certainly acceptable — remember to also alter the style in some other way as well. When considering the use of color in your application, there is an excellent option that should be explored.
Rather than select specific color values, you can choose system-defined colors such as ButtonFace and ActiveBorder that are controlled by the user through the Windows Control Panel. This enables users to select the colors most effective for their own situation and gives your application the flexibility it requires to cater to different needs.
Even a 1-pixel difference in the left-hand side of two controls can show up in the final design as being sloppy and unprofessional. Visual Basic Express does help you with this by providing guidelines and snap-to markers, but you should always take care to properly align your controls. Group those elements that belong together so that users can navigate easily. Note how most applications have menus in which the commands are divided by function, and toolbars that group like actions together. The same applies to your own design, and this rule extends to the main section of your form.
If you were to create a form with information about a person, you would keep the first name and last name fields together, rather than split them up, for example. These guidelines may seem self-evident to you. If so, great! Adding and Customizing Controls Visual Basic Express makes it easy for you to create forms that follow good user interface design practices. Guidelines help you to position and size each control, and components inherit certain properties, such as the font, from their parent component.
This enables you to change a property in one place and have the new setting reflected by all of the child components, ensuring that you maintain a clean consistent design. Name it MyFirstProgram. From the Toolbox, click and drag the Button control to the form. As this is the first control being added to the form, the lines will guide you to the preferred distance from the edges of the form. Position the button so that it is the ideal distance from the top of the form and in the middle horizontally. Now add another Button control to the form in the same way. This time, as you drag the new object over the form, not only will the indicators show the distances from the edges of the form, but also the ideal distance from the other controls on the form.
In addition, new lines this time colored blue , will show when the control is aligned horizontally or vertically with the existing components. Both the ideal positioning and alignment guidelines can be seen in Figure Another point to note is that as you drag the control around the form, it will snap to these lines when you get close enough. Position the second button directly below the first one. Figure 54 4. Resize the second button by clicking over the bottom boundary and dragging it down so that it is roughly square. The form shown in Figure has had a ToolTip object added to it.
Every control has a number of properties that define its appearance and control how users can interact with it. Some of these properties, such as Width and Height, can be controlled by the mouse on the design surface to set the size of the control. However, these properties, along with What the User Sees most of the others, can be accessed in the Properties window some controls have properties that cannot be changed at design time — these need to be set in code. Change the Text property to Say Hello. For a button object, this changes the caption that the user sees on the button.
Change the ForeColor property to red and note how the text changes color to match.
Controls can easily be added to your form by clicking and dragging them to the desired position. Alternatively, you can double-click the control name in the Toolbox, and a new object will automatically be added to the form. Once on the form, you can set most of the properties through the Properties window.