# Visual Basic Help



## shuggans (Feb 6, 2011)

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?


----------



## shuggans (Feb 6, 2011)

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


----------



## streetfighter 2 (Feb 6, 2011)

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 '='?

```
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".


----------



## FordGT90Concept (Feb 6, 2011)

ReadAllText reads the entire text file as a string.  If the file is only supposed to contain True, you need to make it:

```
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.


----------

