13
VBScript: An Easy & Funny Scripting Language I am Rajdip Saha & I am Going To Teach You How To Do VBScripting. Well I Gonna Make You A VBScript Expert. What is VBScript? It is a scripting language. The main platform in which you can programme it is notepad. From my experience I can tell you that it is quite easy. Its proof is that I am only of 13 years & I learned the whole script…. I think this example was enough for you to understand how easy is VBScripting. Scripting language means a small programming language. VBScript is the language used in ASP (Active Server Pages). It is the primary stage of Microsoft’s Visual Basic. It is basically a web script. But being a web script it is used for many kinds of things. VBScript is used as a server-side scripting language. It is not in browser .You cannot see coding in a browser because the scripts are executed on the server. The web pages you see are the output from ASP that is normal HTML. So, I am going to teach you the hidden coding of VBScript & I will make sure that you will find it easy. I am sure that you will enjoy the tutorial. Can’t wait to learn? Ok, so let’s come to the main topic. Dear Learner, if you find it interesting then please, comment & like. You can click here to add a like or comment. Basics of VBScript Ok so let’s get ready to rock…Here are the basics You will just need notepad only to programme VBScript. These are written on notepad and then saved with .vbs extentension. This means that we should save this as anyname.vbs . To do this just write .vbs on the place of .txt & then save it.

Learn vbscripting easily by Rajdip Saha

Embed Size (px)

DESCRIPTION

VBScript is a scripting language. The main platform in which you can programme it is notepad. From my experience I can tell you that it is quite easy. Its proof is that I am only of 13 years & I learned the whole script…. I think this example was enough for you to understand how easy is VBScripting. Scripting language means a small programming language. VBScript is the language used in ASP (Active Server Pages). It is the primary stage of Microsoft’s Visual Basic. It is basically a web script. But being a web script it is used for many kinds of things. VBScript is used as a server-side scripting language. It is not in browser .You cannot see coding in a browser because the scripts are executed on the server. The web pages you see are the output from ASP that is normal HTML. So, I am going to teach you the hidden coding of VBScript & I will make sure that you will find it easy. I am sure that you will enjoy the tutorial.

Citation preview

Page 1: Learn vbscripting easily by Rajdip Saha

VBScript: An Easy & FunnyScripting Language

I am Rajdip Saha & I am Going To Teach You How To Do VBScripting. Well I Gonna Make You A VBScript Expert.

What is VBScript?It is a scripting language. The main platform in which you can programme it is notepad.From my experience I can tell you that it is quite easy. Its proof is that I am only of 13 years & I learned the whole script…. I think this example was enough for you to understand how easy is VBScripting. Scripting language means a small programming language. VBScript is the language used in ASP (Active Server Pages). It is the primary stage of Microsoft’s Visual Basic. It is basically a web script. But being a web script it is used for many kinds of things. VBScript is used as a server-side scripting language. It is not in browser .You cannot see coding in a browser because the scriptsare executed on the server. The web pages you see are the output from ASP that is normal HTML. So, I am going to teach you the hidden coding of VBScript & I will make sure that you will find it easy. I am sure that you will enjoy the tutorial. Can’t wait to learn? Ok, so let’s come to the main topic.

Dear Learner, if you find it interesting then please, comment & like.

You can click here to add a like or comment.

Basics of VBScriptOk so let’s get ready to rock…Here are the basics

You will just need notepad only to programme VBScript. These are written on notepad and then saved with .vbs extentension. This means that we should save this as anyname.vbs . To do this just write .vbs on the place of .txt & then save it.

Page 2: Learn vbscripting easily by Rajdip Saha

Do You Know About Variables In Algebra?

Something like, x=8, a=13

The letter in the above expression (like x or a) are used to store value (like 8).These letters are called variables, and these can be used to store value.

As with algebra, VBScript variables are used to hold values or expressions.

A variable can have a short letter like a or a more descriptive name, like bumble.

But this has some different rules like:

i) They must begin with a letter ii) They cannot have more than 255 charactersiii) They cannot contain a period. Like (.)

In VBScript, all variables are of type variant that can store different types of data.

You can also declare a variant’s (variable) value using ‘=’ sign. Like this

Example: Bumble= Msgbox (“Honey”)

In the above case Bumble is the variable, Honey is the message which will appear & we are using a ‘=’ sign to declare the value of Bumble (variable). We can also see in the above example a word written as Msgbox this is used to create a message box in which a specific message will appear.

