Вы находитесь на странице: 1из 10

Multimedia & Web Technology(code 067) Topic : VBScript Sample -1 6.

Question given below are based on VBScript : (a) Define array. What is the significance of array? How is it declared? 1 (b) Change the following script using For next without affecting the output: dim name , i i=1 name= ARYAN do while I <= len (name) document.write instr(mid(name,i),A) i=i+1 loop c) Give the output for the following script code: 2 dim x,y y=10 for x= 1 to 4 step 1 if (x mod 2 ) = 0 then y=y-x else y=y+2*x end if document.write (y) next d)Rewrite the following code after removing errors with each correction underline: 2 <script> sub result() dim K,M while (K<10 and M>5) if K % 3 = = 0 K=K+M else K=K-M M=M+3 Loop Document.print(K= +K)

</script> Solution -1 Q6. a. array: an array is a collection of elements of same data type. All the elements in an array are identified by the same name but are differentiated by their index value. Significance of Array: i. all elements of an array are stored in adjacent memory location. ii. All elements are identified by the same name. Way of declaration: Syntax Dim arrayname (fileofarray) Example Dim marks(4) b. conversion into for..next dim name, i name=ARYAN for i=1 to ten(name) step 1 document.write instr(mid(name,i), A) next

c. output 12 10 16 12 d. correct code <script language=VBScript> sub result() dim K, M do while(K<10 AND M>5) if K mod 3= 0 then K=K+M Else K=K-M M=M+3 End if Loop Document.write(K & K) End sub <script> Sample-2 6. Question given below are based on VBScript : (a) what is the difference between array variable and scalar variables ? 1 (b) Change the following script using Do while .. loop without affecting the output: sum=0 for I = 0 to 4 for j= 0 to i-1 select case (i+j-1) case -1,0 sum=sum+1 case 1, 2,3 sum=sum+2 case else sum=sum+3 end select next next (c) Give the output for the following script code: 2 dim a,b a=10 b=2 do while b<12 if a>b then document.write (a) else document.write(b) end if a=a-4 b=b+3 loop d)Rewrite the following code after correcting the errors: 2 <script language =vbscript> sub result() dim s For s=1 upto 10 jump 1 If a mod 2 equals 0

Ans=ans*a End if loop document.weite(ans) </script> Solution-2 Q6 a) ARRAY VARIABLE Declaration of array variable (one name for many variable having different index start from o) is called array variable Example: Dim array (10) SCALAR VARIABLES Declaration of simple variable is called scalar variable Example: Dim x, y, z

B) DO WHILE ---- LOOP sum = 0 i=0 do while i<=4 j=0 do while j<=i-1 select case (i+j-1) case -1, 0 sum = sum+1 case 1,2,3 sum = sum + 2 case else sum=sum+3 end select j=j+1 loop i=i+1 loop c) OUTPUT 10 6 8 11 d) Correct code d) <script language = vbscript> sub result() dim s for s=1 to 10 step 1 if a mod 2 = 0 then ans= ans * a end if next document.write(ans) end sub <.script> Sample-3 6. a) Differentiate between Local and Global scope of a variable in VbScript.1 b) Change the following script using Do while .. loop without affecting the output: <script language="VBScript"> sub result() dim i,r,rev,k k=000004320100 for i = 5 to 12 step 5

r=k mod 10 rev=rev*10+r k=k\10 next end sub </script> c) Give the output for the following script code: 2 <script Language="VBScript"> sub result() Name = Web Tech startword = true For i = 1 to Len (Name) if (startword) Then Document.Write (Mid (Name, i, 1) ) if (Mid (Name, i, 1) = W Then startword = false else startWord = true End if End If Next end sub </Script> d)Rewrite the following code after correcting the errors: 2 <script language =vbscript> sub result() dim N1,N2,sum,i N1=messagebox(enter number) N2 =messagebox(enter number) Do while i<=N2 sum=N1+N2 if sum=100 exit do next end sub end sub </script> Solution-3. Q 6 a. Local variable Global i. declared inside a procedure i. declare outside a procedure ii. only access to a particular ii. valid for all the procedure function procedure etc. b. change into Do while . Loop <script language = VBScript> sub result() dim I, r, rev, k k=000004320100 i=5 do while(i<=12) i=5 do while (i<=12) r=k mod 10 rev = rev * 10 +r k=k/10 i=i+5 loop end sub

