[Tutorial]Saving Checkbox True/False Statement

Posts 1–12 of 12 · Page 1 of 1
[Tutorial]Saving Checkbox True/False Statement
Well, credits probably go to Nextge1n for telling me =D

So basiclly what this does is the following:

It saves your "decession" whether you picked False/True.

If the usual value is false and you start your program and set it to true and restart your program, the checkbox will still be checked.

This saves a lot of time. I was actually about to do it way more complicated ->

Code:
Dim box as string

if checkbox1.checked = true
box = 1
Saving this into an .ini...

On form load...

Loading the .ini settings...

->
Code:
if box = 1 then
checkbox1.checked
else
checkbox.checked = false
Forget about my SHITTY idea!

Let's start

1. Go to your form properties(Project-Explorer -> Righ***ick on your project -> Properties)



2. Go to Settings

3. Change the Name "Settings" to "Checked" or whatever you want it to be.
Let's name it "Checked1337."

Hit enter.



Here comes the code...

On Checkbox1.checked event:

Code:
If checkbox1.checked = true Then
My.Settings.Checked1337 = "True"
else 
my.settings.checked1337 = "False"
end if
My.Settings.save
You might also use "1" instead of True or whatever you like..

On Form Load:

Code:
If My.settings.Checked1337 = "True" Then
checkbox1.checked = true
else
checkbox1.checked = false
end if
It should look like this:

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.Checked1337 = "True" Then
            CheckBox1.Checked = True
        Else
            CheckBox1.Checked = False
        End If
    End Sub

  
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            My.Settings.Checked1337 = "True"
        Else
            My.Settings.Checked1337 = "False"
        End If
        My.Settings.Save()

    End Sub
End Class
This tutorial is very noob-friendly

Everyone should be able to understand it.

Thanks to nextgen1.

I didn't check if the code works, it should anyways.

Written by: Meh
Special Thanks to: Nextgen1 AGAIN for explaining me <3
Good for the beginners!
Good Job Posting it,
BASIC BASIC BASIC!!!
oh, and u can use my.settings...
What is this?

Meh thanks for the post I guess.

This section needs more activity IMO.
This section needs more activity IMO.
I agree. Sending you a Pm on somethings soon
hey does this work for a textbox
Quote Originally Posted by hopefordope View Post
hey does this work for a textbox
If you saying that i think you want then yes.

On form_load put this:

[php]If My.Settings.Checked1337 = "True" Then
CheckBox1.Checked = True
TextBox1.Text = "your text here"[/php]

Simple, that will load the textbox's text every time you load it .
Sorry, Lag had me double post.
Use

Use this on form close , or button, or on text1_changed
IO.File.WriteAllText("File Location to save + Filename.Extension", TextBox1.Text)


Use this in form load

TextBox1.Text = IO.File.ReadAllText("FileLocation/File.extension)
Posts 1–12 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us