There are also other boxes like: Inputbox these are used to create a box in which we can input any statement. To create it just write Inputbox in the place of Msgbox.

Page 3: Learn vbscripting easily by Rajdip Saha

*Please Don’t Copy Paste These Codes To Notepad. If You Want To Try Them Then Please Write It In Notepad. Don’t Copy Paste It. Otherwise The Codes Will Not Run.

Example: Dim Bumble

Bumble=Inputbox (“Honey”)

To make a variant Dim is used.

Example: Dim Bumble

Bumble=Msgbox (“Honey”)

In this case a dialog box will appear on the screen in which the word ‘Honey’ will be written.

You can use variants easily.

As: Dim bumble

Bumble=Msgbox (“Honey”)

Dim rumble

Page 4: Learn vbscripting easily by Rajdip Saha

Rumble=Msgbox (“Hey” & Bumble)

It will show “Hey Honey” because of &.

Array VariablesIt is used to store multiple values in a single variant (variable). An example is shown below:

Example: Dim Bumbles(3)

Bumbles(0)=Msgbox (“Yo”)

Bumbles(1)=Msgbox (“Po”)

Bumbles(2)=Msgbox (“Bo”)

Bumbles(3)=Msgbox (“Go”)

The number shown in the bracket is 3. VBScript recognises zero so this array contains 4 elements (From 0 to 3). This is a fixed-size array. You can assign data to each of the elements of the array.

You can have maximum to 60 dimensions in an array. Multiple dimensions are declared by separating the numbers in the brackets with commas like: Dim Table(3,7).

Sub Procedures

A Sub procedure is a series of statements, enclosed by the Sub and End Sub statements can perform actions, but does not return a value can take arguments. Like This:

Sub Mysub()

Some script what you want...

End

Or

Sub Mysub(argument1,argument2)

Some script what you want...

End

Page 5: Learn vbscripting easily by Rajdip Saha

VBScript Function Procedures

A Function procedure is a series of statements, enclosed by the Function and End Function statements. It can perform actions and can return a value. It can take arguments that are passed to it by a calling procedure without arguments, must include an empty set of brackets (). It returns a value by assigning a value to its name

Example: Function Myfunction()

Some script what you want...

Myfunction=some value

End Function

Or

Function Myfunction()

Some script what you want...

Myfunction=some value

End Function

Easy Explanation of Functions: See This Picture:

Codes Used: Function times(x,y) times = x * y End Function

Dim result dim var1

Page 6: Learn vbscripting easily by Rajdip Saha

result = times(10,10)

var1=MsgBox(result)

This would give you 100Let me explain....You told it to times 10 by 10...Result = time(10,10)This went to the function times

x is now 10 and y is now 10So: x * y return value with answer.

WoooHooooo……… You have already learned half of it. So you can be called as a “Half-Programmer” right now. Ok Ok… Let’s learn more...

If, Then & ElseUse the If...Then...Else statement if you want to execute some code if a condition is true or to select one of two blocks of code to execute.

If you want to execute only one statement when a condition is true, you can write the code on one line:

If i<10 Then

Info=Msgbox("Hello")

There is no “Else” in this syntax. You just tell the code to perform one action if a condition is true (in this case If i=10).

If you want to execute more than one statement when a condition is true, you must put each statement on separate lines, and end the statement with the keyword "End If":

If i<10 ThenInfo=Msgbox("Hello")i = i+1End If

There is no “Else” in the example above either. You just tell the code to perform multiple actions if the condition is true.

If you want to execute a statement if a condition is true and execute another statement if the condition is not true, you must add the "Else" keyword:

Easy Explanation of If & Then:

Page 7: Learn vbscripting easily by Rajdip Saha

Theses are quite easy to get but i decided they needed a page in case someone didn't know what they did.

if bumble=TheWorst then msgbox("yes")

But there not that scary you just add an end if at the end of the statement.

Example:

if bumble=TheWorst thenmsgbox ("yes")msgbox ("Oh yes!")end if

This will pop up with 2 messages one after the other, ‘yes' and ‘Oh yes!’.The the end if statement closes it.

Case SelectionCases are simple and can make you life much easier. Example of simple case:

