Results 1 to 5 of 5

Thread: How to create procedures in VBScript

  1. #1
    Join Date
    Jul 2010
    Posts
    28

    How to create procedures in VBScript

    I am little basic knowledge about the VBScripts. I have done some coding in which conditional structure and functions were included. I can do it practically, but when someone asks me about it, I get confused. And I am not having much idea about the procedures that are used in VBScripts. Please tell me how to create procedures in VBScripts? Also I want to know about the Objects that are used in VBScripts. I hope that you members will help me soon. Any coding with an explanation would be better for me to understand. I am expecting your response soon.

  2. #2
    Join Date
    Jan 2009
    Posts
    99

    Re: How to create procedures in VBScripts

    Often the same lines of code to write on a page. To delete these repetitions, you can use the functions. A simple example might be a function that prints the date when prompted.
    Code:
    <script language="vbscript"> 
    releasedate function () 
    WeekdayName document.write (weekday (date)) & "" & day (date) & "" & monthname (month (date)) 
    & "" & Year (Date) End Function 
    </ Script> 
    
    <script language="vbscript"> 
    releasedate() 
    </ Script>
    Note that the function starts with the function statement and ends with end function.

  3. #3
    Join Date
    Feb 2010
    Posts
    592

    Re: How to create procedures in VBScripts

    In the script we have the lowest call the function, simply by typing its name. A function may also receive variable, for example, create a function that prints the factorial.
    Code:
    <script language="vbscript"> 
    function factorial (number) 
    dim c, result 
    result = 1 
    for c = 1 to number 
    result = result * c 
    next 
    document.write "Factorial of" & number & "is" & result 
    end function 
    </ Script> 
    
    <script language="vbscript"> 
    factorial (5) 
    </ Script>
    Finally, a function can also return a value.
    Code:
    <script language="vbscript"> 
    function factorial (number) 
    dim c, result 
    result = 1 
    for c = 1 to number 
    result = result * c 
    next 
    result = factorial 
    end function 
    </ Script> 
    
    <script language="vbscript"> 
    document.write "The factorial of 5 is" & factorial (5) 
    </ Script>
    For us to return the value, it was enough to put before the exit of the function, the function name equal to the value to return. Another way to create functions is through the command SUB. With the SUB command procedures are created. The procedure is that the functions can receive the parameters, but the procedures do not value and therefore can not be used in expressions.

  4. #4
    Join Date
    Feb 2010
    Posts
    531

    Re: How to create procedures in VBScripts

    The procedure is that the functions can receive the parameters, but the procedures do not value and therefore can not be used in expressions.
    So the last statement document.write "The factorial of 5 is" & factorial (5) can not be generated with a SUB. This procedure prints a sequence from initial_value to value_final value_step with a pitch.
    Code:
    <script language="vbscript"> 
    sub sequence (initial_value, value_final, value_step) 
    dim c 
    for c = initial_value to step value_final value_step 
    document.write c & "<br> 
    next 
    end sub 
    </ Script> 
    
    <script language="vbscript"> 
    sequence 10,50,5 
    </ Script>
    As its procedures are very similar to functions in the call that is deployment.

  5. #5
    Join Date
    Feb 2010
    Posts
    428

    Re: How to create procedures in VBScripts

    As in Visual Basic, VBScript are also in the concept of object.
    An object is an entity that has the properties, actions (methods) and generates events. For example, the HTML page, which is the Document object has properties such as background color, such as shares writing a message and the page load event. If you are lucky enough to use as Visual Interdev editor, try to insert a script block and writing documents. Here are the main properties:
    • document.alinkcolor: Returns or sets the color of active links.
    • document.linkcolor: Returns or sets the color for links.
    • document.vlinkcolor: Returns or sets the color for visited links.
    • document.bgcolor: Returns or sets the background color of the page.
    • document.title: Returns or sets the page title.
    • document.url: returns the URL of the page.

    This script returns the properties of this page:
    Code:
    <script language="VBScript"> 
    <! - 
    document.write "alinkColor" & & document.alinkColor "<br> 
    document.write "linkColor" & & document.linkColor "<br> 
    document.write "vlinkColor" & & document.vlinkColor "<br> 
    document.write "bgcolor" & & document.bgcolor "<br> 
    document.write "title" & & document.title "<br> 
    document.write "url" & & document.url "<br> 
    //--> 
    </ Script>

Similar Threads

  1. How to create factorial of numbers using sub procedure in vbscript
    By Gurseerat in forum Software Development
    Replies: 1
    Last Post: 04-02-2012, 12:21 PM
  2. How to create ZIP Files from Command-Line via VBScript?
    By FB in forum Windows Server Help
    Replies: 10
    Last Post: 22-12-2011, 12:18 AM
  3. What are the Sub Procedures in VB 6.0?
    By Acolapissa in forum Windows Software
    Replies: 4
    Last Post: 25-12-2010, 04:39 AM
  4. How to create Functions in VBScript?
    By NIcaBoy in forum Software Development
    Replies: 4
    Last Post: 29-01-2010, 09:42 PM
  5. how to create automatic self extracting zip file in vbscript
    By vivekmohan in forum Software Development
    Replies: 1
    Last Post: 03-09-2009, 09:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,310,550.71608 seconds with 17 queries