Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variables Question

    is it alright to use the $ to define a variable in ASP like in PHP? i know you don't have to but i think it would be easyer to read the code if you add a $ sign in front of the variables. so anyways, is there a problem with that?

  • #2
    New Coder
    Join Date
    Oct 2003
    Location
    19° 26' N, 99° 7' W
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I get the following error, do you?

    ************
    Microsoft VBScript compilation error '800a0408'

    Invalid character

    /testing/test1.asp, line 3

    Dim $Variable1
    -----^
    *******************

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You declare variables in ASP/VBScript using the "Dim" keyword, for "Dimension".

    Example:

    Code:
    Dim strFruit
    
    strFruit = "Apple"
    Yeah, it's not common to other languages... but what do you want from Microsoft? That's just the way it is.

    P.S. Regarding your statement "I know you don't have to", that's not always true.

    If you want to be able to use a variable globally (i.e. something used outside of a subroutine or function that you want to use inside such constructs), you HAVE to dimension it in order for it to carry a value.

    A good practice for making sure you DO declare such variables is using "Option Explicit" at the top of your VB scripts.

    A colleague I work with often questions why I do that... if he only realized how many times I've helped him fix things (and/or fixed errors in his scripts for the same reason) because he DOESN'T use Option Explicit, he'd quit asking me that question!!!
    Last edited by whammy; 12-30-2003 at 03:54 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    I think what he/she meant with "I know you don't have to" is "I know you don't have to (use the $ sign in a variable)"


  •  

    Posting Permissions

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