Dim MessageMessage=InputBox("Enter Your Name to Know Which Hero You Are")Select Case MessageCase "Rajdip"Info=Msgbox("You Are Captain America”)Case "Mandira"Info=Msgbox("You Are Divergent")Case "Bikram"Info=Msgbox("You Are Thor")End Select

This simple script will select options from a list & in this case it will tell you which super

hero are you.

Let me go into it in a bit more detail ...

You get your variant: Dim Message. Then you ask the vbscript to look through a list to

find your variant ...

If it cannot find it then it will go to the: Case Else which is just like the “if”, “else”

command.

If it finds your variant it will execute it. Like if you enter the name Rajdip in input box it

will tell you that you are “You Are Captain America” through a message box. The Case

Page 8: Learn vbscripting easily by Rajdip Saha

message selects a specified answer for a specific entry. Don’t Forget to Add “End Select”

Statement at the last.

LoopLooping statements are used to run the same block of code a specified number of times.

In VBScript we have four looping statements:

For...Next statement - runs code a specified number of times

For Each...Next statement - runs code for each item in a collection or each element of anarray

Do...Loop statement - loops while or until a condition is true

While...Wend statement - Do not use it - use the Do...Loop statement instead

Easy Explanation of For, Next Do Loop: Example:

for var = 0 to 5msgbox(var)nextmsgbox("Finish")

This will pop up a message box counting 0,1,2,3,4,5 then it will say 'Finish'REMEMBER in vbscript 0 nearly always counts!So that code would repeat a command 6 times

Example:

for var = 0 to 5msgbox("hello")nextmsgbox("Finish")

The message 'hello' would come up 6 times. On the 7th time it will say finish.

If you add: step ... to the end of for var = 0 to 5

Example:

for var = 0 to 5 step 5

Page 9: Learn vbscripting easily by Rajdip Saha

That will make it jump 5 each time... In this case the message will only show twice because 5 is the limit.You can also step down as well. Step -5 would count down 5 each time.

Do, LoopThe do loop is used to loop a piece of code over and over and over. Mainly used for viruses

But you can use them to help you... say if you wanted to keep saying a message until a certain option is picked. You Can always add a Until on the do or on the loop part. e.g.Do until var=5But in the code you must make it add 1 or more to the variable .. or it will keep on looping.

You can also use do from thing like: do while var=10.This will only do the commands if variable (Var) is equal to 10!

Ahhhhhhhh… You are almost done… Let’s learn the last step:

Extras of Message BoxOk … let’s talk about something harder…

The MsgBox function creates a dialog box with a specified message and prompts the userto click a button, upon which the dialog box closes and a value relating to which button was clicked is returned. These values, along with their Constants, are listed in the table below:

Page 10: Learn vbscripting easily by Rajdip Saha

Syntax: MsgBox(Prompt, Buttons, Title)

Prompt: The Prompt argument is the message string that appears in the message box.

Buttons: The optional Buttons argument must only use the constant or value in the MsgBox CONSTANTS.

Title: The optional Title argument is the title that appears at the top of the message box window.

Note you may use either the Title argument or the HelpFile, Context arguments. You cannot use both at the same time.

HelpFile: The optional HelpFile argument is a string that specifies the help file that you wish to display. This must be either a .chm or .hlp file.

Note you may use either the Title argument or the HelpFile, Context arguments. You cannot use both at the same time.Context: The optional Context argument specifies the help context number in the help file of the topic you wish to display. If you have created your own custom help file, then the Context argument is mandatory.

VBScript Functions

Date & Time Codes

Code Function

Page 11: Learn vbscripting easily by Rajdip Saha

CDate Converts a valid date and time expression to the variant of subtype DateDate Returns the current system dateDateAdd Returns a date to which a specified time interval has been addedDateDiff Returns the number of intervals between two datesDatePart Returns the specified part of a given dateDateSerial Returns the date for a specified year, month, and dayDateValue Returns a dateDay Returns a number that represents the day of the month (between 1 and 31, inclusive)FormatDateTime Returns an expression formatted as a date or timeHour Returns a number that represents the hour of the day (between 0 and 23, inclusive)IsDate Returns a Boolean value that indicates if the evaluated expression can be converted to a dateMinute Returns a number that represents the minute of the hour (between 0 and 59, inclusive)Month Returns a number that represents the month of the year (between 1 and 12, inclusive)MonthName Returns the name of a specified monthNow Returns the current system date and timeSecond Returns a number that represents the second of the minute (between 0 and 59, inclusive)Time Returns the current system timeTimer Returns the number of seconds since 12:00 AMTimeSerial Returns the time for a specific hour, minute, and secondTimeValue Returns a timeWeekday Returns a number that represents the day of the week (between 1 and 7, inclusive)WeekdayName Returns the weekday name of a specified day of the weekYear Returns a number that represents the year

Math Codes

Codes FunctionsAbs Returns the absolute value of a specified numberAtn Returns the arctangent of a specified numberCos Returns the cosine of a specified number (angle)Exp Returns e raised to a powerHex Returns the hexadecimal value of a specified numberInt Returns the integer part of a specified numberFix Returns the integer part of a specified numberLog Returns the natural logarithm of a specified numberOct Returns the octal value of a specified numberRnd Returns a random number less than 1 but greater or equal to 0Sgn Returns an integer that indicates the sign of a specified numberSin Returns the sine of a specified number (angle)Sqr Returns the square root of a specified numberTan Returns the tangent of a specified number (angle)

Format Codes

Codes FunctionsFormatCurrency Returns an expression formatted as a currency valueFormatDateTime Returns an expression formatted as a date or timeFormatNumber Returns an expression formatted as a numberFormatPercent Returns an expression formatted as a percentage

Conversion Codes

Codes Functions

Page 12: Learn vbscripting easily by Rajdip Saha

Asc Converts the first letter in a string to ANSI codeCBool Converts an expression to a variant of subtype BooleanCByte Converts an expression to a variant of subtype ByteCCur Converts an expression to a variant of subtype CurrencyCDate Converts a valid date and time expression to the variant of subtype DateCDbl Converts an expression to a variant of subtype DoubleChr Converts the specified ANSI code to a characterCInt Converts an expression to a variant of subtype IntegerCLng Converts an expression to a variant of subtype LongCSng Converts an expression to a variant of subtype SingleCStr Converts an expression to a variant of subtype StringHex Returns the hexadecimal value of a specified numberOct Returns the octal value of a specified number

String Codes

Codes FunctionsInStr Returns the position of the first occurrence of one string within another. The search begins at the first

character of the stringInStrRev Returns the position of the first occurrence of one string within another. The search begins at the last

character of the stringLCase Converts a specified string to lowercaseLeft Returns a specified number of characters from the left side of a stringLen Returns the number of characters in a stringLTrim Removes spaces on the left side of a stringRTrim Removes spaces on the right side of a stringTrim Removes spaces on both the left and the right side of a stringMid Returns a specified number of characters from a stringReplace Replaces a specified part of a string with another string a specified number of timesRight Returns a specified number of characters from the right side of a stringSpace Returns a string that consists of a specified number of spacesStrComp Compares two strings and returns a value that represents the result of the comparisonString Returns a string that contains a repeating character of a specified lengthStrReverse Reverses a stringUCase Converts a specified string to uppercase

Array Codes

Codes FunctionsArray Returns a variant containing an arrayFilter Returns a zero-based array that contains a subset of a string array based on a filter criteriaIsArray Returns a Boolean value that indicates whether a specified variable is an arrayJoin Returns a string that consists of a number of substrings in an arrayLBound Returns the smallest subscript for the indicated dimension of an arraySplit Returns a zero-based, one-dimensional array that contains a specified number of substringsUBound Returns the largest subscript for the indicated dimension of an array

Other Codes

Page 13: Learn vbscripting easily by Rajdip Saha

Codes FunctionsCreateObject Creates an object of a specified typeEval Evaluates an expression and returns the resultIsEmpty Returns a Boolean value that indicates whether a specified variable has been initialized or notIsNull Returns a Boolean value that indicates whether a specified expression contains no valid data (Null)IsNumeric Returns a Boolean value that indicates whether a specified expression can be evaluated as a numberIsObject Returns a Boolean value that indicates whether the specified expression is an automation objectRGB Returns a number that represents an RGB color valueRound Rounds a numberScriptEngine Returns the scripting language in useScriptEngineBuildVersion Returns the build version number of the scripting engine in useScriptEngineMajorVersion Returns the major version number of the scripting engine in useScriptEngineMinorVersion Returns the minor version number of the scripting engine in useTypeName Returns the subtype of a specified variableVarType Returns a value that indicates the subtype of a specified variable

WoooHooooo… You Are Now A Programmer… You Learned The Whole One..

If you found my article interesting please like my page or click here.

Sources: W3School, Instructables, My Sister & My School.

You Can Learn VBScripting In More Details From The Above Sources.

Thank You for Reading My Article. Best Wishes for Your Future.

You Can Read My Other Articles From tecnoraj.webstarts.com As Well From authorstream.com.

This is copied from technoraj.webstarts.com