Consulting

Results 1 to 8 of 8

Thread: Static variables with vbs??

  1. #1

    Static variables with vbs??

    Hi all,

    To get straight to the point, Is it possible for me to create a static variable with vbs??

    When I do this with VBA,

    [VBA]
    Static tnow
    tnow = Time + TimeSerial(0, 1, 0)
    Do Until Time > tnow
    MsgBox Time
    Loop[/VBA]

    Fine, it works, but in vbs I get an error. I therefore suspect the use of Static is not allowed in vbs. If this is the case, how can I get round this??

    Many thanks in advance.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I tried your snippet in a VB6 form, and it ran without error.

  3. #3
    I tried your snippet in a VB6 form
    Indeed, but I'm only concerned with VBS not VB6 !!

  4. #4
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    There is no Static declaration in VBS and yes there is in VBA and VB 6, thats why it works on both.

    I recommend you to check this site http://www.sunny-beach.net/manual/249.htm for differences between VB, VBA and VBScript.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  5. #5
    Ok, thanks Carlos. I suspected this.

    So, how do I get round this??

    Any suggestions folks??

  6. #6
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi,

    just take the static off. You may use this:
    HTML Code:
    <html>
    <head>
    <script language="VBScript">
    Sub Test
       tnow = Time + TimeSerial(0, 1, 0)
       Do Until Time > tnow
    	   MsgBox Time
       Loop
    End Sub
    </script>
    </head>
    <body onload="Test">
    Tested!
    </body>
    </html>
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  7. #7
    Thanks my friend, sorry for the delay in getting back. Spun off in an Excel charts whirlwind!!

  8. #8
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    You are welcome and thanks for the help on my post!
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •