1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Visual Basic Help

Discussion in 'Programming & Webmastering' started by shuggans, Feb 6, 2011.

  1. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    my application uses streamwriter to save a Boolean value of true or false to a text file. i did this for the prurpose of a config setting for the application to read from and set a variable value of true or false depending on whatever the text file said each time the program starts up. however, i cant seem to get it to read the value from the file.
    heres the block of code.

    If My.Computer.FileSystem.ReadAllText("SlingShot_CommonsDashboard_Enabled.txt") = True Then
    var_CommonsDashboard_Start = True
    ElseIf My.Computer.FileSystem.ReadAllText("SlingShot_CommonsDashboard_Enabled.txt") = False Then
    var_CommonsDashboard_Start = False
    End If
    If var_CommonsDashboard_Start = True Then
    Console_CommonsDashboard.Show()
    End If
    any ideas?
     
  2. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    in otherwords, i need a way to read the one word in the text file when the program starts, and set a variable with the value of true or flase depending on what that text file says
     
  3. streetfighter 2

    streetfighter 2 New Member

    Joined:
    Jul 26, 2010
    Messages:
    1,658 (1.06/day)
    Thanks Received:
    732
    Location:
    Philly
    Your file is named "SlingShot_Comm onsDashboard_Enabled.txt"? That's a weird name for a file.

    Shouldn't you be using String.Equals instead of '='?
    Code:
    If String.Equals(My.Computer.FileSystem.ReadAllText("SlingShot_Comm onsDashboard_Enabled.txt"), "True") Then
        var_CommonsDashboard_Start = True
    Else
        var_CommonsDashboard_Start = False
    End If
    If var_CommonsDashboard_Start = True Then
        Console_CommonsDashboard.Show()
    End If
    Hopefully that works but I haven't done VB in a couple years. I'm concerned about how ReadAllText handles the special characters '\0' and '\n'; it may be that the file contents should be compared to "True\0".
     
    Last edited: Feb 6, 2011
  4. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,838 (6.26/day)
    Thanks Received:
    3,707
    Location:
    IA, USA
    ReadAllText reads the entire text file as a string. If the file is only supposed to contain True, you need to make it:
    Code:
    If My.Computer.FileSystem.ReadAllText("SlingShot_Comm onsDashboard_Enabled.txt") = "True" Then
    So that it performs a string comparison instead of comparing a string to a boolean value.
     
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page