</script> c. Wb Tech d. <script language = Vbscript> sub result() dim N1, N2, sum, i N1= inputbox (enter number) N2= inputbox (enter number) Do while(i<=N2) Sum = N1+N2 If sum = 100 then Exit do End if Loop End sub </script> Sample-4 (Do it your self) 6. Questions given below are based on VBScript: (a) Where and how VBScript inserted in HTML document? How many types of procedures are there? How we call procedure from main program. (2 Ans :Vbscript part inserted in the head part of the HTML using <script language =vbscript> there are two type s of procedure I) Sub Procedure II) Function Procedure A subroutine is a named block of code that can be called from anywhere in a program to accomplish a specific task, which do not return a result to the caller. Example: Sub Sum(a,b) Document.Write(a+b) End Sub A function is a block of code that can be called from anywhere in a program to accomplish a specific task and which also returns a result or value to the caller. Example: Function Sum(a,b) Sum = a+b End Function Procedure are always called from main program using CALL word if it is SUB procedure and FUNCTION NAME if it is a Function procedure. (b) Change the following script using DO.. WHILE loop without effecting the Output : (2 <Script Language=VBScript> DIM TOTAL, COUNT TOTAL = 0 COUNT =10 DO document. Write (COUNT & <BR>) COUNT = COUNT - 2 TOTAL = TOTAL + COUNT LOOP UNTIL COUNT<1 doument. Write (TOTAL) </Script> (c) Give the output of the following code segment: (2 <Script Language = VBScript> Name = Mock Test 2009 startword = 1 For i = 1 to Len (Name) if (startword <>0 ) Then

Document.Write (right (Name, i) ) if (Mid (Name, i, 1) = Then startword = 0 else startWord = 5 End if End If Next </Script> Sample-5 6. Answer the following questions based on VBScript: a) Define the term event. Name the events to be used in the following situations: 2 (i) To display a message every time the viewer closes a web page. (ii) To deactivate a particular textbox in a form b) Write the equivalent script for the following code using DO.. WHILE loop without effecting the output: 2 <SCRIPT LANGUAGE=VBScript> DIM sum sum=0 FOR a= 1 TO 10 STEP 3 sum=sum + a*a document.write(a) NEXT document.write(sum) </SCRIPT> c) Give the output of the following code segment: 2 <Script Language=VBScript> Dim A , B A=1 B = 10 Do While A < 5 Document.Write(A+B) A=A+1 B=B-2 Loop </Script> Solution-5 6. (a) An event describes actions that occur as the result of user interaction with a web page. For example, when a user clicks a hyperlink or a button an event is generated. (i) OnUnload (ii) OnBlur (1 mark for correct definition) ( mark for each correct event name) b) <SCRIPT LANGUAGE=VBScript> DIM sum,a sum=0 a=1 DO WHILE a<=10 sum=sum + a*a document.write(a) a=a+3 LOOP document.write(sum) </SCRIPT> ( mark for correct initialisation of variables) (1 mark for correct syntax of DO..WHILE loop) ( mark for correct increment of variable) c) Output:

111098 ( marks for each correct value i.e. 11, 10, 9, 8) Sample-6 6. Answer the following questions based on VBScript: a) Differentiate between a sub-routine and a function with the help of an example. 1 b) Name the built-in functions to be used in the following situations: 1 (i) To return a number rounded to specified decimal places. (ii) To check if string1 occurs within string2 and return the starting position of string2 in string1. c) Write the equivalent script for the following code using FOR loop without effecting the output: 2 <SCRIPT LANGUAGE=VBScript> DIM count,ans ans=1 count=2 DO ans=ans*count count=count+2 LOOP WHILE count<=10 document.write(ans) </SCRIPT> d) Give the output of the following code segment: 2 <SCRIPT LANGUAGE=VBScript> Dim Names() Count = 2 ReDim Names(Count) Names(0)=Raj Names(1)=Simran Names(2)=Nisha ReDim Names(Count + 2) Names(4)=Rohit Document.Write(Names(0)) Document.Write(Names(1)) Document.Write(Names(2)) Document.Write(Names(3)) </SCRIPT> Solution-6 b) i) ROUND( ) ii) INSTR( ) ( mark for each correct function name) c) <SCRIPT LANGUAGE=VBScript> DIM count,ans ans=1 40 FOR count=2 TO 10 STEP 2 ans=ans*count NEXT document.write(ans) </SCRIPT> (1 mark for correct syntax of FOR statement) ( mark for giving correct value in STEP) ( mark for NEXT) d) Output: MayaRohit (1 mark for each correct name) Sample-7 6. Answer the following questions based on VBScript: a) Differentiate between IFTHEN..ELSE and SELECTCASE statements with the help of an example. b) Write the equivalent script for the following code using DO..WHILE without effecting the output: <SCRIPT LANGUAGE=VBScript> DIM arr(5)

