Results 1 to 24 of 24

Thread: [RESOLVED] SpecialFolder returning numerical value?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    West Warwick, RI
    Posts
    193

    Resolved [RESOLVED] SpecialFolder returning numerical value?

    For some reason when I try to set a path to 'Environment.SpecialFolder.Windows' the path ends up being '36', even when dimming as a string - What the heck am I doing wrong?

    Code:
            Dim Install As String = Environment.SpecialFolder.Windows
            MsgBox(Install & "\qcinfs\temp.inf")
    Outputs as '36\qcinfs\temp.inf' :-(
    Last edited by relentlesstech; Dec 25th, 2013 at 11:12 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    West Warwick, RI
    Posts
    193

    Re: SpecialFolder returning numerical value?

    Figured it out:

    Code:
            Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
            MsgBox(Environment.CurrentDirectory)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] SpecialFolder returning numerical value?

    What you're doing is not reading the documentation. The Help menu is there in your IDE for a reason. Environment.SpecialFolder is an enumeration and, like all enumerations, is a list of named labels that correspond to numeric values and those numeric values mean something when used properly. Not surprisingly, the documentation for that enumeration tells you how to use it properly. Always read the documentation first.

    By the way, use Path.Combine to combine two partial paths into a single path.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: SpecialFolder returning numerical value?

    Quote Originally Posted by relentlesstech View Post
    Figured it out:

    Code:
            Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
            MsgBox(Environment.CurrentDirectory)
    No, you didn't figure it out. You just used a different, vastly inferior option.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by relentlesstech View Post
    For some reason when I try to set a path to 'Environment.SpecialFolder.Windows' the path ends up being '36', even when dimming as a string - What the heck am I doing wrong?

    Code:
            Dim Install As String = Environment.SpecialFolder.Windows
            MsgBox(Install & "\qcinfs\temp.inf")

    Outputs as '36\qcinfs\temp.inf' :-(
    I wouldn't have used either, there are other ways to do it, but if that's how you want to display it, but this only gives you the name, assuming that's what you want? Otherwise use System.IO.Path class

    Code:
    Dim WinFolder As String = Environment.SpecialFolder.Windows.ToString
            MsgBox(WinFolder & "\qcinfs\temp.inf")

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by Mucker View Post
    I wouldn't have used either, there are other ways to do it, but if that's how you want to display it, but this only gives you the name, assuming that's what you want? Otherwise use System.IO.Path class

    Code:
    Dim WinFolder As String = Environment.SpecialFolder.Windows.ToString
            MsgBox(WinFolder & "\qcinfs\temp.inf")
    Nope, that ain't it. You make take a look at that documentation yourself.

  7. #7
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Jmc if he is only looking for it to output the name of the folder, then my code will do that as tested below. So what isn't it?

    Attachment 108737

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Code:
            Dim aFile As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "qcinfs\temp.inf")
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: [RESOLVED] SpecialFolder returning numerical value?

    The point here is that SpecialFolder is an enum, and JMC is pointing out that you're not reading the documentation to see why it's returning a numeric value, even though it should (because it's an enum). The Environment.GetFolderPath() function takes the enum as a parameter and turns that into the folder location you want as a string. Path.Combine() is self-explanatory.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by Mucker View Post
    Jmc if he is only looking for it to output the name of the folder, then my code will do that as tested below. So what isn't it?

    Attachment 108737
    He's not looking for the name of the folder. He's looking for the path of the folder. If you check out the members of the Environment.SpecialFolder enumeration then you'll see that many of them don't even return the folder name from their ToString method. You could have saved yourself looking a fool by taking 30 seconds to read the documentation.

  11. #11
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by jmcilhinney View Post
    He's not looking for the name of the folder. He's looking for the path of the folder. If you check out the members of the Environment.SpecialFolder enumeration then you'll see that many of them don't even return the folder name from their ToString method. You could have saved yourself looking a fool by taking 30 seconds to read the documentation.
    Lets get a few things straight here. First keep your insults to yourself and dont call me a fool. There is no need for disrespect. You dont even know me... and I am not disrespecting you.

    Secondly, I do this for a hobby and i do what i know works for me based on practice and things i try to learn, regardless if its meant to work like that or not. if the enum is meant to represent a numerical value. Cool beans! Obviously the value represents a folder name if I can return it from a string. So who cares if I used it inappropriately to display the folder name. Is that a reason to insult me?

    If you want people on this site to learn and not post " Stupid " things, then instead of saying read the documentation; which is as good as saying read Google! (Which defeats the purpose of the forum.) Why don't you provide a link to that exact documentation you're referring us to learn and try to explain it to us instead? To much work for you jmc?

    According to the screenshots, it will do that for each and every special directory listed. so who cares?

    Attachment 108745Attachment 108747Attachment 108749Attachment 108751

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by Mucker View Post
    Lets get a few things straight here. First keep your insults to yourself and dont call me a fool. There is no need for disrespect. You dont even know me... and I am not disrespecting you.

    Secondly, I do this for a hobby and i do what i know works for me based on practice and things i try to learn, regardless if its meant to work like that or not. if the enum is meant to represent a numerical value. Cool beans! Obviously the value represents a folder name if I can return it from a string. So who cares if I used it inappropriately to display the folder name. Is that a reason to insult me?

    If you want people on this site to learn and not post " Stupid " things, then instead of saying read the documentation; which is as good as saying read Google! (Which defeats the purpose of the forum.) Why don't you provide a link to that exact documentation you're referring us to learn and try to explain it to us instead? To much work for you jmc?

    According to the screenshots, it will do that for each and every special directory listed. so who cares?

    Attachment 108745Attachment 108747Attachment 108749Attachment 108751

    John didn't say you are a fool, just that you looked foolish. If you turn Option Strict On, as it should always be, your solution will not compile.

    When you object to reading the documentation you seem to imply that you want someone to read it for you, and then regurgitate here. Maybe a link to the page in question would help. Look under Remarks here: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

    If you want the correct answers here, then all answers have to be scrutinized for correctness, which is not the same as it works under certain scenarios. In this case your answer only works if Strict is Off.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Thanks dbasnett for the link. Regardless, looking a fool or being called a fool is as good as calling one a fool in my eyes. Nevertheless I've already forgotten about it.

    Back on topic, why is it that my application compiles when Option Strict is On Or Off? :S

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: [RESOLVED] SpecialFolder returning numerical value?

    When I copied your code I only got Environment.SpecialFolder.Windows which will not compile. The issue is that you are not getting the path to the folder, just a name.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Well if you are only using part of my code it shouldn't compile, Part:
    Code:
    Environment.SpecialFolder.Windows
    but it does with my full code:
    Code:
    Dim WinFolder As String = Environment.SpecialFolder.Windows.ToString
            MsgBox(WinFolder & "\qcinfs\temp.inf")
    I think there may have been a misunderstanding along the way... because if you use the full code i posted it outputs the foldername. --option strict on/off. Obviously if you use part of the code, it wont compile as you are not specifying anything and the expression is not a method. so what was the argument again?

  16. #16
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: [RESOLVED] SpecialFolder returning numerical value?

    so what was the argument again?
    The argument is that the OP wanted to set a path, in which case the .ToString method would only return the SpecialFolder's name rather than it's path(In most, if not all cases). The suggestion is to use Environmnet.GetFolderPath and to set the path by using IO.Path.Combine.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: [RESOLVED] SpecialFolder returning numerical value?

    The debate is rather irrelevant, as what was wanted was the path (see post #1).

    As such the proper answer is what dbasnett posted earlier.
    Quote Originally Posted by Mucker View Post
    because if you use the full code i posted it outputs the foldername.
    No it doesn't... what it outputs is the enumeration name.

    By definition, you would get exactly the same result by replacing Environment.SpecialFolder. and .ToString with quotes, eg:
    Code:
    Dim WinFolder As String = "Windows"
    Regardless, looking a fool or being called a fool is as good as calling one a fool in my eyes.
    They are very different things. Doing something foolish is temporary (and we all do it at times), while being a fool is permanent and therefore a much nastier thing to say about someone.

  18. #18
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by si_the_geek View Post
    The debate is rather irrelevant, as what was wanted was the path (see post #1).

    As such the proper answer is what dbasnett posted earlier.
    No it doesn't... what it outputs is the enumeration name.

    By definition, you would get exactly the same result by replacing Environment.SpecialFolder.
    So let me get this, the specialfolder.whatever is an enum representing a numerical value which used correctly acts as an numerical ID of some kind to identify a folder name? Correct or not? If i understand this right, is that why the number can be output as a foldername?

    Lol that's a bit of something to get your head around... Sorry this led on from me misunderstanding the question in the first post, based on his code, and question i thought he wanted the folder name.

  19. #19
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: [RESOLVED] SpecialFolder returning numerical value?

    So let me get this, the specialfolder.whatever is an enum representing a numerical value which used correctly acts as an numerical ID of some kind to identify a folder name? Correct or not? If i understand this right, is that why the number can be output as a foldername?
    I would really open up a new thread about this, but I'll go ahead and answer it anyways. That's correct. There are a few different Enums, just take a look at DialogResult and a ProgressBar's Style. Just as you can do:
    Code:
    If MessageBox.Show("Please click ok", Me.Text, MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
    You can also do:
    Code:
    If MessageBox.Show("Please click ok", Me.Text, MessageBoxButtons.OKCancel) = 1 Then
    You can create Enumerators or Enums like this:
    Code:
    Public Enum FooEnum
        FooVal1
        FooVal2
        FooVal3
    End Enum
    And optionally you can set the value of the enum too:
    Code:
    Public Enum FooEnum
        FooVal1 = 10
        FooVal2 = 50
        FooVal3 = 100
    End Enum
    So if you were to call the ToString method on that custom Enum above:
    Code:
    Console.WriteLine(FooEnum.FooVal1.ToString)
    The output would be FooVal1
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  20. #20
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Right, good examples! I totally get it now. Thanks for explain that Dday.

  21. #21
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: [RESOLVED] SpecialFolder returning numerical value?

    This little snippet shows the value(integer) of the enum, the name associated with the value, and the path associated with the value.

    Code:
            For Each foo As Integer In [Enum].GetValues(GetType(Environment.SpecialFolder))
                Debug.WriteLine(foo & "  " & [Enum].GetName(GetType(Environment.SpecialFolder), foo) & "  " & Environment.GetFolderPath(DirectCast(foo, Environment.SpecialFolder)))
            Next
            Stop
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  22. #22
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: [RESOLVED] SpecialFolder returning numerical value?

    In addition to what has been posted above, a bit of extra info:
    Quote Originally Posted by Mucker View Post
    So let me get this, the specialfolder.whatever is an enum representing a numerical value which used correctly acts as an numerical ID of some kind to identify a folder name? Correct or not?
    Not quite, it does not in any sense represent a folder name.

    If used as a parameter to a particular function (which knows that the numeric value has a particular meaning) such as Environment.GetFolderPath, it will allow that function to return the path to a special folder.

    If i understand this right, is that why the number can be output as a foldername?
    The name used is basically equivalent to a variable name, and that is what is being output.

    The names Microsoft use for enums are generally chosen quite well, so you can usually tell at a glance what they are meant to represent (if used appropriately), but they have no more meaning than any variable names.

    If instead of calling it SpecialFolder.Windows they had called it SpecialFolder.Bork , your code would output Bork (which would be of no use to the user), and it takes much more effort than directly setting the string to Bork in the first place.

  23. #23
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Quote Originally Posted by Mucker View Post
    Lets get a few things straight here. First keep your insults to yourself and dont call me a fool. There is no need for disrespect. You dont even know me... and I am not disrespecting you.
    Well, you kind of are. I suggested more than once that the documentation could show how to do this properly and you staunchly refused to read it apparently. I certainly don't claim to know everything but my post count and reputation should suggest that I know a few things. You might at least consider taking my advice in future. More often than not it will get you somewhere.

  24. #24
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2012
    Location
    Largo, FL.
    Posts
    1,836

    Re: [RESOLVED] SpecialFolder returning numerical value?

    Boys and Girls - lets try and keep the comments about each other off the site. Thank you.

Posting Permissions

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



Click Here to Expand Forum to Full Width