Best Practices in QTP
1. Use comments liberally. It is helpful in every section to identify what is being done and how you intend to do it. This makes it much easier for people to understand what the test intends to do.
2. Fname, Lname, Country, Gender are not good names for datatable columns. See http://prosoftqa.blogspot.com/2006/04/logical-names-updated-410.html for an article about naming.
3. FN, LN etc are not good variable names. Absolutely avoid the use of such variable names as i, j, k. The reasons for this should be obvious.
4. It is always a good idea to define your variables at the top of your test and specify what type of data you intend to store into them.
E.g.
Dim strCountry 'Stores the name of the country
5. The Msgbox function should absolutely never be in a test. An automated test is designed to run with unattended execution. Using this function pauses the test and waits for user interaction. If you want to preserve log messages during your test, try the Reporter.ReportEvent method.
6. Never use the Inputbox function in a test. Your data should always be either
a. Hard-coded - Simple but not flexible
b. Parameterized - Best option since your datatable is editable through any spreadsheet tool.
7. Always indent your code. The interpreter does not care if you don't indent but humans do. Don't forget that during the lifetime of your code, someone else may be charged with updating it. Without proper indentation, it is difficult to figure out what the code below is doing:
If blnTest=True Then
strMessage="Passed"
If numCount=2"
strMessage = strMessage & " again."
End If
Else
strName="Failed"
End If
The following is easier to read:
If blnTest=True Then
strMessage="Passed"
If numCount=2"
strMessage = strMessage & " again."
End If
Else
strName="Failed"
End If