Friday, July 5, 2013

VBA Tools and Techniques – VBA Tips

Leave a Comment
Developing an Application requires the technique. Unlike the other language, VBA is a language that is special for Microsoft Office Application, which is built by Microsoft. The technique in VBA is the quite the same as programming by Microsoft likes VB.net, C#. For Visual Basic Application (VBA), it requires four steps to start with. These techniques include designing an interface, setting property to each control, implementing or coding, and testing.

Designing an interface:
Designing interface is important. It helps you to know what you will deal with. In order to design an interface you should know some controls that exist in the controls group.

Here is some basic control
Text Box control, sometime called an edit field or edit control, displays the information entered at design time, entered by user, or assign to the control at run time.
Label is a graphical controlthat you can use to display text that a user cannot change directly.
Command Button control is used to begin, interrupt, or end a process, when chosen; A Command Button appears pushed in and so is sometime called a push button.
Combo Box control is the same as textbox except it provide user to select data from the list for inputting without typing
List Box is use to display data in a list.
Option Group: use for grouping data or function.
Option Button uses grouping data that user select only one from that values. Option Button is true when it is selected otherwise is false.
Check Box is similar to option Button but user can select more than one.
Image Box is used to display image

Setting Property to Each Control
Setting Property is the step where you name or object within your interface. Setting Property helps you to know what your object is and the name of your object is easy to remember. In order to setting property you need the conversion of object name. The following is the most common conversion in VBA.
Object
Prefix
Example
Form
frm
frmSum
CommandButton
cmd
cmdSum
Label
lbl
lblInputX
Text Box
txt
txtResult
Check Box
chk
chkOption
Menu
mnu
mnuEdit


Implementing (Coding)
Coding is to add event or procedure to you controls. This event can be Button click event, mouse drag and drop, text change… etc For example:
.Private Sub cmdSum_Click()
   txtSum = CInt(txtInputX.Text) + CInt(txtInpuY.Text)
End Sub

Testing and Debug code
Testing is the step that you must do to find all bugs in your code. In the Testing Step, you can see errors and how your code work through intermediate window and Watch window in the VBA Editor Explorer.

Example Design interface and Setting Properties
1. Start with new form object

2. Start Drawing Some Control
3. Setting Properties to each control
Form1
Name
frmSum
Caption
Sum Two Number

Label1
Name
lblInputX
Caption
InputX

Label2
Name
lblInputY
Caption
InputY

Label3
Name
lblResult
Caption
Result

TextBox1
Name
txtInputX

TextBox2
Name
txtInputY

TextBox3
Name
txtResult

CommandButton1
Name
cmdSum
Caption
Sum

CommandButton2
Name
cmdCancel
Caption
Cancel


After that, our form would look like the following form


In summary, VBA require you to know how to deigning interface, setting property to control, and implementing or coding so that you can easily work with VBA. 

0 comments :

Post a Comment

DMCA.com Protection Status