Call all settings at once

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Hello -

Is there a way to call All settings at once?

Example:

If I have 100 check boxes on a form and they are all tied to My.Settings (boolean) and I need to have the following code, but want to condense it to a simple call instead:

VB.NET:
If My.Settings.Checkbox1 = True Then
label1.Visible = True
Else
label1.Visible = False
End If
If My.Settings.Checkbox2 = True Then
label2.Visible = True
Else
label2.Visible = False
End If
If My.Settings.Checkbox3 = True Then
label3.Visible = True
Else
label3.Visible = False
End If
If My.Settings.Checkbox4 = True Then
label4.Visible = True
Else
label4.Visible = False
End If
If My.Settings.Checkbox5 = True Then
label5.Visible = True
Else
label5.Visible = False
End If
If My.Settings.Checkbox6 = True Then
label6.Visible = True
Else
label6.Visible = False
End If
If My.Settings.Checkbox7 = True Then
label7.Visible = True
Else
label7.Visible = False
End If
If My.Settings.Checkbox8 = True Then
label8.Visible = True
Else
label8.Visible = False
End If
If My.Settings.Checkbox9 = True Then
label9.Visible = True
Else
label9.Visible = False
End If
If My.Settings.Checkbox10 = True Then
label10.Visible = True
Else
label10.Visible = False
End If
etc....

Would I have to right all 100 or is there a way to call them all at once?

Thanks in advanced

daveofgv
 
Construct the name of the setting in a loop and use My.Settings(name). That is accessing default Item property which is type Object, so with Option Strict you need to cast it to type Boolean with CBool.

Also, this code:
If My.Settings.Checkbox6 = True Then
label6.Visible = True
Else
label6.Visible = False
End If
you should write like this:
label6.Visible = My.Settings.Checkbox6
 
Back
Top