jeudi 17 mai 2018

Checkbox state saved in text file vb.net

This is my code:

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    Dim checkboxvalue As String = File.ReadAllText(Application.StartupPath + "\discordstatus.txt")
    If checkboxvalue = "1" Then
        CheckBox1.Checked = True
    End If

    If checkboxvalue = "0" Then
        CheckBox1.Checked = False
    End If

    If CheckBox1.Checked = "1" Then
        Dim fileReader As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath + "\discordstatus.txt").Replace("0", "1")
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\discordstatus.txt", fileReader, False)
    End If

    If CheckBox1.Checked = "0" Then
        Dim fileReader As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath + "\discordstatus.txt").Replace("1", "0")
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\discordstatus.txt", fileReader, False)
    End If
End Sub

I want it to (when unchecked) put 0 in the text file and (when checked) put a 1 in the text file, this code lets me control the status by changing the number in the file manually, but i cant check or uncheck the checkbox, please help.




Aucun commentaire:

Enregistrer un commentaire