Sunteți pe pagina 1din 9

1) The name of the interpreter required for interpreting VB Scripts which is inbuilt into the OS? A) Wscripts.

exe 2) msgbox 3-2 ; msgbox 3^2 ; 3) Write a VB script using the delimiter : . A) DIM A : A = 2 : MSGBOX A 4) Write a VB script to display to accept the name from end user and display it in double cots. A) VNAME = INPUTBOX(ENTER YOUR NAME:) MSGBOX &VNAME& 5) Arithmetic operator precedence. A) ( ), ^, *, /, \, mod, +, 6) Write a VB script to display the first occurrence of s in the word qspiders.

Write a VBS to accept the number from the end user and print you won if the length of the number is greater than or equal to four, print you loss if the length of the number is less than four. A) OPTION EXPLICIT DIM VAR, VAR1 VAR = INPUTBOX (ENTER THE NUMBER: ) VAR1 = LEN (VAR) IF VAR1 >= 4 THEN MSGBOX YOU WON ELSE MSGBOX YOU LOSS END IF Write a vb script to accept age from the user and verify whether the person is eligible to vote or not? OPTION EXPLICIT AGE = CINT (INPUTBOX (ENTER YOUR AGE :)) IF AGE > = 18 THEN MSGBOX YOU ARE ELIGIBLE TO VOTE ELSEIF MSGBOX YOU ARE NOT ELIGIBLE TO VOTE ENDIF Write a vb script to accept gender and age from the user and verify whether the person is eligible to marry or not. Note that the case of the gender should accept both lower and upper case. OPTION EXPLICIT DIM GENDER, AGE GENDER = UCASE (INPUTBOX (ENTER YOUR GENDER, MALE M, FEMALE F:)) AGE = CINT (INPUTBOX (ENTER YOUR AGE :)) IF GENDER = M AND AGE >= 21 THEN MSGBOX YOU ARE ELIGIBLE TO MARRY ELSE IF GENDER = F AND AGE >= 18 THEN MSGBOX YOU ARE ELIGIBLE TO MARRY ELSE

MSGBOX NOT ELIGIBLE TO MARRY ENDIF (OR) OPTION EXPLICIT DIM GENDER, AGE GENDER = UCASE (INPUTBOX (ENTER YOUR GENDER, MALE-M, FEMALE-F:)) AGE = CINT (INPUTBOX (ENTER YOUR AGE: )) IF (GENDER = M AND AGE >= 21) OR (GENDER = F AND AGE >= 18) THEN MSGBOX YOU ARE ELIGIBLE TO MARRY ELSEIF GENDER <> M OR GENDER <> F THEN MSGBOX INVALID ELSE MSGBOX YOU ARE NOT ELIGIBLE TO MARRY END IF Write a vbs to verify if the word is a vowel or not. Note that if the first letter in the word is vowel then the word is vowel. OPTION EXPLICIT DIM WORD, FIRSTLETTER WORD = UCASE (INPUTBOX (PLEASE ENTER A WORD: )) FIRSTLETTER = MID (WORD, 1, 1)
IF FIRSTLETTER=A OR FIRSTLETTER=E FIRSTLETTER=I OR FIRSTLETTER=O OR FIRSTLETTER=U THEN

MSGBOX THE WORD&&WORD&&IS VOWEL ELSE MSGBOX THE WORD&&WORD&&IS NOT A VOWEL END IF Write a vbs for traffic signal using select case, red means stop, yellow means get ready, green means go. OPTION EXPLICIT DIM VCHOICE VCHOICE = INPUTBOX (ENTER YOUR CHOICE, RED STOP, YELLOW GET READY, GREEN GO) SELECT CASE VCHOICE CASE = 1 MSGBOX STOP CASE = 2 MSGBOX GET READY CASE = 3 MSGBOX GO CASE ELSE MSGBOX INVALID END SELECT (OR) OPTION EXPLICIT DIM COLOR COLOR=UCASE (INPUTBOX (PLEASE ENTER YOUR CHOICE, RED OR YELLOW OR GREEN))

