Sunday, October 5, 2008

Export Datatable into Text File

Pre Requisite - abc.xls with one sheet with some values in first column

textfile="c:\demo.txt"
Set fso=createobject("scripting.filesystemobject")
Set f=fso.createtextfile(textfile,2)

datatable.Import("C:\abc.xls")
set dg=datatable.GetSheet(1)

x=dg.getparametercount
rc=dg.getrowcount

For i=1 to x
n=dg.getparameter(i).name ' Gives the First coulmn name
Set pmg=dg.getparameter(n)
f.writeline(n)
For j=1 to rc
f.writeline(pmg.valuebyrow(j))
next
Next

Use of Flat File

''''''''Pre requisite---Open A Note Pad and enter some order nos 1 by 1, and Save it as flat.txt in c:\\'''''''''''''''''''''''''

Set z=createobject("scripting.filesystemobject")
Set f=z.opentextfile("c:\flat.txt",1)
While f.atendofline<>true
n=f.readline
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set n
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Wend

Creating Constants

Constants-A constant is a meaningful name that takes the place of a number or string and never changes.
The difference between variable and constant is we can change the variable value in run time
but for constants its not possible.

Creating constants

const str="RAJAPUTRA"

here str is a constant and the value will never change.

We have public and Private constants. By default all are public. If you want specify the type then

Public const str="RAJAPUTRA"
or
Private const str="RAJAPUTRA"

Copying Files and Folders

Set fso=createobject("scripting.filesystemobject")
fso.copyfile"C:/SourceFileName.ext","c:/DestinationFile Name.ext" 'For copying a Files
fso.copyfolder "C:/SourceFolderName","C:/DestinationFolderName" ' For copying a Folders

Copy the Data from One Sheet to Another Sheet

'''Let assume we have a excel file called abc.xls in C drive.
'''In abc.xls we have one sheet with some values.
'''We need to copy first sheet values into second sheet

datatable.Import("c:\abc.xls")
Set src=datatable.GetSheet(1) 'Source Sheet
Set dsc=datatable.GetSheet(2) 'Destination Sheet

pc=src.getparametercount 'Get the Source sheet column count
rc=src.getrowcount 'Get the Source sheet row count

For i=1 to pc
n=src.getparameter(i).name ' Get the Source sheet column name
'msgbox n
Set pmg=src.getparameter(n)
Set pm=dsc.addparameter(n,"")

For j=1 to rc
pm.valuebyrow(j)=pmg.valuebyrow(j)
next
Next

By Value Vs By Reference

Types of arguments in procedures

1. ByVal
2. ByRef


ByVal:

Indicates that the argument is passed by value.

ByRef :
Indicates that the argument is passed by reference.

By default all arguments are 'ByRef'.

Syntax -

Function demo_add(a,b)

demo_add=a+b

End Function

Here a,b are the arguments. By default these are 'ByRef'.

In simple words ByRef Means the value which is assigned to the variable with in the function is permanent and we can use that value out side of that function also.

ByVal means the value which is assigned to the variable with in the function is temporary
and we can use that value only with in that function.

Example:

Function demo_parameters( byref x,byval y)
x=20
y=50
demo_parameters= x+y
End Function

a=10
b=20
msgbox demo_parameters( a,b)
msgbox a
msgbox b


In the above function x and y are the arguments, declared as byref and byval.
With in that function i assigned values to x and y.

Outside of the function i assigned values to two variables and passing those variables in to the function.
'a' is passing reference to x and b is passing value to y.

With in that function i am changing the value for x. This value is permanent for 'a'. Because 'a' is passed as 'ByRef'.

But the value of 'b' will not be changed because it is passed as 'ByVal'.

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.