Using %temp% and %user% in vb?

Discussion in 'Programming' started by Nuclear_Ice, Feb 24, 2010.

  1. #1
    Hi guys, I have this code here:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Dir("%temp%\test.txt") <> "" Then
                Label1.ForeColor = Color.Red
                Label1.Text = ("Found!")
            Else
                Label1.ForeColor = Color.Green
                Label1.Text = ("Passed!")
            End If
        End Sub
    
    Code (markup):
    So if the file test.txt in the %temp% (C:\Documents and Settings\Nick\Local Settings\Temp) folder is found it will display red and change the label to found..

    But for some reason it doesn't read like console or batch files do? Is there a way to recognize the directories using something similar to %user% and %temp% and %sysroot% instead of typing out the whole directory? If I could I would type out the whole directory but if I ran the program on another computer, it doesn't have the same username as me etc....


    Any ideas? Thanks!
     
    Nuclear_Ice, Feb 24, 2010 IP
  2. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It sounds like VB6 to me....

    You can use Window API functions to get these paths. See this for getting special paths using VB6.
     
    NeoCambell, Feb 25, 2010 IP
  3. Nuclear_Ice

    Nuclear_Ice Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Oh sorry, I should have mentioned. :p

    It's VB 2008.
     
    Nuclear_Ice, Feb 27, 2010 IP
  4. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0