SELECT CASE COLOR CASE RED MSGBOX STOP CASE YELLOW MSGBOX GET READY CASE GREEN MSGBOX GO CASE ELSE MSGBOX INVALID END SELECT Write a vbs to display the highest number among two numbers without using end if. OPTION EXPLICIT DIM FN, SN IF FN>SN THEN MSGBOX FN& IS GREATER Write a vbs to accept a number and check whether it is an odd number or not, without using end if. OPTION EXPLICIT DIM NUMBER, VSTR NUMBER = INPUTBOX (PLEASE ENTER A NUMBER) VSTR = NUMBER MOD 2 IF VSTR <> 0 THEN MSGBOX NUMBER& IS ODD Write a vbs to accept two numbers and print the odd numbers between the two numbers, if the second number is greater than first number, if the first number is greater than second number, print the odd numbers between them in reverse order. OPTION EXPLICIT DIM A, B, I A = CINT (INPUTBOX (PLEASE ENTER THE FIRST NUMBER:)) B = CINT (INPUTBOX (PLEASE ENTER THE SECOND NUMBER:)) IF A<B THEN FOR I = A TO B IF I MOD 2 <> 0 THEN MSGBOX I END IF NEXT ELSEIF A>B THEN FOR I = A TO B STEP -1 IF I MOD 2 <> 0 THEN MSGBOX I END IF NEXT END IF Write a vbs to retrieve spi from the word qspiders. A = QSPIDERS B = MID (A, 2, 3) MSGBOX B

Write a vbs to fetch letter q from the word qspiders. A=QSPIDERS B=MID (A, 1, 1) MSGBOX B Write a vbs to fetch letters from second position onwards from the word qspiders. A = QSPIDERS B = MID (A,2) MSGBOX B Write a vbs to display the length of the word qspiders. A = QSPIDERS B = LEN (A) MSGBOX B Remove the spaces at the left and right ends of the strings and display the length of the word qspiders . A = QSPIDERS B = TRIM (A) C = LEN (B) MSGBOX C Write a vbs to remove spaces at the left end of the word qspiders and display the length of the word. A = QSPIDERS B = LTRIM (A) C = LEN (B) MSGBOX C Write a vbs to remove spaces at the right end of the word qspiders and display the length of the word. A = QSPIDERS B = RTRIM (A) C = LEN (B) MSGBOX C Write a vbs to replace letter q with letter k in the word qspiders. A = QSPIDERS B = REPLACE (A, Q, K) MSGBOX B Write a vbs to replace single space with no space in the word qspi ders and find the length of the word. A = QSPI DERS B = REPLACE (A, , ) MSGBOX B Write a vbs to print the word qspiders in reverse. A = QSPIDERS B = STRREVERSE (A) MSGBOX B Write a vbs to print the current system date.

MSGBOX DATE Write a vbs to print the current system time. MSGBOX TIME Write a vbs to print the current system date and time. MSGBOX NOW Write a vbs to print the current system hour. MSGBOX HOUR(TIME) Write a vbs to print the current system minute. MSGBOX MINUTE (TIME) Write a vbs to print the current system second. MSGBOX SECOND (TIME) Write a vbs to accept a string and display one letter at a time. OPTION EXPLICIT DIM WORD, A, B, I WORD = INPUTBOX (PLEASE ENTER THE WORD:) A = LEN (WORD) FOR I = 1 TO A B = MID (WORD, I, 1) MSGBOX B NEXT Write a vbs to accept a string and print each letter in separate line but in same window. OPTION EXPLICIT DIM WORD, I, A, B, VAR WORD = INPUTBOX (PLEASE ENTER THE WORD:) A = LEN (WORD) FOR I = 1 TO A B = MID (WORD, I, 1) VAR = VAR & B & VBNEWLINE NEXT MSGBOX VAR Write a vbs to accept a set of numbers and display the product of the individual numbers (factorial). OPTION EXPLICIT DIM NUMBER, A, B, TEMP NUMBER = INPUTBOX (PLEASE ENTER A SET OF NUMBERS) A = LEN (NUMBER) TEMP = 1 IF ISNUMERIC (NUMBER) THEN FOR I = 1 TO A B = MID (NUMBER, I, 1) TEMP = TEMP * B NEXT MSGBOX TEMP

