Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, February 7, 2012

Multiple Line Syntax in VBScript


If you are a newcomer of VBScript, you must be eager to learn how to write multiple line syntax in VBScript. Here you will learn what code or syntax you should exactly put in to create multiple lines in VBScript. This is required when your codes gets very long that need to be placed in multiple lines.


One good news for you guys is that Microsoft has already integrated a very special character as multiple line syntax or code. And the special character is the underscore sign ‘_’. The example below will show you how to write multiple line syntax of in VBScript using the underscore ‘_’ sign. The following example deals with a long written statement in which you will find that ultiple lines are required to complete the code.


Example of Multiple Line Syntax in VBScript:


document.write("This statement is a very long written " &_

"statement that needs to be positioned in a way that " &_

"the lines can be readable!")


This VBScript code will display the following:


This statement is a very long written statement that requires to be positioned in such a way that the lines can be readable!


If you find this blog helpful, don’t forget to drop a comment.

Sunday, November 22, 2009

Learning VBScript

Currently im working with SQL Server for business report automation. Although i love to write code in C++ or Java, but now i need to learn vbscript for the purpose of scheduled sending of mails. SQL server provides packages to perform scheduled data transformation, but working with the imported data ie. send the imported excel to the concerned person attaching it requires a activx script object and scripting in it and theres a whole lot of things you can do with microsoft automation scripting.

First i'd like to add most frequently asked questions' answers when working in this type of environment


  1. Set a variable when this is an object like
    dim name
    name=some value

    when some value is of primitive literal type the name doesnt require setting. But if some value is of like a createObject() method call of another reference of object like anObj.Property then you need to write

    dim name
    Set name=some object reference
    name=some other reference

    for the first time when initialising the name variable. Thenafter you can assign other references.
  2. In VBScript we have four looping statements:

    -For...Next statement - runs statements a specified number of times.
    -For Each...Next statement - runs statements for each item in a collection or each element of an array
    -Do...Loop statement - loops while or until a condition is true
    -While...Wend statement - Do not use it - use the Do...Loop statement instead

    Sample Codes:

    For i=1 to 10
    some code
    Next

    For i=2 To 10 Step 2
    some code
    Next

    For i=10 To 2 Step -2
    some code
    Next

    dim cars(2)
    cars(0)="Volvo"
    cars(1)="Saab"
    cars(2)="BMW"
    For Each x in cars
    document.write(x & "
    ")
    Next

    Do While i>10
    some code
    Loop

  3. Useful functions:

    Syntax




    FormatDateTime(date,format)





    ParameterDescription
    dateRequired. Any valid date expression (like Date()
    or Now())
    formatOptional. A Format value that specifies the date/time format to use

    Example 1







    document.write("The current date is: ")
    document.write(FormatDateTime(Date()))

    Output:

    The current date is: 2/22/2001


    Example 2







    document.write("The current date is: ")
    document.write(FormatDateTime(Date(),1))

    Output:

    The current date is: Thursday, February 22, 2001