+ Reply to Thread
Results 1 to 4 of 4

Difference between Environ("USERNAME") and Environ$("USERNAME")

  1. #1
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Difference between Environ("USERNAME") and Environ$("USERNAME")

    I'm even ashamed of asking but what is the difference in using Environ("USERNAME") or Environ$("USERNAME")?

    And from my readings, coders advice to use an "Option Explicit" factor. Why? And where to you put it in your code?

    EDIT: For instance, I deviced the following code from help from all around. I placed a question regarding part of it last week here but no answer, and I needed help on something related on MrExcel, but I figured it already, so I'll advice them shortly:
    Please Login or Register  to view this content.
    As you notice my code is novice, do I need the Option Explicit thingy (or anything else) there? So far it works, so I'm so proud of myself...

    Thanks,
    Last edited by ron2k_1; 02-03-2011 at 05:08 PM.
    Ron
    Knowledge is knowing that a tomato and pepper are fruits. Wisdom is knowing whether to put these in a fruit salad

    Kindly

    [1] Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks
    [2] Mark your post [SOLVED] if it has been answered satisfactorily by editing your original post in advanced mode.
    [3] Thank (using the little scale) those that provided useful help; its nice and its very well appreciated

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Difference between Environ("USERNAME") and Environ$("USERNAME")

    Hi ron2k_1,
    When you use "Option Explicit" in the first line of module you force the declaration of all variables using the Dim as string long ect. This sets memory aside for the variable and the code know how to use the value. Very good idea to always use it for error checking.
    Other wise you get an error.

    the $ is short hand for declaring string
    Dim UserName As String can also be dim UserName$
    hope it helps
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Difference between Environ("USERNAME") and Environ$("USERNAME")

    But you can do without:
    Please Login or Register  to view this content.



  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Difference between Environ("USERNAME") and Environ$("USERNAME")

    For common perspectives among professionals, ...

    Chip Pearson has a good explanation at http://www.cpearson.com/excel/DeclaringVariables.aspx

    See Use Option Explicit and Avoid Variants at http://www.fmsinc.com/tpapers/vbacode/

    See http://blogs.msdn.com/b/developingfo...do-in-vba.aspx

    Relevant to ASP rather thanVBA, but same principal, see http://www.4guysfromrolla.com/webtec...ate/faq6.shtml
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1