Msgboxes
Message boxes are used when you want to ask the user a question or display an error message(s) and advise the user. There are six types of message boxes here are their functions and what they do. Here is the listing of all the possible msgbox events
The Buttons displayed in a message here
Button Layout
| Value
| Short Description |
vbOKonly
| 0
| Displays the OK button. |
vbOKCancel
| 1
| Displays the ok and cancel button. |
vbAbortRetryIgnore
| 2
| Displays the Abort , Retry , Ignore |
vbYesNoCancel
| 3
| Displays Yes , No and Cancel button |
vbYesNo
| 4
| Displays the Yes / No button |
vbRetryCancel
| 5
| Displays the retry and Cancel buttons. |
The Icons dispayed in the message box are here
Icon on message
| Value
| Short Description |
vbCritical
| 16
| Displays critical message icon |
vbQuestion
| 32
| Displays question icon |
vbExclamation
| 48
| Displays exclamation icon |
vbInformation
| 64
| Displays information icon |
The Default button displayed in a message form
Default Button
| Value
| Short Description |
vbDefaultButton1
| 0
| Button 1 is default |
vbDefaultButton2
| 256
| Button 2 is default |
vbDefaultButton3
| 512
| Button 3 is default |
Msgbox Return Value
Return Value
| Value
| Short Description |
vbOk
| 1
| The User Clicked OK |
vbCancel
| 2
| The User Clicked Cancel |
vbAbort
| 3
| The User Clicked Abort |
vbRetry
| 4
| The User Clicked Retry |
vbIgnore
| 5
| The User Clicked Ignore |
VbYes
| 6
| The User Clicked Yes |
VbNo
| 7
| The User Clicked No |
The syntax for use of the message box in Mgsgbox "TEXT", VALUE, "TITLE"
If you want to use two or more tables just add the values together. Therefore to print a message box to say "The Device was not Found!" OK & Explanation :
Source code 1
Private Sub Form_Load()
MsgBox "The Device was not Found!", 48, "Header"
End Sub
Source code 2
Private Sub Form_Load()
MsgBox "The Device was not found!", vbExclamation, "Header"
End Sub
You should get the picture shown below whatever source code you used.

This is a basic msgbox which in this case has not been processed in any way. The following Source code displays a msgbox that ask you for specific text. For example lets make a password program out of this message box.
Private Sub Form_Load()
lngBefore = Timer
Do
strAns = InputBox("What is the password Password is Example", "Password Required")
Loop Until Val(strAns) = Example
lngAfter = Timer
msgbox "Correct Password", vbInformation
End Sub
Once you copy and paste the source code you should get prompted for a password in a different type of msgbox as it includes text. From looking at this example you should be able to see how the loop function works to generate and then check the value. All of the Return Values work in the same way to return an object input.
Opening & Retriving information from files
When applications are loaded they normal get some setting out of the registry or file this section will show you how to retrieve 1 string out of a file.
Private Sub Form_Load()
Dim F As Integer, password As String
F = FreeFile
Open App.Path & "\password.txt" For Input As F
Input #F, password
Close #F
End Sub
As you can see from this source code the password is previously declared as a string. After this is done be sure to close the file otherwise next time you want to store or read the file the computer will think it is being used by another application and windows will not let you do anything with it. So as you can see it is Very Important to close the file
Storing Information to a file
FTP programs often store information to a file such as a username and password or host information in the same way. This following example will put some information into the file.
Private Sub Form_Load()
Dim F As Integer, pass As String
F = FreeFile
save = txtNew
Open App.Path & "\password.txt" For Output As F
Write #F, Text1.text
Close #F
End Sub
Although this is a bit obvious I think I should include it just incase I think differently to other people.
Printing text to the printer.
This is rather easy to do and it gets used in notepad etc...
Private Sub Form_Load()
Printer.Print " The printer will print this text "
Printer.Print ""
Printer.Print " It will leave a line here"
Printer.Print " It should add the contence of text1.text here : " & Text1.Text & " As you can see it works"
Printer.Print ""
Printer.EndDoc 'This will tell the printer it has finished.
End Sub
Everything that apears in position (A) will get printed by the default printer printer.print " A ". The printer enddoc is used to tell the printer the job is finished if this is not added the printer can not estimate how near it will be until it has finish and when it has finished it will think it has'nt so be sure to include this to prevent confusion.
Control Arrays
A control array is a list of controls with the same name. Therefore, instead of using five command buttons with separate five names, you can place a command button control array on the form, and that control array holds five command buttons. The control array can have a single name, and you will distinguish the control from each other with a subscript. One of the best reasons to use control array from that first control, all the elements in the control array take on the same property values, You then can change those properties that need to be changed without having to set every property for each control individually. Control arrays have a lot in common with data arrays. A control array has one array, and you distinguish all the array's controls from each other with the zero-based subscript. ( The index property holds the controls subscript number ). All of the control elements must be the same data type. As soon as you place a control on a form that has the same name as an existing control, Visual Basic makes sure you that you want to begin a control array by issuing the warning message to show that the control is already in use. This is used as a built in safety so that you do not over right an existing control by putting it some where else on the same form. If you answer the warning box with a no button, Visual Basic uses a default control name for the placed control.
Picture Not available at the moment!
All event procedures that use control from a control array require a special argument value passed to them that the determines which control is being worked on. For example if your application contains a single control command button named cmdtotal the click () event begins and ends as follows
Private sub cmdtotal_click()
End Sub
If however you create a control array named the same name as before ( cmdtotal ) it will end up like this
Private sub cmdtotal_click (index as integer)
End sub
The procedure uses the index argument as the control index number ( the subscript ) that the user clicked, Therefore if you want to change the clicked command buttons caption property inside the cmdtotal_click () the procedures you would need are as follows Cmdtoal(index).caption = "A caption name" The index value holds the command button's index the user click to generate the event procedures so you will always respond to the proper control clicked if you use Index after the control array name.
|