Sunday, May 23, 2010

How to create class and constructor using VBScript

Class sampleClass
Private str

Private sub Class_Initialize()
msgbox("I am constructor")
End Sub

Private sub Class_Terminate()
msgbox("I am destructor")
End Sub

Public function setString(strVar)
str=strVar
End Function

Public function getString()
getString=str
End Function
End Class

Set strObj= New sampleClass
strObj.setString("Uday")
temp=strObj.getString
msgbox(temp)

How to execute a stored procedure using vbscript

conStr="driver=sql server;server=ServerName;database=test;uid=sa;pwd=sa" 'This is my connection string
Set cmdObj=createobject("adodb.command")
Set recObj=createobject("adodb.recordset")
With cmdObj
.activeconnection=conStr
.commandtype=4
.commandtext="SP_Insert_EMP" 'This is my SP name
.parameters.refresh
.parameters(1).value=22 'These are input parameters for SP
.parameters(2).value="xyz"
.execute 'The SP will be executed after this statement
End with

Tuesday, May 18, 2010

Script to reverse a number in vbscript

num=inputbox("Enter a number")
result=0
While num>0
digit=num mod 10
num=int(num/10)
result=result*10+digit
Wend
msgbox result

Find largest and smallest values in an array

Dim arr(6)
arr(0)=44
arr(1)=32
arr(2)=99
arr(3)=7
arr(4)=10
arr(5)=1
arr(6)=6
'Finding the largest
largest=arr(0)
For i=1 to ubound(arr)
If largest largest=arr(i)
End If
Next
msgbox largest

'Finding the smallest
smallest=arr(0)
For i=1 to ubound(arr)
If smallest>arr(i) Then
smallest=arr(i)
End If
Next
msgbox smallest

Thursday, May 13, 2010

What are DDL, DML, DCL and TCL in Database

Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:

* CREATE - to create objects in the database
* ALTER - alters the structure of the database
* DROP - delete objects from the database
* TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
* COMMENT - add comments to the data dictionary
* RENAME - rename an object

Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:

* SELECT - retrieve data from the a database
* INSERT - insert data into a table
* UPDATE - updates existing data within a table
* DELETE - deletes all records from a table, the space for the records remain
* MERGE - UPSERT operation (insert or update)
* CALL - call a PL/SQL or Java subprogram
* EXPLAIN PLAN - explain access path to data
* LOCK TABLE - control concurrency

Data Control Language (DCL) statements. Some examples:

* GRANT - gives user's access privileges to database
* REVOKE - withdraw access privileges given with the GRANT command

Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.

* COMMIT - save work done
* SAVEPOINT - identify a point in a transaction to which you can later roll back
* ROLLBACK - restore database to original since the last COMMIT
* SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

Tuesday, May 11, 2010

How to reverse a string using vbscript

str="uday"
For i=len(str) to 1 step -1
strchar=mid(str,i,1)
resultstr=resultstr&strchar
Next
msgbox resultstr

or you can use the built-in function in vbscript
msgbox strreverse("uday")

Friday, May 7, 2010

How to check text displayed in a image

Use "GetTextLocation" method to Checks whether a specified text string is contained in a specified window area. If the text string is located, the location coordinates are also returned.

TextUtil.GetTextLocation(TextToFind, hWnd, Left, Top, Right, Bottom[, MatchWholeWords])

TextToFind : The text string you want to locate
hWnd : The handle to a run-time object's window(If hWnd is not 0, then the coordinate arguments apply to the specified window. If hWnd is 0, the coordinates apply to the screen.)
Left, Top, Right, Bottom : These arguments define the search area within the window or screen. Set all coordinates to -1 to search for the text string within the entire window or screen. The method returns the coordinates of the rectangle containing the first instance of the text into these variables if the text is found.

MatchWholeWordOnly : Optional. If True, the method searches for occurrences that are whole words only and not part of a larger word. If False, the method does not restrict the results to occurrences that are whole words only.
Default value = True

Script:

l = -1
t = -1
r = -1
b = -1

Succeeded = TextUtil.GetTextLocation("your search text",0,l,t,r,b)
msgbox Succeeded

Work with dictionary objects

Set dictObj=createobject("Scripting.Dictionary")
dictObj.Add "name","Uday"
dictObj.Add "tech","qa"
dictObj.Add "loc","hyd"
dictObj.Key("loc")="location"
msgbox dictObj.Item("location")
msgbox dictObj.Count

How do you create classes and objects using vbscript

Class math

Public function addition(a,b)
addition=a+b
End Function

Public function substraction(a,b)
substraction=a-b
End Function
End Class

Set mathObj=new math
msgbox mathObj.addition(2,5)
msgbox mathObj.substraction(9,3)
Set mathObj=nothing

Monday, May 3, 2010

Write a script to find out the number of links displayed in a web page

Set linkObj=description.Create
linkObj("micclass").value="link"

Set linkchildObjs=browser("xxx").Page("yyy").ChildObjects(linkObj)

childCount=linkchildObjs.count

For i=0 to childCount-1
msgbox linkchildObjs(i).getROProperty("innertext")
Next

If you want to click on the last link on that page:
browser("xxx").Page("yyy").link("index:="&childCount-1).click

Set linkObj=nothing


Following is the code to check all checkboxes:
Set cbObj=description.Create
cbObj("html tag").value="INPUT"
cbObj("type").value="checkbox"

set childObj=browser("xxx").Page("yyy").ChildObjects(cbObj)

For i=0 to childObj.count-1
childObi(1).set "ON"
Next