Different

Replace the file paths with the paths you want to use in your code. CopyFile does not preserve ACEs (Access Control Entries). The newly created file inherits default ACEs from the directory in which it is created. The following table lists examples of tasks involving the My.Computer.FileSystem.CopyFile method. VB uses the hexadecimal system to represent the color. You can check the color codes in the properties windows which are showing up under ForeColor.

3.1 The Control Properties

Before writing an event procedure for the control to response to an event, you have to set certain properties for the control to determine its appearance and how will it work with the event procedure. You can set the properties of the controls in the properties window or at runtime.

Figure 3.1 is a typical properties window for a form. In the properties window, the item appears at the top part is the object currently selected. At the bottom part, the items listed in the left column represent the names of various properties associated with the selected object while the items listed in the right column represent the states of the properties. Properties can be set by highlighting the items in the right column then change them by typing or selecting the options available.

For example, in order to change the caption, just highlight Form1 under the name Caption and change it to other names. You may also alter the appearance of the form by setting it to 3D or flat, change its foreground and background color, change the font type and font size, enable or disable, minimize and maximize buttons and more.

You can also change the properties at runtime to give special effects such as change of color, shape, animation effect and so on. Example 3.1 show the code that will change the form color to red every time the form is loaded. VB uses the hexadecimal system to represent the color. You can check the color codes in the properties windows which are showing up under ForeColor and BackColor .

Example 3.1: Program to change background color

This example changes the background colour of the form using the BackColor property.

Example 3.2: Program to change shape

This example is to change the control's Shape using the Shape property. This code will change the shape to a circle at runtime.

We are not going into the details on how to set the properties yet. However, we would like to stress a few important points about setting up the properties.


  • You should set the Caption Property of a control clearly so that a user knows what to do with that command.

  • Use a meaningful name for the Name Property because it is easier to write and read the event procedure and easier to debug or modify the programs later.

  • One more important property is whether to make the control enabled or not.

  • Finally, you must also considering making the control visible or invisible at runtime, or when should it become visible or invisible.

3.2 Handling some of the common Controls

Figure 3.2 below is the VB6 toolbox that shows the basic controls.

3.2.1 The TextBox

The text box is the standard control for accepting input from the user as well as to display the output. It can handle string (text) and numeric data but not images or pictures. A string entered into a text box can be converted to a numeric data by using the function Val(text). The following example illustrates a simple program that processes the input from the user.

Example 3.1

In this program, two text boxes are inserted into the form together with a few labels. The two text boxes are used to accept inputs from the user and one of the labels will be used to display the sum of two numbers that are entered into the two text boxes. Besides, a command button is also programmed to calculate the sum of the two numbers using the plus operator. The program use creates a variable sum to accept the summation of values from text box 1 and text box 2.The procedure to calculate and to display the output on the label is shown below.

The output is shown in Figure 3.3

VMware Workstation 15.5.1 Crack is one of the best hypervisors or VMM (virtual machine monitor) worldwide. It is compatible with the Windows operating system, as well as the Linux operating system. This software allows the user to create more than one virtual machine on a physical device. VMware Workstation 15 Serial Key is a very popular operating system software that supports user all great experience to perform a comprehensive set of features and a higher level of high-performance virtualization. VMware Workstation Player 15.5 Crack uses virtual machines to do professionally designed work. A 64-bit processor and a 64-bit host. Vyatta Virtualization Iso Vmware Workstation Free Vyatta Virtualization Iso Vmware Workstation Key. The commit and save commands are very important commit makes the configuration “live” and save saves it to disk if you do not type save on reboot any changes you’ve made will be lost. At this point you should be able to ping those x. Vyatta does not have a suspend/power mgmt option, but VMware Workstation 6 will suspend the machine showing a black screen till you press a key. The host operating system does not suspend, but the Virtual Machine does. Is there some setting in VM that i need to change to fix this, i couldn't find anything on it. Vyatta virtualization iso vmware workstation key.

3.2.2 The Label

The label is a very useful control for Visual Basic, as it is not only used to provide instructions and guides to the users, it can also be used to display outputs. One of its most important properties is Caption. Using the syntax Label.Caption, it can display text and numeric data . You can change its caption in the properties window and also at runtime. Please refer to Example 3.1 and Figure 3.1 for the usage of the label.

3.2.3 The Command Button

The command button is one of the most important controls as it is used to execute commands. It displays an illusion that the button is pressed when the user click on it. The most common event associated with the command button is the Click event, and the syntax for the procedure is

Example 3.2 A Simple Password Cracker

In this program, we want to crack a secret passoword entered by the user. In the design phase, insert a command button and change its name to cmd_ShowPass. Next, insert a TextBox and rename it as TxtPassword and delete Text1 from the Text property. Besides that, set its PasswordChr to *. Now, enter the following code in the code window.

