1. How to check it is odd or
even?
'Accept a number and display
is it Odd or Even
Dim a
a=inputbox("Enter a
number")
If a mod 2=0 Then
MsgBox "It is Even number"
Else
MsgBox"It is Odd number"
End If
1.
2. Enter a number.
3. Store the result in the
variable ‘a’
4. Check whether a mod 2=0 is
true
5. Display the message ‘it is
even number’
6. Display the message ‘it is
odd number’
2. How to compare strings?
Dim MyString as String =
"Hello World"
Dim OtherString as String =
"Hello World!"
Dim MyInt As Integer =
MyString.CompareTo(OtherString)
Console.WriteLine(MyInt)
Steps:
1. Declare the variable
2. Declare the variable
3. Compare the two variables
4. Display the string
3. To access Send keys method
Set objShell =
CreateObject("WScript.Shell")
objShell.SendKeys
"aaa"
objShell.SendKeys
"{F5}"
objShell.SendKeys "
{F4}"
Steps:
1. Create the object
2. enters the string
"aaa" using keyboard
3. Press F5 button Refresh
4. Close the currently
activated window/browser
4. How to create folder &
sub folder?
'Creating folders and sub
folders
Set
j=CreateObject("Scripting.filesystemobject")
Set
v=j.Createfolder("E:\sai,srss")
1. Create object
2. Create main folder,sub
folder by using create folder
5.how to create data table
& add parameters?
'Data table creat and
parameterand values
s=DataTable.AddSheet("saiganesh").AddParameter("SRSS","ganesh").Name
DataTable.SetCurrentRow(2)
DataTable("SRSS",3)="ramesh"
1.
create datatable
2.
create parameters
3.
assign the value
6. Demonstration of some
predefined function
Dim k
k="saiganesh"
MsgBox Left (k, 3)
MsgBox Right (k, 5)
MsgBox InStr (1,
k,"i")
Len (k)
1.
Defined the
variable and assign the value
2.
using left pre
defined function
3.
using right pre
defined function
4.
Instr function is
used for searching particular char
5.
Len function is
used for count the string length
7.how to add Dictionary
variables?
' Add Method
Dim d
Set d =
CreateObject("Scripting.Dictionary")
d.Add "1",
"Sai"
d.Add "2",
"Ganesh"
d.Add "3",
"SRSS"
For Each i in d
print i
Next
Steps:
1. Create a variable.
2. Create object.
3. Add some keys and items.
4. Add some keys and items.
5. Add some keys and items.
6. Create for loop.
7. Display the keys.
8. How to remove keys and
items?
Dim a, d
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens"
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...
d
.Remove(
"b")
Steps:
1.
Create some
variables.
2. Create object.
3. Add some keys and items.
4. Add some keys and items.
5. Add some keys and items.
6.
Remove second
pair.
9. How to use the items
method?
' Item Method
Dim d
Set d =
CreateObject("Scripting.Dictionary")
d.Add "1",
"Sai"
d.Add "2",
"Ganesh"
d.Add "3",
"SRSS"
t=d.items
For Each i in t
print i
Next
Steps:
1.
Create some
variables.
2.
Create Object.
3. Add some keys and items.
4. Add some keys and items.
5. Add some keys and items.
6.
Get the items.
7.
Print items.
10. How to get keys in
dictionary objects?
' Keys Method
Dim d
Set d =
CreateObject("Scripting.Dictionary")
d.Add "1",
"Sai"
d.Add "2",
"Ganesh"
d.Add "3",
"SRSS"
t=d.keys
For Each i in t
print i
Next
Steps:
1.
Create some
Variables.
2.
Create Object.
3. Add some keys and items.
4. Add some keys and items.
5. Add some keys and items.
6.
Get the keys.
7.
Print items.
11. How to remove all
Dictionary objects?
Dim d
Set d =
CreateObject("Scripting.Dictionary")
d.Add "1",
"Sai"
d.Add "2",
"Ganesh"
d.Add "3",
"SRSS"
t=d.removeall
print t
Steps:
1.
Create some
variables
2.
Create dictionary
object.
3.
Add some keys and
items
4.
Add some keys and
items
5.
Add some keys and
items
6.
Remove all
dictionary objects.
7.
print
12. How add m s word and
store the some text?
Set
k=CreateObject("word.application")
k.visible=true
k.documents.add
k.selection.typetext
"Application"
Print k
Steps:
1.
Create object.
2.
Add ms word
document.
3.
Display the text
into ms word.
13. How to replacing one
character into another character in string?
'Replacing one character to
another character is a string
k="replacing
characters"
i=replace
(k,"a","i")
Print i
Steps:
1.
Create some
variable and string.
2.
Replace the
characters into string.
3.
Print the
replaced string.
14.How to Accept 2 numbers
and displays Arithmetic Calculations
Dim a,b
a=inputbox("Enter a
number")
b=inputbox("Enter a
number")
MsgBox cint (a)+cint(b)
MsgBox a-b
MsgBox a*b
MsgBox a/b
MsgBox a mod b
Steps:
1.
Create some
variables.
2.
Gather the input
values
3.
Display the
addition value
4.
display the sub
value
5.
display the
multiplication value
6.
display the
division value
7.
display the mod
value
15. How to use msgbox key into normal variable.
Dim MsgBox
MsgBox=10
print MsgBox
MsgBox "sai"
Steps:
1.
Create some variables.
2.
Assign some
value.
3.
Print value.
16. How to open IE browser
and invoke the Gmail?
Set
brow=CreateObject("internetexplorer.application")
brow.navigate("http:\\www.gmail.com")
brow.visible=true
Steps:
1.
Create object for
IE browser.
2.
navigate gmail.com
17. How to open excel sheet
& entre value into particular column?
Set
xl=CreateObject("excel.application")
xl.visible=true
Set wb=xl.workbooks.add
Set
ws=wb.worksheets("sheet1")
ws.cells(1,1)="saiganesh"
wb.activesheet.saveas"sai"
Steps:
1.
Create object for
excel.
2.
Check visibility.
3.
Add workbooks
4.
select sheet1
5.
enter value
particular cell
6.
Save this excel
sheet.
18. How display popup window
with “Yes”,” NO”
MsgBox"k",Vbyesno,"sai"
MsgBox"k"
Steps:
1. Display popup window with yes, no
19. How to open word &
write some text & save?
Set
d=CreateObject("word.application")
d.visible=true
d.documents.add
d.selection. typetext
"Sai"
d.activedocument.saveas
"E:\Sai1.doc"
Steps:
1.
Create object for
word.
2.
Add word
documents.
3.
Enter some text
into word document.
4.
save into some
20. How to return specific
weekday name?
Steps:
1.
declare
the variable
2.
use
weekdayname( ) function
3.
displaying the day
Dim a
a=Weekday Name (1)
Msgbox a
Output-Sunday
a=Weekday Name (1)
Msgbox a
Output-Sunday
21.Script to check whether yahoologinpage(www.yahoomail.com)checkbox is checked or not
Set g=Browser("name:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!")
Set obj=Description.Create
obj("html tag").value="INPUT"
obj("Class Name").value="webcheckbox"
obj("type").value="checkbox"
Set a=g.childobjects(obj)
c=a(0).getroproperty("checked")
msgbox(c)
If c=0 Then
msgbox "checkbox is not checked"
else
msgbox"checkbox is checked"
End If
Steps:
1. Create a new description object to use for programmatic descriptions.
2. Create a new description object to use for programmatic descriptions. Store the result in the variables”obj”.
3. Set the properties.
4. Set the child objects. Store into ‘a’ variable.
5. Find to how many checkboxes select and give message.
22.Descriptive Programming for Yahoo Login Page
SystemUtil.Run"iexplore",http://www.yahoomail.com
Set g=Browser("name:=Yahoo.*").Page("title:=Yahoo.*")
g.WebEdit("name:=login").Set "aaa"
g.WebEdit("name:=passwd").SetSecure "bbb"
g.WebButton("name:=Sign In").Click
g.Link("name:=Inbox.*","html
id:=WelcomeInboxFolderLink").Click
g.Link("name:=Sign Out").Click
SystemUtil.Run"iexplore","http://www.yahoomail.com"
statement opens yahoo login page
aaa=username
bbb=password
Steps:
1. Invoke the yahoo mail by using IE browser.
2. Enter the User name.
3. Enter the password.
4. Click Sing In button.
5. Click inbox link button.
6. Click logout button
23. How to select browser and count and close?
Set b=Description.Create
b("text").value="New Tab - Google Chrome"
Set obj=Desktop.ChildObjects(b)
For i=0 to obj.count-1
c=obj(i).getroproperty("name")
obj(i).Close
Next
Step:
1. Create a new description object to use for programmatic descriptions. Store the result in the variables.
2. Set the properties.
3. Store the result in the variable ‘obj’
4. Repeat the following steps one or more times according to the define loop condition.
5. Get the property value.
6. Close the browser.
Creating hyperlinks in Excel file with VBScript
Set O_EXCEL = WScript.CreateObject("Excel.Application")
O_EXCEL.Visible = TRUE
O_EXCEL.Workbooks.Open "C:\1.xlsx"
O_EXCEL.Workbooks(1).Activate
O_EXCEL.Workbooks(1).Worksheets(1).Range("A1").Select
LINK_TO = "http://www.google.com"
O_EXCEL.Workbooks(1).Worksheets(1).Hyperlinks.Add O_EXCEL.Selection, LINK_TO
O_EXCEL.Workbooks(1).Save
O_EXCEL.Quit
set O_EXCEL = nothing
Set O_EXCEL = WScript.CreateObject("Excel.Application")
O_EXCEL.Visible = TRUE
O_EXCEL.Workbooks.Open "C:\1.xlsx"
O_EXCEL.Workbooks(1).Activate
O_EXCEL.Workbooks(1).Worksheets(1).Range("A1").Select
LINK_TO = "http://www.google.com"
O_EXCEL.Workbooks(1).Worksheets(1).Hyperlinks.Add O_EXCEL.Selection, LINK_TO
O_EXCEL.Workbooks(1).Save
O_EXCEL.Quit
set O_EXCEL = nothing
Steps:
1. Create a new object for Excel application.
2. check visibility of object
3. open workbook
4. Activate workbook
5. select the range
6. assign the value into LINK_TO
7. set hyperlink in excel
8. save the workbook
9. Close the excel file.
25.How to copy one excel sheet to another
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set Excel1= objExcel.Workbooks.Open("C:\1.xlsx")
Set Excel2= objExcel.Workbooks.Open("C:\2.xlsx")
Excel1.Worksheets("Sheet1").UsedRange.Copy
Excel2.Worksheets("Sheet1").Range("A1").PasteSpecial -4163
Excel1.save
Excel2.save
Excel1.close
Excel2.close
objExcel.quit
set objExcel=nothing
Steps:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set Excel1= objExcel.Workbooks.Open("C:\1.xlsx")
Set Excel2= objExcel.Workbooks.Open("C:\2.xlsx")
Excel1.Worksheets("Sheet1").UsedRange.Copy
Excel2.Worksheets("Sheet1").Range("A1").PasteSpecial -4163
Excel1.save
Excel2.save
Excel1.close
Excel2.close
objExcel.quit
set objExcel=nothing
Steps:
1. Create a new object for Excel application.
2. check visibility of object
3. Open workbook and set in the excel1
object.
4. Open workbook and set in the excel2
object.
5. Copy the sheet1 information.
6. Paste information into excel2 sheet1.
7. Save excel1.
8. Save excel2.
9. Close the excel1.
10. Close the excel2.
11. Exit excel object.
26.Select case
example
Dim x,y, Operation, Result
x= Inputbox (" Enter x value")
y= Inputbox ("Enter y value")
Operation= Inputbox ("Enter an Operation")
Select Case Operation
Case
"add"
Result=
cdbl (x)+cdbl (y)
Msgbox
"Hello SRSS"
Msgbox
"Addition of x,y values is "&Result
Case
"sub"
Result=
x-y
Msgbox
"Hello SRSS"
Msgbox
"Substraction of x,y values is "&Result
Case
"mul"
Result= x*y
Msgbox
"Hello SRSS"
Msgbox
"Multiplication of x,y values is "&Result
Case
"div"
Result= x/y
Msgbox
"Hello SRSS"
Msgbox
"Division of x,y values is "&Result
Case
"mod"
Result=
x mod y
Msgbox
"Hello SRSS"
Msgbox
"Mod of x,y values is "&Result
Case
"expo"
Result= x^y
Msgbox
"Hello SRSS"
Msgbox"Exponentation
of x,y values is "&Result
Case Else
Msgbox
"Hello SRSS"
msgbox
"Wrong Operation"
End Select
Step:
- Declare new variable x, y, Operation, Result.
- Gather the input values from x,y
- Gather the any operator (add, sub, mul….)
- Create select statement.
- Create cases for Add.
- Do the add operation and store into ‘result’ variable.
- Display message box
- Create cases for Sub.
- Do the add operation and store into ‘result’ variable.
- Display the message box
- Create cases for Sub.
- Do the add operation and store into ‘result’ variable.
- Display the message box
- Create cases for Mul.
- Do the add operation and store into ‘result’ variable.
- Display the message box
- Create cases for Div.
- Do the add operation and store into ‘result’ variable.
- Display the message box
- Create cases for Mod.
- Do the add operation and store into ‘result’ variable.
- Display the message box
- Create cases for else.
- Display the message.
- Display the message box
- End select statement.
27. Read two numbers and display the sum?
Dim num1, num2, and sum
num1=inputbox ("Enter num1")
num2=inputbox ("Enter num2")
Sum= Cdbl (num1) + Cdbl (num2)
msgbox ("Sum is " &sum)
Steps:
1. Declare a variable for number1, number2, and sum.
2. Gather the value number1
3. Gather the value number2
4. Add the two numbers.
5. Display the message.
28.Read P, T, R values and Calculate the Simple Interest?
Dim p,t, r, si
p=inputbox ("Enter Principle Amount")
t=inputbox ("Enter Time")
r=inputbox ("Enter Rate of Interest")
si= (p*t*r)/100 '
p= principle amount, t=time in years, r= rate of interest
Msgbox ("Simple Interest
is " &si)
Steps:
1. Declare a variable p, t, r, si
2. Gather input value for amount.
3. Gather input value for time in years.
4. Gather input value for interest rate
5. Calculate the total interest.
6. Display the message.
29.Read any four digit number and display the number in reverse
order?
Dim num, rev
Num= inputbox ("Enter a number")
If len(num)=4 Then
Rev=rev*10 + num mod 10
num=num/10
num= left(num,3)
rev=rev*10 + num mod 10
num=num/10
num= left(num,2)
rev=rev*10 + num mod 10
num=num/10
num= left(num,1)
Rev=rev*10 + num mod 10
Msgbox
"Reverse Order of the number is "&rev
Else
Msgbox
"Number, you entered is not a 4 digit number"
End If
Steps:
1. Declare a new variable for num,rev
2. Gather the input value and store into num
variable.
3. Create the if condition.
4.
30.Minimum marks 35 for any subject, otherwise
'no grade fail'
Dim e,m,p,c, tot
e=inputbox ("Enter english Marks")
m=inputbox ("Enter maths Marks")
p=inputbox ("Enter physics Marks")
c=inputbox ("Enter chemistry Marks")
tot= cdbl(e) + cdbl(m) + cdbl(p) + cdbl(c)
msgbox tot
If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35 and
cdbl(c) >=35 and tot >=300 Then
msgbox "Grade
is Distinction"
else If cdbl(e) >=35 and
cdbl(m) >=35 and cdbl(p) >=35 and cdbl(c) >=35 and tot >=240 and
tot<300 Then
msgbox "Grade
is First"
else If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35
and cdbl(c) >=35 and tot >=200 and tot<240 Then
msgbox "Grade
is Second"
else If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35
and cdbl(c) >=35 and tot >=160 and tot<200 Then
msgbox "Grade
is Third"
else
msgbox "No Grade, Fail"
End If
End If
End If
End If
Steps:
1.
Declar
the variables e,m,p,c, tot.
2.
Entre
the English marks.
3.
Entre
the maths marks.
4.
Entre
the physics marks.
5.
Entre
the chemistry marks.
6.
add
the total marks and store into tot variable.
7.
create
the if condition.
8.
display
the message.
9.
create
the if condition.
10.
display
the message.
11.
create
the if condition.
12.
display
the message.
13.
create
the if condition.
14.
display
the message.
15.
end
if condition
16.
end
if condition
17.
end
if condition.
31.A script to open, display and close a
PDF file using QTP.
Option Explicit
Dim accapp, acavdocu
Dim pdf_path
pdf_path = "C:\QTP_PAM.pdf"
Set accapp = CreateObject( "AcroExch.App" )
accapp.Show()
Set acavdocu = CreateObject( "AcroExch.AVDoc" )
acavdocu.Open pdf_path, "MyTitle" wait 0, 200
accapp.CloseAllDocs()
accapp.Exit()
Set accapp = Nothing : Set acavdocu = Nothing
Steps:
1. Declare the variables accapp, acavdocu,
pdf_path
2. Assign the path into variable pdf_path.
3. Initialize Acrobat by creating App object
('AcroExch.App is the Acrobat application)
4. Shows the Acrobat application.
5. Create one AVDoc object per displayed
document
6. Open the PDF by using pdf_path.
7. Close the all documents.
8. Exit Acrobat application
32. Script to get the list of links in Google and do spell check
Dim d
set mw=CreateObject("Word.Application")
set d=Description.Create
d("micclass").value="Link"
set a=Browser("Google").page("Google").childobjects(d)
for i=0 to a.count-1
mw.WordBasic.filenew
s=a(i).getROProperty("innertext")
mw.WordBasic.insert s
if mw.ActiveDocument.Spellingerrors.count>0 then
Reporter.ReportEvent 1,"Spelling","spelling error :"&s
end if
mw.ActiveDocument.Close(False)
next
mw.quit
set mw=nothing
set mw=CreateObject("Word.Application")
set d=Description.Create
d("micclass").value="Link"
set a=Browser("Google").page("Google").childobjects(d)
for i=0 to a.count-1
mw.WordBasic.filenew
s=a(i).getROProperty("innertext")
mw.WordBasic.insert s
if mw.ActiveDocument.Spellingerrors.count>0 then
Reporter.ReportEvent 1,"Spelling","spelling error :"&s
end if
mw.ActiveDocument.Close(False)
next
mw.quit
set mw=nothing
Steps:
1. Declare a variable‘d’.
2. Create an object ‘mw’ for word
application.
3. Create an object‘d’.
4. Set the property in ‘d’ object for link.
5. Create object a for child object.
6. Create for loop.
7. Create new file.
8. get inner text property value and store into
s variable
9. Insert the value into new file.
10.
Create
if condition and check spellings.
11.
Print
report for spelling error.
12.
end
if condition
13.
Close
the word document.
14.
Set
next statement for for loop.
15.
Close
the documents.
16.
Set
object nothing.
33. Function to send a mail
Function SendMail(SendTo, Subject, Body, Attachment)
Set otl=CreateObject("Outlook.Application")
Set m=otl.CreateItem(0)
m.to=SendTo
m.Subject=Subject
m.Body=Body
If (Attachment <>
"") Then
Mail.Attachments.Add(Attachment)
End If
m.Send
otl.Quit
Set m = Nothing
Set otl = Nothing
End Function
Call
SendMail("srss.srss46@gmail.com","hi","This is test mail
for tsting","")
Steps:
1. Create function for send mails.
2. Set object for outlook application.
3. Set object for item.
4. Assign the variables ‘sendto’.
5. Assign the variables ‘body’.
6. Create if condition.
7. Create attachments.
8. End if condition.
9. Send mail.
10.
Close
the out look application.
11.
Set m
object empty.
12.
Set
otl object empty.
13.
end
function
14.
call sendmail function
34. Open Internet Explorer and navigate to yahoo mail
Dim ie
Set ie=CreateObject("InternetExplorer.Application")
ie.Visible=True
ie.Navigate "www.yahoomail.com"
x=Browser("CreationTime:=0").GetROProperty("title")
msgbox x
steps:
1. declare an variable for InternetExplorer
‘ie’
2. Create object for
InternetExplorer.Application.
3. Check visibile property.
4. Navigate yahoomail.com.
5. Create variable x for getting title
prpperty value.
6. Display the message box.
35.Function for Counting Objects from any opened web page
Function Objects_Count(myObject)
Dim Objects
Set Objects=Description.Create
Objects("micclass").value=myObject
Set
Object=Browser("title:=.*").Page("title:=.*").ChildObjects(Objects)
TotObjects=Object.Count
Msgbox TotObjects
End Function
Call Objects_Count("WebButton")
Steps:
1. Create function for objects count.
2. Declare variable objects.
3. Set object for description programming.
4. Assign properties for object.
5. set object description to find
6. Count total object.
7. Display total objects count in message
box.
8. End function.
9. Call function object_count.
36.Count all opened Browsers on desktop and close them all?
Set oDesc = Description.Create()
oDesc("micclass").Value = "Browser"
Set Browsers =Desktop.ChildObjects (oDesc)
NumberofBrowsers = Browsers.Count()
Reporter.ReportEvent 2,"Res","Number of Browsers are:
"&NumberOfBrowsers
For Counter=0 to NumberofBrowsers-1
Browsers(Counter).Close
Next
37.Verify whether the 'Gmail' link available or not on Google Homepage
Option explicit
Dim oLink, Links, TotLinks, i, myLink
Set oLink = description.Create
oLink("micclass").value = "Link"
SystemUtil.Run "D:\Program Files\Internet Explorer\IEXPLORE.EXE"
set Links = Browser("name:=Google").page("title:=Google").ChildObjects(oLink)
TotLinks = Links.count
For i =0 to TotLinks-1
myLink = Links(i).getroproperty("innertext")
If mylink = "Gmail" Then
reporter.ReportEvent 0,"res","Link Gmail available"
End If
Next
Option explicit
Dim oLink, Links, TotLinks, i, myLink
Set oLink = description.Create
oLink("micclass").value = "Link"
SystemUtil.Run "D:\Program Files\Internet Explorer\IEXPLORE.EXE"
set Links = Browser("name:=Google").page("title:=Google").ChildObjects(oLink)
TotLinks = Links.count
For i =0 to TotLinks-1
myLink = Links(i).getroproperty("innertext")
If mylink = "Gmail" Then
reporter.ReportEvent 0,"res","Link Gmail available"
End If
Next
38.Count how many links available in a Web Page(any web page,
using Regular Expressions)
Dim oLink,Links, TotLinks
Set oLink=Description.Create
oLink("micclass").value="Link"
Set Links=Browser("title:=.*").page("title:=.*").ChildObjects(oLink)
TotLinks=Links.count
msgbox TotLinks
Reporter.ReportEvent 2,"Res","Total Links are: "&TotLinks
Dim oLink,Links, TotLinks
Set oLink=Description.Create
oLink("micclass").value="Link"
Set Links=Browser("title:=.*").page("title:=.*").ChildObjects(oLink)
TotLinks=Links.count
msgbox TotLinks
Reporter.ReportEvent 2,"Res","Total Links are: "&TotLinks
steps:
1. Declare a
variables.
2. Create
objects for description programming.
3. set
properties for link.
4. create child
object for link and store into links object.
5. count no. of
links and store into totlinks.
6. display the
message total links count.
7. print report
into output page.
39.Minimum marks 35 for any subject, otherwise
'no grade fail')
Dim e,m,p,c, tot
e=inputbox ("Enter english Marks")
m=inputbox ("Enter maths Marks")
p=inputbox ("Enter physics Marks")
c=inputbox ("Enter chemistry Marks")
tot= cdbl(e) + cdbl(m) + cdbl(p) + cdbl(c)
msgbox tot
If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35 and
cdbl(c) >=35 and tot >=300 Then
msgbox "Grade
is Distinction"
else If cdbl(e) >=35 and
cdbl(m) >=35 and cdbl(p) >=35 and cdbl(c) >=35 and tot >=240 and
tot<300 Then
msgbox "Grade
is First"
else If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35
and cdbl(c) >=35 and tot >=200 and tot<240 Then
msgbox "Grade
is Second"
else If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35
and cdbl(c) >=35 and tot >=160 and tot<200 Then
msgbox "Grade
is Third"
else
msgbox "No Grade, Fail"
End If
End If
End If
End If
Steps:
1.
Declare
the variables for English, maths, physics, chemistry,Total.
2.
Gather
the input value and store into e variable.
3.
Gather
the input value and store into m variable.
4.
Gather
the input value and store into p variable.
5.
Gather
the input value and store into c variable.
6.
Calculate
total marks and store into tot variable.
7.
Display
the total marks.
8.
Set
if condition for minimum pass and total marks.
9.
Display
the message Grade is Distinction.
10.
Set
else condition.
11.
Set
if condition for minimum pass and total marks.
12.
Display
the message Grade is First.
13.
Set
else condition.
14.
Set
if condition for minimum pass and total marks.
15.
Display
the message Grade is second.
16.
Set
else condition.
17.
Set
if condition for minimum pass and total marks.
18.
Display
the message Grade is Third.
19.
Set
else condition.
20.
Display
the message Grade is Fail.
21.
End
if condition.
22.
End
if condition.
23.
End
if condition.
24.
End
if condition.
40.Display Odd numbers up to n?
Dim num,n
n=Inputbox ("Enter a Vaule")
For num= 1 to n step 2
msgbox num
Next
Steps:
1. Declare variables number, n
2. Gather input value and store into n
variable.
3. Set for loop.
4. Display message for num.
5. set next condition for loop.
41. Display Even numbers up to n?
Dim num,n
n=Inputbox ("Enter a Vaule")
For num= 2 to n step 2
msgbox num
Next
Steps:
1. Declare a
variable num,n
6. Gather input value and store into n
variable.
7. Set for loop.
8. Display message for num.
9. Set next condition for loop.
42.display natural numers up to n and write in a text file?
Dim num, n, fso, myfile
n= inputbox ("Enter any Value")
num=1
For num= 1 to n step 1
Set fso= createobject ("scripting.filesystemobject")
set myfile=fso.opentextfile ("E:\srss.txt", 8, true)
myfile.writeline num
myfile.close
Next
Steps:
1.
Declare a variable num, n, fso, and myfile.
2.
Gather
input value and store into n variable.
3.
Set
num value is 1.
4.
Set
for loop.
5.
Set
object for filesystemobject.
6.
Open
text file as path
7.
Write
the line in that file.
8.
Close
file.
9.
set
next for loop.
43.Display Natural numbers in reverse order up to n?
Dim num,n
n=Inputbox ("Enter a Vaule")
For num=n to 1 step -1
msgbox num
Next
Steps:
1. Daclare variable num, n.
2. Gather input value and store into n
variable.
3. Set for loop.
4. Display the message.
5. set the next condition for loop.
44.Display Natural numbers sum up to n? (using For...Next Loop)
Dim num, n, sum
n= inputbox ("Enter a Value")
sum=0
For num= 1 to n step 1
Sum= sum+num
Next
msgbox sum
Steps:
1.Daclare variable num, n.
2.Gather input value and store into n
variable.
3.Set value 0 into sum variable.
4.set for loop.
5.Calculate total sum.
6.set the next condition for loop
7.Display the message
45. Display Natural numbers sum up to n? (using While...Wend Loop)
Dim num, n, sum
n= inputbox ("Enter a Value")
While num <=cdbl (n)
sum= sum+num
num=num+1
Wend
msgbox sum
steps:
1. Declare a variable num,n,sum.
2. Gather input value and store into n.
3. Create while loop.
4. Do the add operation and store the value
into sum variable.
5. Increment num into 1.
6. Set the wend statement.
7. Display the sum message
46. Display Natural numbers sum up to n? (using Do...Until...Loop)
Dim num, n, sum
N= inputbox ("Enter a Value")
Sum=0
Num=1
Do
Sum= sum+num
Num=num+1
Loop Until num =cdbl (n+1)
msgbox sum
Steps:
1. Declare a variable num, n, sum
2. Gather input value and store into n.
3. Set sum value to 0
4. Set num value into 1.
5. Starts do loop.
6. Do the add operation for sum and num and
store the value into sum variable.
7. Starts loop until condition.
8. Display sum message.
47. Write a Function for Natural Numbers sum up to n?
Function NNumCou (n)
Dim num, sum
Sum=0
For num= 1 to n step 1
Sum= sum+num
Next
msgbox sum
End Function
Steps:
1.
Create
function for NnumCou.
2.
Declare
the variables num, sum.
3.
Set
sum value into 0.
4.
Start
for loop.
5.
Do
the add operation and store into sum value.
6.
Set next
statement.
7.
Display
sum value in message.
8. end function
48.Insert Data into a database table using Database Command Object
Dim objCon,objCom
Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SRSS.mdb;"
Set objCom=Createobject("ADODB.Command")
objCom.ActiveConnection=objCon
objCom.CommandText="insert into Emp values('srss',88233,30000)"
objCom.Execute
objCon.Close
Set objCom=Nothing
Set objCon=Nothing
Dim objCon,objCom
Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SRSS.mdb;"
Set objCom=Createobject("ADODB.Command")
objCom.ActiveConnection=objCon
objCom.CommandText="insert into Emp values('srss',88233,30000)"
objCom.Execute
objCon.Close
Set objCom=Nothing
Set objCon=Nothing
Steps:
1. Declare the
variable connection, command.
2. Set object
for ADODB Connection.
3. Set provider
name and source details.
4. Set object
for ADODB command.
5. Activate
connection.
6. Insert the
values into EMP table.
7. Excute the
command.
8. close the
connection.
9. set command
object empty.
10.
set connection object empty.
49.Executing a certain block of statements when two / more
conditions are True (Nested If...)
Dim State, Region
State=Inputbox ("Enter a State")
Region=Inputbox ("Enter a Region")
If state= "AP” Then
If Region= "Telangana" Then
msgbox "Hello SRSS"
msgbox "Dist count is 10"
Else if Region= "Rayalasema" Then
msgbox "Hello GCR"
msgbox "Dist count is 4"
Else If Region= "Costal" Then
msgbox "Hello Chandra mohan Reddy"
msgbox "Dist count is 9"
End If
End If
End If
End If
Steps:
1. Declare variables
for state, region.
2. Gather the
input value and store into variable state.
3. Gather the
input value and store into variable region.
4. Set if
condition for state is AP.
5. Set if
condition for region is Telangana.
6. Display
message
7. Display
message for districts.
8. Set else
condition.
9. Set if
condition for checking region is Rayalasema.
10.
Display message
11.
Display message for districts count.
12.
Set else condition.
13.
Set if condition for checking region is Costal.
14.
Display message
15.
Display message for districts.
16.
End if condition.
17.
End if condition.
18.
End if condition.
19.
End if condition.
50.Deciding Between Several Alternatives
Dim x
x= Inputbox (" Enter a value")
If x>0 and x<=100 Then
Msgbox "Hello SRSS"
Msgbox "X is a Small Number"
Msgbox "X value is "&x
Else IF x>100 and x<=500 Then
Msgbox "Hello SRSS"
Msgbox "X is a Medium Number"
Else IF x>500 and x<=1000 Then
Msgbox "Hello SRSS"
Msgbox "X is a Large Number"
Else
Msgbox "Hello Sir"
Msgbox "X is a Grand Number"
End If
End If
End If
Steps:
1. Declare a variable x.
2. Gather the input value.
3. Set if condition for x limitations.
4. Display the massage.
5. Display the x value is small number.
6. Display the x value.
7. Set else condition.
8. Set if condition for x limitations.
9. Display the hello message.
10. Display the x value is Medium Number.
11. Display the x value.
12. Set else statement.
13. Set if condition for x limitations.
14. Display the hello message.
15. Display the x value is Large Number.
16. Display the x value.
17. Set else statement.
18. Display the hello message.
19. Display the x value is Grand Number.
20. End if condition.
21. End if condition.
22. End if condition.
51.Write a program for finding out whether the given year is a leap year or not?
Dim xyear
xyear=inputbox ("Enter Year")
If xyear mod 4=0 Then
msgbox "This is a Leap year"
Else
msgbox "This is NOT"
End If
Steps:
1. Declare a variable for leap year.
2. Gather input value and store into xyear variable.
3. Set if condition
4. Display message for Leap year.
5. Set else condition.
6. Display message for not Leap year.
7. end if condition.
52.Read Four digit number,
calculate & display the sum
of the number or display Error message if the number is not a four digit
number?
Dim num, sum
num=inputbox ("Enter a Four digit number")
If Len(num) = 4 Then
sum=0
sum=sum+num mod 10
num=num/10
num=
left (num, 3)
sum=sum+num mod 10
num=num/10
num=
left (num, 2)
sum=sum+num mod 10
num=num/10
num=
left (num, 1)
sum=sum+num mod 10
msgbox ("Sum is "
&sum)
else
msgbox "Number, you entered is not a 4 digit number"
End If
Steps:
1.
Declare
a variable for number, sum.
2.
Gather
input value and store into num variable.
3.
Set
if condition.
4.
Set
sum equal to zero.
5.
Calculate
value and store into sum variable.
6.
Calculate
value and store into sum variable.
7.
Calculate
value and store into sum variable.
8.
calculate
value and store into sum variable.
9.
Display
the message for sum.
10.
display
the message for not 4 digit number.
11.
end
if condition.
No comments:
Post a Comment