You are on page 1of 5

Find the factorial of a number using vb script vb script program to find the factrial of a given number n=cint(inputbox(Enter a number))

) dim f f=1 if n<0 then msgbox Invalid number elseif n=0 or n=1 then msgbox The factorial of given number &n& is :&f else for i=n to 2 step -1 f=f*i next msgbox The factorial of given number &n& is :&f end if 2.Find the fibonacci series of a number using vb script fibonacci series of a given number n=cint(inputbox(enter a number)) dim f0,f1,f2 f0=0 f1=1 f2=f0+f1 var=The fibonacci series of a given number &n& is :&vbnewline var=var& &f0& &f1 do while(f2<=n) var=var& &f2 f0=f1 f1=f2 f2=f0+f1 loop msgbox var 3.Search whether the given name is exists or not using vb script vb script prgram to give some names in the array and search for the given name whether the given name is exists or not names=array(gopi,ramu,ravi,raju) str=inputbox(enter name to search) for i=0 to ubound(names) if str=names(i) then

msgbox the given name &str& is there exit for end if next if i=ubound(names)+1 then msgbox the given name &str&is not there end if 4.Find the sum of diagonal elements in the matrix using vb script vb script program to find sum of diagonal elements in the given matrix declare double dimentional array dim a(2,2) dim sum,k sum=0 k=0 for i=0 to ubound(a,1) for j=0 to ubound(a,2) a(i,j)=cint(inputbox(enter elements)) next sum=sum+a(i,k) k=k+1 next msgbox sum 5.Display row and column elements in the array using vb script vb script program to display row and column elements in the given matrix declare double dimentional array in vb script dim a(1,2) dim row,col col=" for i=0 to ubound(a,1) row=" for j=0 to ubound(a,2) a(i,j)=cint(inputbox(enter elements)) row=row& &a(i,j) next msgbox row next for i=0 to ubound(a,2) col=" for j=0 to ubound(a,1) a(i,j)=cint(inputbox(enter elements)) col=col& &a(j,i)

next msgbox col next 6.Tracebility of a given matrix using vb script vb script program to tracebility of the given matrix declare double dimentional array in vb script dim a(1,1),b(1,1) dim row,col for i=0 to ubound(a,1) for j=0 to ubound(a,2) a(i,j)=cint(inputbox(enter elements)) next next for i=0 to ubound(a,2) for j=0 to ubound(a,1) b(i,j)=a(j,i) msgbox b(i,j) next next 7.Reverse the string using vb script Reverse a string using mid function in vb script str,strrev,ch,i,l str = inputbox(enter string) l = Len(str) For i = l To 1 Step -1 ch = Mid(str,i,1) strrev = strrev & ch Next msgbox strrev mid function returns the characters or string 8.How to fine greatest number from the given numbers in vb script option explicit dim myarray,max,i myarray = array( 34,23,45,67,12 ) max=myarray(0) for i=0 to ubound(myarray) if max < myarray(i) then

max=myarray(i) end if next msgbox max number is : &max 9.simple program having many basics Basics of vb script a=20 msgbox a Keywords are not case sensitive Msgbox a Implicit declaration (do not declare variables and use them) b=10 msgbox b may be variables are also not case sensitive msgbox B output 10 Explicit declaration (declare the varables and use them) dim c c=30 msgbox c array declaration in vb script the below array can store 3 elements dim x(2) x(0)=10 x(1)=gitam x(2)=date for loop in vb script for i=0 to 2 msgbox x(i) next for each in vb script for each i in x msgbox i next Conditional Statements in vb script dim i,j,k i=10 j=20 k=30 if i>j then msgbox The biggest number is : &i

elseif j>k then msgbox The biggest number is : &j else msgbox The biggest number is : &k end if how to goto new line in vb script msgbox This goes to first line&vbnewline&This goes to second line message box in vb script msgbox welcome to message box giving input from the keyword in vb script cint converts string into integer a=cint(inputbox(enter a number)) msgbox a represents type of variable using typename() in vb script a=10 b=india c=date d=12.5 dim e msgbox typename(a)& &typename(b)& &typename(c)& &typename(d)& &typename(e) Date,Month and Year functions in vb script a=date b=day(date) c=month(date) d=year(date) e=time f=now g=weekdayname(weekday(date)) i=monthname(month(date)) msgbox a& &b& &c& &d msgbox e& &f& &g& &i