Run the program and enter a password, then click on the Show Password button to reveal the password, as shown in Figure 3.4.

You can also reveal the password by setting the PasswordChr property back to normal mode, as follows:

*Check out our more advanced password cracker program

3.2.4 The PictureBox

The Picture Box is one of the controls that is used to handle graphics. You can load a picture at design phase by clicking on the picture item in the properties window and select the picture from the selected folder. You can also load the picture at runtime using the LoadPicture method. For example, the statement will load the picture grape.gif into the picture box.

Example 3.4 Loading Picture

In this program, insert a command button and a picture box. Enter the following code:

* You must ensure the path to access the picture is correct. Besides that, the image in the picture box is not resizable. The output is shown in Figure 3.5

View our more advanced picture viewer here.

3.2.5 The Image Control

The Image Control is another control that handles images and pictures. It functions almost identically to the pictureBox. However, there is one major difference, the image in an Image Box is stretchable, which means it can be resized. This feature is not available in the PictureBox. Similar to the Picture Box, it can also use the LoadPicture method to load the picture. For example, the statement loads the picture grape.gif into the image box.

Example 3.5 Loading Image

In this program, we insert a command button and an image control into the form. Besides that, we set the image Strech property to true. Next, enter te following code:

* Note the the difference between the image in Figure 3.5 and Figure 3.6.

3.2.6 The ListBox

The function of the ListBox is to present a list of items where the user can click and select the items from the list. In order to add items to the list, we can use the AddItem method. For example, if you wish to add a number of items to list box 1, you can key in the following statements

Example 3.2

The Output

The items in the list box can be identified by the ListIndex property, the value of the ListIndex for the first item is 0, the second item has a ListIndex 1, and the third item has a ListIndex 2 and so on

3.2.7 The ComboBox

The function of the Combo Box is also to present a list of items where the user can click and select the items from the list. However, the user needs to click on the small arrowhead on the right of the combo box to see the items which are presented in a drop-down list. In order to add items to the list, you can also use the AddItem method. For example, if you wish to add a number of items to Combo box 1, you can key in the following statements

Example 3.3

The Output

3.2.8 The CheckBox

The Check Box control lets the user selects or unselects an option. When the Check Box is checked, its value is set to 1 and when it is unchecked, the value is set to 0. You can include the statements Check1.Value=1 to mark the Check Box and Check1.Value=0 to unmark the Check Box, as well as use them to initiate certain actions. For example, the program in Example 3.4 will show which items are selected in a message box.

Example 3.4

The Output

3.2.9 The OptionButton

The OptionButton control also lets the user selects one of the choices. However, two or more Option buttons must work together because as one of the option buttons is selected, the other Option button will be unselected. In fact, only one Option Box can be selected at one time. When an option box is selected, its value is set to “True” and when it is unselected; its value is set to “False”.

Example 3.4

In this example, we want to change the background color of the form according to the selected option. We insert three option buttons and change their captions to 'Red Background','Blue Background' and 'Green Background' respectively. Next, insert a command button and change its name to cmd_SetColor and its caption to 'Set Background Color'. Now, click on the command button and enter the following code in the code window:

Run the program, select an option and click the 'Set Background Color' produces the output, as shown in Figure 3.10.

3.2.10 The Shape Control

In the following example, the shape control is placed in the form together with six OptionButtons. To determine the shape of the shape control, we use the shape property. The property values of the shape control are 0, 1, and 2,3,4,5 which will make it appear as a rectangle, a square, an oval shape, a circle, a rounded rectangle and a rounded square respectively.

Example 3.5

In this example, we insert six option buttons. It is better to make the option buttons into a control array as they perform similar action, i.e to change shape. In order to create a control array, click on the first option button, rename it as MyOption. Next, click on the option button and select copy then paste. After clicking the paste button, a popup dialog (Figure 3.11)will ask you whether you wish to create a control array, select yes. The control array can be accessed via its index value, MyOtion(Index. In addition, we also insert a shape control.

Now, enter the code in the code window. We use the If.Then.Else program structure to determine which option button is selected by the user. You can learn about If.Then.Else in Lesson 7.

Run the program and you can change the shape of the shape control by clicking one of the option buttons. The output is shown in Figure 3.12.

3.2.10 The DriveListBox

The DriveListBox is for displaying a list of drives available in your computer. When you place this control into the form and run the program, you will be able to select different drives from your computer as shown in Figure 3.13

3.2.11 The DirListBox

The DirListBox means the Directory List Box. Drivers navman f series canada 310 tomtom. It is for displaying a list of directories or folders in a selected drive. When you place this control into the form and run the program, you will be able to select different directories from a selected drive in your computer as shown in Figure 3.14

You can coordinate the Drive List Box, the Directory List Box and the File List Box to search for the files you want. The procedure will be discussed in later lessons.


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved Contact Privacy Policy


Popular Posts