Monday, February 12, 2007

Exercises: Scripting

STRING MANIPULATION
===================
1. Write code that accepts a string as input and does the following
* Display the size of the string
* Display the string in reverse

2. Print the following string on 2 lines using one Msgbox function: "Hello" "World"
This should be printed as:

Hello
World

but done using 1 Msgbox function

3. Write code that takes the value 2000111.4 and displays it as $2,000,111.40

4. Write code that takes the value $1,234,567.70 and displays it as $1234567.70

5. Write code that accepts a number and displays whether the number is a prime number or not

6. Create a script that prompts a user for a word and then the script does the following:

a. Displays the string entered
b. Print out the length of the string
c. Print out the string in reverse



DATE MANIPULATION
=================
1. Write code that accepts a date in MM/DD/YY format and then prints the date in Mon, DD, YYYY format.
e.g. 03/01/04 and display Mar, 01 2004

2. Write code that displays the time in HH:MM AM format e.g. 02:35 PM

3. Create a script that will print out the day value e.g. Sunday/Monday

3. Write code that displays the time in long format e.g. Two thirty-five PM.



FILE I/O
========
1. Create a script that will accept an input and write it into a file named mydata.txt

2. Create a script that will accept a file name and print "Exists" if the file exists and "Doesn't Exist" if it doesn't.






MORE EXERCISES
==============
1. Create a simple loop that will print "Hello" 5 times




2. Write code that prints out all the even numbers between 2 and 8 and displays them at a single time using the following format:

2 - 4 - 6 - 8!

Labels: ,

Friday, February 02, 2007

Exercises: VBScript

EXERCISES
=========

1. Write the item below as a comment using the 2 forms of comments that are available in VBScript

This is a comment



2. Fix the following line of code of code using any of the 2 comment keywords. When you are done, the code should run properly and print 'Hello World' 2 time

Declaring variables
Dim strMessage
Dim numLoop
strMessage = "Hello World" Assigning a value to my variable

For numLoop = 0 To 1 Step 1
Printing a message
Msgbox strMessage This will display the message
Next

The end of the code


3. We used the InputBox function to ask the user for input. Complete the following script so that when I run it, it will ask me for a number and then it will double the number and display it to me.

Option Explicit
Dim numValue
numValue = InputBox("Please enter a number")



4. Create a script that accepts any numerical input and then displays a message if the number is a prime number or not.
[Note: A prime number is a number that is a non-negative and that is only divisible by one and itself]

Labels: ,

Thursday, February 01, 2007

Exercises: TSL

1. Modify the following code using comment and inserting missing symbols so that it would run properly

------ code start
Declaring a variable
static numCount This variable will hold the number of times I execut the test
// Assigning a value to this variable
numCount = 3;
/* Print the variable */
print("Value of numCount:" + numCount);

------ code ends


2) Indicate which of the following are incorrect And what (if anything is wrong)

int intNumberofDays

static numBankBalance
numBankBalance = "Hello";

public numLoopCounter
numLoopCounter = 14

Static strData;

static if = 0;

public +2;
+2 = "Hello";

Static list+names;
list+names = "John, James, Victor";

static a;
static b = "Hello";
a = b + "2";


3. Complete the following if statement to display "More than 10" if the input value is more than 10.

static numInput;
numInput = 7;

# Please create the appropriate if statement


4. Create an if statement to display "5 or more" if the input value is 5 or greater and "Less than 5" if it is not

static numInput;
numInput = 7;

# Please create the appropriate if statement


5) Create an if statement structure to display
* "Even" if a number is even
* "Odd" if the number is odd
* "Zero" if the number is 0
* "Negative" if the number is less than zero.

Please note that all these are mutually exclusive i.e. a number can either be even, odd, zero or negative.


6. Fix the errors in the following TSL code to make it function properly

Declare a variable
static numData
numData = 7; This is an assignment statement
//Print the value
print("numData");


7. Write TSL code that prints out all the even number between 1 and 10 in the following form

1, 3, 5, 7, 9
Note: PLease use only 1 pause statement.

Labels: ,