ELSE MSGBOX PLEASE ENTER NUMBERS ONLY END IF

Write a vbs to print all the odd and even numbers in a separate msgbox (from 1 to 20) OPTION EXPLICIT DIM I, ODD, EVEN FOR I = 1 TO 20 STEP 1 IF (I MOD 2) <> 0 THEN ODD = ODD & I & VBNEWLINE ELSE EVEN = EVEN & I &VBNEWLINE END IF NEXT MSGBOX THE ODD NUMBERS ARE & VBNEWLINE & I MSGBOX THE EVEN NUMBERS ARE & VBNEWLINE & I Write a vbs to accept two inputs and display even numbers between the two numbers. OPTION EXPLICIT DIM NUM1, NUM2, I, VAR NUM1 = INPUTBOX (ENTER FIRST NUMBER:) NUM2 = INPUTBOX (ENTER SECOND NUMBER:) FOR I = NUM1 TO NUM2 STEP 1 IF I MOD 2 = 0 THEN VAR = VAR & I & VBNEWLINE END IF NEXT Above script works only if NUM1 > NUM2

Write a vbs to accept two numbers and display the odd numbers between them. OPTION EXPLICIT DIM NUM1, NUM2, I, VAR NUM1 = INPUTBOX ("ENTER FIRST NUMBER:") NUM2 = INPUTBOX ("ENTER SECOND NUMBER:") IF NUM1 > NUM2 THEN FOR I = NUM1 TO NUM2 STEP -1 IF I MOD 2 <> 0 THEN VAR = VAR & I & VBNEWLINE END IF NEXT MSGBOX VAR

ELSEIF NUM1 < NUM2 THEN FOR I = NUM1 TO NUM2 STEP 1 IF I MOD 2 <> 0 THEN VAR = VAR & I & VBNEWLINE END IF NEXT MSGBOX VAR ELSE MSGBOX "EQUAL NUMBERS" END IF

Sample vbs on arrays. DIM A (2) A (0) = 1 A (1) = "HI" A (2) = TRUE B = A (1) C = A (2) D = A (0) MSGBOX B MSGBOX D MSGBOX C

Using arrays write a vbs to accept three numbers and display the numbers. DIM A (2) FOR I = 0 TO 2 STEP 1 A (I) = INPUTBOX (ENTER THE VALUE:) NEXT FOR I = 0 TO 2 STEP 1 MSGBOX A(I) NEXT DIM A (I) FOR I = 0 TO 2 STEP 1 A (I) = INPUTBOX (ENTER THE VALUE:) NEXT FOR I = 0 TO 2 STEP 1 VAR = VAR & A(I) & NEXT MSGBOX VAR

Display the picture as shown below. * ** *** **** DIM I, J, VAR FOR I = 1 TO 4 STEP 1 FOR J = 1 TO I STEP 1 VAR = VAR & * & NEXT VAR = VAR & VBNEWLINE NEXT MSGBOX VAR Display the picture as shown below. **** **** **** **** FOR I = 1 TO 4 STEP 1 FOR J = 1 TO 4 STEP 1 VAR = VAR & * & NEXT VAR = VAR & VBNEWLINE NEXT MSGBOX VAR SPLIT DIM A A = ("A, B, C") B = SPLIT (A, ",") Mention the same delimiter as in A

FOR EACH I IN B VAR = VAR & I & VBNEWLINE

NEXT MSGBOX VAR Split the string 1,2.3 4 A = 1,2.3 4 B = REPLACE (A, ,, ) C = REPLACE (B, ., ) D = SPLIT (C, ) FOR EACH I IN D MSGBOX I NEXT

Sample vbs on normal sub-routine (values hard coded). CALL ADD ( ) SUB ADD ( ) A=1 B=2 C=A+B MSGBOX C END SUB Sample vbs on normal sub-routine (passing arguments). A=3 B=6 CALL ADD (A, B) SUB ADD (A, B) C = A+ B MSGBOX C END SUB (OR) ADD ( )

MSGBOX THIS IS MSGBOX, 48, TITLE BAR MSGBOX THIS IS MSGBOX, 33, TITLE MSGBOX THIS IS MSGBOX, 29, MY TEXT

etc.