Thursday, September 20, 2012

Factorial Function

'Factorial of number


Function factorial(no)

Dim fact
fact=1

For i=1 to no

fact=fact*I

Next

factorial=fact

End Function

num=inputbox("Enter number")

msgbox "Factorial is" &factorial(num)

Friday, September 14, 2012

String is palindrome or not

'string is palindrome or not
str=Inputbox ("enter string")
revstr=strreverse(str)
If str=revstr Then
    msgbox "string is palindrome"
else
    msgbox "string is not palindrome"
End If

Find Square of Number

' Program to square of number
num=inputbox ("Enter number","Square of number")
square=num*num
msgbox "Square of number is " &square

Example of LCASE function- “AuTOMatIon123_!@#” and 'convert all the upper case letter to lower case like “automation123_!@#”.


'Write a program that mimics the functionality of LCase function.
' For example, your program should take any variable like “AuTOMatIon123_!@#” and
'convert all the upper case letter to lower case like “automation123_!@#”.

'Code
Str = InputBox("String to be lowered")
diff = Asc("a") - Asc("A")

For i = 1 to Len(Str)
If Asc(Mid(Str,i,1))<=Asc("Z") And Asc(Mid(Str,i,1))>=Asc("A")Then
    If Asc(Mid(Str,i,1)) = Asc(" ") Then
    StrLower= StrLower + Mid(Str,i,1)
    End If
    temp= chr(Asc(Mid(Str,i,1))+diff)
    StrLower= StrLower+temp
Else
    StrLower= StrLower + Mid(Str,i,1)
End If
Next
MsgBox StrLower
'End Code