Tue, Dec
5 New Articles

Visual Programming Using VB 5.0

Visual Basic
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

VB has become an enormously successful application development language. One reason it is so successful is the ease with which a beginner can develop a Windows GUI. This article explains the visual programming strategy that Microsoft used in its VB IDE.

According to Microsoft, more than three million programmers are developing software applications using Visual Basic (VB). This makes it by far the most widely used visual development tool on the planet. The appeal of VB is, in large part, because of its ability to balance ease of use with robust functionality. This balance is evident when looking at the VB Integrated Development Environment (IDE). With each successive version, Microsoft has enhanced the IDE to provide a more powerful programming environment. With Visual Basic Version 5.0, the programmer has powerful development tools tightly integrated into an IDE that is customizable to each individual’s preferences. This article demonstrates how to use the VB IDE to develop a visual software application.

When you start VB, it displays a dialog box that asks you which type of application you want to create. While a number of choices are available, you essentially choose whether your project is to be a standalone application or a component to be used by other applications. Figure 1 shows the VB New Project dialog box.

IDE Basics

As the AS/400 provides tools such as SEU and SDA to assist in software development, the IDE is used to create VB applications. Just as its name implies, the IDE provides a single integrated environment for screen design, code editing, project compilation, online help text, and interactive debugging. Figure 2 shows the VB IDE.

The VB IDE consists of six main components: the Toolbox, the Form Design Window, the Code Window, the Project Window, the Properties Window, and the Form Layout Window. Each window performs a specific task to assist you with the development of a VB project.

The Toolbox

The VB Toolbox contains a variety of controls that may be added to your project. When added to a VB form, controls such as text boxes, list boxes, labels, and command buttons provide the user interface for your software application. Controls are prepackaged objects that provide specific functionality to the applications you construct using VB. The characteristics and functionality of a control are accessed in your VB programs via properties, methods, and events.

Properties are the attributes that commonly define the appearance and/or characteristics of a control. The attributes of a control are changed by manipulating the values of the control’s properties. For example, to change the color of a screen heading’s text, you simply change the value of the Label control’s ForeColor property to the desired color.

In addition to properties, most controls have methods that perform predetermined functions. A method can be thought of as the functionality that is built into a control. To trigger the control to do something, you call one of the control’s predefined methods.

Unlike methods, event procedures allow you to associate your source code with a predefined control action. The code you add to an event procedure automatically executes when the event occurs. Some examples of common control events are clicking on a command button, keying text into a text box, and displaying a form. Event procedures allow you to say “when the user clicks this button, execute this VB source code.” VB comes with a set of standard controls that are adequate to build most applications, each possessing unique properties, methods, and events.

The Form Design Window

The Form Design Window provides a workspace that allows you to design the layout of your application’s forms. Conceptually, the Form Design Window does for a VB programmer what SDA does for an AS/400 programmer.

The Code Window

The Code Window provides a workspace that allows you to edit and organize VB code statements. Conceptually, the Code Window does for a VB programmer what SEU does for an AS/400 programmer.

The Project Window

The Project Window provides an organized view of your project’s components. From the Project Window, you can see all of the forms and code modules that make up your application.

The Properties Window

The Properties Window displays the attributes or properties of the selected component. Properties can be thought of simply as the attributes that define a component’s appearance and behavior. For example, if you are designing a form in the Form Design Window, the Property Window displays the form’s properties. If you select a specific control on the form, such as a button, the properties associated with the button are displayed.

The Form Layout Window

The Form Layout Window is used to define the positioning of a form on the screen. When the application runs, the form is displayed according to the positioning defined in the Form Layout Window.

The AS/400 Message Utility

A sample application called the AS/400 Message Utility demonstrates how the IDE is used to develop an application. The application is a simple client/server utility that is used

to send a message to one or more active AS/400 users. Figure 3 shows the completed AS/400 Message Utility.

To create applications such as the AS/400 Message Utility, you will start VB and open a new project defined as a standard executable (EXE), as shown in Figure 1. The VB IDE presents you with a new project given a default name of Project1 and a blank form given a default name of Form1. To rename the project, you will click on the File menu, then on the option labeled Save File As. This will allow you to give your project a suitable name, such as “Message”.

From the IDE, you will use the Form Design Window and Toolbox to create the application’s screen or form. Once you have decided how you want the form to look, simply select the desired control on the Toolbox and draw the control onto your form. To draw the control onto the form, you click your left mouse button on the desired location on the form. While holding down the button, simply drag the mouse across the form until the control appears in the desired dimensions. Once a control has been added, you may hone the look of your application by moving or resizing it using your mouse. Five basic controls are used in the sample application:

1) A VB frame allows you to provide a logical grouping of controls on your form. It appears as a lined box drawn around areas of the form. The sample application uses two frames to separate the list of users from the message entry, as shown in Figure 4.

2) The sample application employs a list box control to contain a list of active AS/400 users. Much like an AS/400 subfile, the list box provides an automatic scrolling mechanism that allows you to organize a large list of entries. Properties are set for the list box using the Properties Window, which allows a user to select multiple entries, as shown in Figure 5.

3) Text boxes are used to provide an input-capable field on your form. A text box is used in the sample application to accept a message to be keyed in by the user. The MaxLength property is set to 512, limiting the length of input to be accepted, as shown in Figure 6.

4) Label controls are typically used to define constant text, such as field headings on a form. In the sample application, a label control is used at the bottom of the form to provide a status message area. Properties are set on the control to give the label the appearance of a three-dimensional box, as shown in Figure 7.

