Starting Visual Basic

0 views
Skip to first unread message

In Libman

unread,
Aug 4, 2024, 4:11:10 PM8/4/24
to maisnowettor
Itwas made by a colleague and wanted me to test it out, but Access keeps crashing and restarts every time I tried to access a specific user-written function's code. I tried just opening visual basic and opening any of the forms via project explorer to find if there was any offending code, but the window also doesn't show any code. The directory indicates that I'm supposedly viewing the file, but all I get is a blank window, unable to press any buttons. Since this is a work computer with limited permissions, I haven't had the opportunity to reinstall Office 365.

If it helps, the code was written with some Japanese characters in it (I assume the functions used are still in English but some strings are in Japanese), but seeing that I'm also using office with a Japanese language pack (on a computer with Japanese Windows 10) it comes across as it might be software issue, possibly even a hardware issue. I tried resetting the PC's language to Japanese to address the language problem and even that didn't work out.


In Chapter 1, "Introduction to Visual Basic," you toured Visual Basic to familiarize yourself with the development environment. In Chapter 2, "Brief Language Overview," you learned the Visual Basic language. Armed with this knowledge, you are ready to start the project that you will build on throughout the rest of the book. By working toward building an application using Visual Basic, you can learn Visual Basic in the context of a real coding situation. Like any successful software project, let's start by understanding the requirements and formulating a design.


The best approach to designing a software application is to first understand what the requirements are. Do this by interviewing some representatives of the targeted user base or by collaborating with someone with domain knowledge of the business problem. By domain knowledge, we mean someone that understands the business and the expected benefits that would be provided by the software application after it is built.


Because you are now reading a book about Visual Basic and not a book on software requirements and analysis, we do not expect you to go through the process of collecting requirements. To get to the coding part as quickly as possible, we are going to provide some basic requirements for the project. The requirements we came up with are intended to spawn the development of an application that exercises most of the features of Visual Basic. This is a daunting task considering the breadth of features provided by Visual Basic. The point we want to make is that these requirements might not exactly match the real-world requirements of a similar application; that is not the purpose of the requirements presented in this chapter. The purpose is to have a base set of requirements (no matter what they are) so that you can start designing and developing an application.


In an effort to come up with an interesting application that you would enjoy working with, we chose to build an application that supports purchasing products from a store. This project is obviously written in Visual Basic but has the same type of functionality that you would see when browsing or ordering products over the Internet. These types of applications are intended to provide access to the warehouse of product information as well as provide the capability to purchase products.


It is possible that an application of this nature would require many different types of information with which to deal. To keep our application manageable we will be focusing on the following types of information:


The overall application is a virtual store and requires the capability to minimally specify the store name and possible location. Of course, you also need products to sell. You must add products to the store and specify the prices. It also would be nice to see what the product looks like. In addition, you could really use some customers, and it would be great if they bought some products that result in purchase orders. So, now you have a basic idea of what the project is! Now, let's define some requirements.


The application needs the capability to specify store information, maintain products, add and maintain customer information, and enable customers to create orders. To be more specific, here is a list of requirements we came up with. The capability to


This requirements list should get you thinking in terms of what it is we are going to build (not what we think a real application of this type is required to do because that would be a larger list). Along the way, we will be adding more features to the project that do more than meet these requirements.


You do not want these two categories to be part of the same user interface because you do not want to let customers change the prices of products before they buy them--you would quickly be out of business. So, you are going to build two user interfaces as part of the overall application. You will call the user interfaces Administrative Services and Customer Services. Administrative Services contains all necessary functionality for the store worker to do her job. The Customer Services provides the necessary functionality for customers to purchase products.


Obviously, you need products to sell. The user of your application must browse the products that are sold by the store. The user may be someone wanting to buy products or a worker who is performing inventory. A worker would need the capability to edit things like the price and quantity of a product. Because some products become discontinued, the worker needs to be able to delete products.


For the purposes of your store, you want to track the customers and enable them to register with your store. The customer can create a profile to save her address and credit card information. This information is used for any orders that are created within the application by the customer.


The store owner wants to view all the orders currently in the application. The owner might need to see all currently open orders, orders that have not had credit approval, and orders that have been shipped.


The customer who purchases products from the store uses the Customer Services user interface. This is the interface she would use to browse products and create orders. In support of this, the customer must be able to do the following:


Anyone is allowed to register as a new customer. She chooses a customer user ID and password to create her customer profile. The customer stores her billing and shipping address as well as her credit card information within the profile.


While viewing the products, a registered customer must be able to collect a list of products that will eventually become part of one order. By choosing to add to a shopping cart, these products are added to the list of products for purchase.


We are going to stop here with the requirements definition so that we don't get too deep into analysis paralysis. This is the state where software projects don't move forward because of some techno-religious belief that everything must be defined before you write some code. If you feel you are in this situation, build something to validate the requirements you have defined. You can always revisit the requirements and design later. You will not be able to revisit anything if you have not developed anything. Treat software development as a continuous cycle.


The intention is to familiarize you with what we are going to build. We do not need to cover all the details of what we are going to build because we will explore these details as we build the application. Throughout this book, we are going to add functionality as we see fit for the purpose of maximizing our use of Visual Basic in this learning process.


Open Visual Basic and, at the initial dialog box, choose Standard EXE on the New tab to create a new standard application project. The Standard EXE option should be highlighted by default. If it is not, click it. After the option is selected, click the Open button in the dialog box to create the new project. After you have created a new Standard EXE project, you are presented with a workspace that looks like the one in Figure 3.1.


Notice that new Visual Basic projects start with a default name of Project1. The project also contains one form that has a default name of Form1. The first thing you want to do is change the name of the project and the form to a more descriptive name, and then save the project.


Click the element named Project1 at the top of the tree in the Project Explorer. The content of the Properties window (just below the Project Explorer window) now contains the properties of the project. The Properties window always displays the properties of whatever is selected in the Project Explorer window. Double-click the Project1 text in Name property within the Properties window. This selects the entire text. Now type a new name for the project. Enter VBFS for the project name. Figure 3.2 shows the Properties window containing the new name of the project.


The initial form you are going to develop is the login form. This form is used to get the user's name and password before starting the application. Let's start this form by renaming it. Just like you did for the project, click the Form1 form in the Project Explorer. Again, the contents of the Properties window reflect the selection in the Project Explorer. This time you will notice many more properties for forms as opposed to projects. You can view the properties using the scrollbar to the right of the Properties window. Also, clicking the value of a particular property puts you into an edit mode for that property. We will explore the form properties later; for now, double-click the Form1 text in the Name property within the Properties window. Now type frmLoginDlg as the new name.


Standard Visual Basic naming conventions include prepending frm to form names to distinguish them from other objects within the code. This is not a requirement of the Visual Basic language. It is just good practice for you to follow naming conventions to make your code more understandable to yourself and others. As you read through the code it really helps to be able to identify the datatype of a variable when naming conventions are followed. Other people will be able to read and understand your code more readily, and it will help you when you are debugging your application.

3a8082e126
Reply all
Reply to author
Forward
0 new messages