counter=1 DO UNTIL counter > 5 arr(counter) = counter *counter counter =counter + 1 LOOP </SCRIPT> c) Give the output for the following script: <SCRIPT LANGUAGE=VBScript> B=10 FOR A=1 TO 12 STEP 3 C=A+B DOCUMENT.WRITE(C) B=B-1 DOCUMENT.WRITE(<BR>) NEXT </SCRIPT> Solution-7 6. The If...Then statement offers only one alternative for the value being checked whereas SELECT CASE is well suited for situations where there are a large number of possible conditions for the value being checked. For example: If Location = Delhi Then Select Case Location ShippingFee= 400 Case Delhi Else ShippingFee= 400 ShippingFee = 500 Case Else End If ShippingFee = 500 End Select (1 mark for the correct difference) (1 mark for the example) b) The code using DO WHILE is: 2 <SCRIPT LANGUAGE=VBScript> DIM arr(5) counter=1 DO WHILE counter <= 5 arr(counter) = counter *counter counter =counter + 1 LOOP </SCRIPT> (1 mark for correct syntax of DO..WHILE loop) (1 mark for correct condition check of counter) c) 11 2 13 15 17 ( mark for each correct output line) (Give 1 marks if the output is given without line breaks) Sample 8 6. Answer the following questions based on VBScript: a) Differentiate between a sub-routine and a function with the help of an example . 1 b) Name the built-in functions to be used in the following situations: 1 (i) To return a number rounded to specified decimal places. (ii) To check if string1 occurs within string2 and return the starting position of string2 in string1. c) Write the equivalent script for the following code using FOR loop without effecting the output: <SCRIPT LANGUAGE=VBScript> DIM A,B A=1 B=2

DO A=A*B N=N+2 LOOP WHILE N<=10 </SCRIPT> d) Give the output of the following code segment: 2 <SCRIPT LANGUAGE=VBScript> B=12 FOR A=3 TO 12 STEP 3 C=A+B DOCUMENT.WRITE(C) B=B-2 DOCUMENT.WRITE(<BR>) NEXT </SCRIPT> Solution 8 Q6. a) A subroutine is a named block of code that can be called from anywhere in a program to accomplish a specific task. Subroutines are procedures that do not return a value to the caller. Data that is required for the execution of the subroutine may be passed through variables called arguments. Example: Sub DisplaySum(a,b) Dim c c=a+b Document.Write(Sum = & c) End Sub b) i) Round() ii) Instr() c) <SCRIPT LANGUAGE=VBScript> DIM A,B A=1 B=2 For N = 0 to 10 step 2 A=A*B next </SCRIPT> d) 15 16 17 18 Assignment -1 Q6. Answer the following questions based on VBScript: a) Differentiate between IFTHEN..ELSE and SELECTCASE statements with the help of an example. b) Write the equivalent script for the following code using FOR loop without effecting the output: DIM count,ans ans=1 count=2 DO ans=ans*count count=count+2 LOOP WHILE count<=10 c)Rewrite the following code after correcting the errors: 2 sub result() dim n1,n2,sum

1 2

n1=5 n2 =10 for i=n1 upto n2 skip 2 if n1>n2 then n1+n2=sum next end sub d) Give the output of the following code segment: 2 sub result() arr=array(10,20,30,40,50,60,70) for i=5 to 2 step -1 arr(i) = arr(i)\7 document.write(arr(i)) next end sub Assignment -2 Q6. Answer the following questions based on VBScript: a) Define the term event. Name the events to be used to display a message every time the viewer closes a web page.1 b) Find the errors in the following code 2 <htnl> <body> s= Dynamic Array for i= 1 to 7 step 2 if mod(len(s),2)=1 document.write (n) loop </body> </html> c) Write the equivalent script for the following code using Do Until.. Loop without effecting the output: <SCRIPT LANGUAGE=VBScript> DIM count,ans ans=1 count=2 DO ans=ans*count count=count+2 LOOP WHILE count<=10 document.write(ans) </SCRIPT> d) Give the output of the following code segment: 2 <SCRIPT LANGUAGE=VBScript> sub result() arr=array(10,20,30,40,50,60,70) for i=ubound(array) to 2 step -2 arr(i) = arr(i)/2 document.write(arr(i)) next end sub </SCRIPT>

Вам также может понравиться