5) The Command Button control provides a push button mechanism for the user interface. The sample application uses command buttons to refresh the user list and to send the message keyed into the text box control, as shown in Figure 8.

Using Third-party Controls

As previously stated, VB comes with a set of basic controls suitable for most visual applications. However, these basic controls sometimes don’t provide the functionality or the look you want for a particular application. One of the greatest strengths of VB is that it allows you to use controls created by outside sources. The third-party control market is huge, with hundreds of companies selling VB add-in components. For instance, you may want to create an application that accepts input of a date. Rather than having the user key in a date, you may want the user to see a calendar and click on the desired date. Probably a dozen or more companies sell calendar controls that can be added to your VB applications.

Even IBM provides a set of three controls as part of Client Access for Windows 95/NT. The IBM controls provide access to AS/400 functions from within your VB application. Since these controls were designed to conform to Microsoft’s ActiveX standard, they can be used by any ActiveX-capable software. This means that in addition to

using the controls in VB, you may also use them in packages like Excel, Access, and Word. The Message Utility application uses all three available Client Access controls to provide client/server connectivity to the AS/400.

System List Box

The Client Access System List Box control returns a list of attached or configured AS/400 system names. The control automatically interrogates your Client Access connection to determine the name of your AS/400. The control eliminates the need to hardcode a system name in your VB program, making your applications more maintainable. When used in a multiple AS/400 environment, the control can be used to allow the user to select the desired AS/400 from a list. For single system environments, the functionality of the control can be used without making the control visible to the user. The control can be hidden from view by setting the control’s Visible property to false.

Remote Command Button

The Client Access Remote Command Button control is used to execute an AS/400 command. The sample application uses this control to call a processing program that creates a list of active system users and writes each user profile name to a data queue. When supplied a system name, as retrieved by the System List Box control, the Remote Command Button control executes a CL command on the specified AS/400. Like the system list box, the functionality of the Remote Command Button control can be used without making the control visible to the user. The control is hidden from view by setting the Visible property to false.

Data Queue Text Box

The Client Access Data Queue Text Box control gives your VB applications read and write capabilities to an AS/400 data queue object. This functionality provides a simple and effective means of transporting data to and from an AS/400. The Data Queue Text Box control handles the chore of converting data between ASCII and EBCDIC formats automatically. The functionality of the Data Queue Text Box control can be used without making the control visible to the user. The control is hidden from view by setting the Visible property to false. The sample application uses this control to read entries from a data queue for each active system user.

Adding Controls to a Project

To add third-party controls to your project, open the Project menu and select the Components option. A dialog box will display a list of components available for use by your project, as shown in Figure 9.

Selecting the Client Access Control Library will allow your project to use the three Client Access controls. Once selected, the controls will appear on your toolbox in the IDE, as shown in Figure 10.

From the toolbox, you will add the controls to the form just as you added the frame, list box, label, text box, and command button controls.

Once the visual design of the project is completed, the remaining task is to add functionality to the application in the form of source code statements. To switch the IDE from the Form Design Window to the Code Window, double-click on the control you want to code. The Code Window displays the event procedures available for the selected control. For example, if you double-click on the Command Button control, the button’s event procedures are displayed in the Code Window. The Code Window allows you to easily switch between events and controls. You will key in VB code that you want to execute when the selected event occurs. For the application command buttons, you will select the Click event and key in the code that you want to execute when the button is

clicked. To create a simple application like the Message utility, most of the code involves setting control properties and executing methods. For example, when the user clicks on the button to refresh the AS/400 user list, the button’s Click event procedure, as shown in Figure 11, executes.

To be fully functional, the Message Utility requires a fair amount of code that is beyond the scope of this article.

Simple, Yet Powerful

As you can see by this quick overview, the VB IDE provides a well-designed integrated development tool, balancing the ease of use needed for weekend hobbyists and functionality demanded by enterprise application developers. For AS/400 client/server developers, VB’s ability to use add-in components makes it an attractive option. Many third-party tools are available to make connection to an AS/400 easy.

Figure 1: The VB New Project dialog box


Visual_Programming_Using_VB_5.005-00.png 899x675

Figure 2: The VB IDE

Visual_Programming_Using_VB_5.006-00.png 906x679

Figure 3: AS/400 Message Utility sample application

Visual_Programming_Using_VB_5.007-00.png 902x658

Figure 4: Adding frames to the form

Visual_Programming_Using_VB_5.008-00.png 906x631

Figure 5: Adding a list box to the form

Visual_Programming_Using_VB_5.009-00.png 906x631

Visual_Programming_Using_VB_5.009-01.png 906x631

Figure 6: Adding a text box to the form

 Figure 7: Adding a label to the form

Visual_Programming_Using_VB_5.010-00.png 906x631

Figure 8: Adding command buttons to the form

Visual_Programming_Using_VB_5.011-00.png 906x631

Figure 9: The VB Components dialog box

Visual_Programming_Using_VB_5.012-00.png 900x800

Visual_Programming_Using_VB_5.013-00.png 150x791

Figure 10: The VB IDE toolbox

Private Sub cmdRefresh_Click() ‘‘ Initialize captions and buttons by setting properties ‘pnlStatusBar.Caption = “Calling AS/400 Program...” cmdRefresh.Enabled = False mnuRefresh.Enabled = False pnlStatusBar.ForeColor = vbBlue

‘ Clear list box of users using Clear method lstUsers.Clear ‘‘ Load the Call command into CommandButton and ‘ execute DoClick Method to send command to AS/400 ‘crcCommand1.CommandString = “CALL MCLIB/AUSRC”

crcCommand1.DoClick Figure 11: The Click event



Support MC Press Online

$0.00 Raised:

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: