Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

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

Reverses the order of words (not characters) in a sentence -“Good Morning Everybody” to “Everybody Morning Good”


' Write a program that reverses the order of words (not characters) in a sentence.
'For example, the program should change the sentence “Good Morning Everybody” to “Everybody Morning Good”

StrPR2 = InputBox("String to be Reversed")
SplitStr= Split(StrPR2)
For i = UBound(SplitStr) to 0 Step -1
StrRev=StrRev+" "+SplitStr(i)
Next
MsgBox StrRev

Program to display output in format V, B, S, c,r,i,p,t


'Given a string, write a program that finds out all the characters that constitute the string.
' Example – If the string is VBScript, the output (using a msgbox) should be in this format
' The string VBScript contains variables – V, B, S, c, r, i, p, t

Dim str
str = InputBox("Enterr string to be reversed","Trupti's trial prog")
iLen = Len(str)
For i =1 to iLen
temp=Mid(str,i,1)
RevStr= RevStr+temp+","
Next
msgbox "Reverse string example" &RevStr

Thursday, April 19, 2012

VB Script -Programs

  1. *
    **
    ***
    Please write a code to get output like above diagram.
for i=1 to 3 step 1
  for j=1 to i step 1
    vstr=vstr&"*"
  next
   vstr=vstr&vbnewline
next
msgbox vstr
  1. sunday is sunday
    monday
    tuesday
    wendesday
    sunday
    thursday
    friday
    saturday
    sunday
    sunday

    how to count no of sunday in the text file from vb?
Set fso=createobject("scripting.filesystemobject")
Set forread=fso.OpenTextFile("path\test.txt",1)
text=forread.ReadAll
coun=ubound(split(text,"sunday"))
msgbox coun

3. int a=4857 i need output as 7584.without using any inbuild function?
var=4857 For i=1 to len(var) x=var mod 10 num=num&x var=var/10 var=fix(var) Next msgbox num