1 May 2013

VB Script General Examples


'Print the odd numbers upto n

Dim num,n

n=inputbox("enter a number")

For num=1 to n step 2

print num

Next

'Print the even numbers upto n

Dim num,n

n=inputbox("enter a number")

For num=2 to n step 2

print num

Next


'Display natural numbers upto n and write into textfile


Dim num,n,fso,myfile

n=inputbox("enter a number")

For num=1 to n step 1

Set fso=createobject("scripting.filesystemobject")

Set myfile=fso.OpenTextFile("D:\naturalnumbers.txt",8, true)

myfile.WriteLine num

myfile.Close

Next

'Display natural numbers in reverse order upto n


Dim num,n

n=inputbox("enter a number")

For num=n to 1 step -1

print num

Next


'Display natural numbers sum upto n using for loop?

Dim num,n

sum=0

n=inputbox("enter a number")

For num=1 to n step 1

sum=sum+num

print sum

Next


Verify weather the entered value is a 10 digit value or not and  numeric value or not?

num=InputBox("Enter a Phone Number")

a1=left(num,1)

a10=right(num,1)

a2=mid(num,2,1)

a3=mid(num,3,1)

a4=mid(num,4,1)

a5=mid(num,5,1)

a6=mid(num,6,1)

a7=mid(num,7,1)

a8=mid(num,8,1)

a9=mid(num,9,1)

If len(num)=10 Then

If isnumeric(a1)="True" and  isnumeric(a2)="True" and  isnumeric(a3)="True" and  isnumeric(a4)="True" and  isnumeric(a5)="True" and  isnumeric(a6)="True" and  isnumeric(a7)="True" and  isnumeric(a8)="True" and  isnumeric(a9)="True" and  isnumeric(a10)="True" Then

msgbox "it is a numeric value"

End If

End If

If len(num)<>10 Then

msgbox "it is not a valid number"

End If


'Generate intrest for 1 to 5 years( for 1 year -2%, for 2 year-3%,for 3 year-4%,for 4 year-5% and 5 year-6%)

Dim amount,duration,intrest

amount=inputbox("enter amount")

If amount<10000 Then

msgbox "low amount"

else

For i=1 to 5

If duration=1 Then

intrest=(amount*2*12)/100
msgbox "1 year intrest is: " &intrest

else if duration=2 then
intrest=(amount*3*24)/100
msgbox "2 year intrest is: " &intrest

else if duration=3 then
intrest=(amount*4*36)/100
msgbox "3  year intrest is: " &intrest

else if duration=4 then
intrest=(amount*5*48)/100
msgbox "4 year intrest is: " &intrest

else if duration=5 then
intrest=(amount*6*60)/100
msgbox "5 year intrest is: " &intrest

else

msgbox "invalid data"

End If
End If
End If
End If
End If
Next

End If







No comments:

Post a Comment