Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving information for startup 1

Status
Not open for further replies.

orisons

Programmer
Feb 18, 2002
49
CA
I have a progrm I am trying to write (yes still working on it) now I have a form with loads of checkboxes (about 20) now onnce a user selects one of them it is added to a listbox. how can I save what check boxes have been checked and then when the program is restarted the same chk/bxs will be checked??????
this is sort of thrown me. Please take into account I am a newbie (plank of wood in front of computer comes to mind) any help would be much appriciated>
 
One quite simple option comes to mind, especially if the checkboxes are an array of controls.

To save the configuration

dim CheckBoxConfig as String
dim FileHand as integer

CheckBoxConfig = ""
if its a control array then do this
for i = 0 to NumberCheckboxes - 1
CheckBoxConfig = CheckBoxConfig & iif(chkChkBox(i).Value = vbChecked, "1", "0")
next i
if its not a control array then do this
CheckBoxConfig = CheckBoxConfig & iif(chkChkBox01.Value = vbChecked, "1", "0")
CheckBoxConfig = CheckBoxConfig & iif(chkChkBox02.Value = vbChecked, "1", "0")
CheckBoxConfig = CheckBoxConfig & iif(chkChkBox03.Value = vbChecked, "1", "0")
CheckBoxConfig = CheckBoxConfig & iif(chkChkBox04.Value = vbChecked, "1", "0")

filehand = freefile
open "chkcnfg.txt" for output as #filehand
print #filehand, CheckBoxConfig
close #filehand


When the program restarts, read the config file and initialize


dim CheckBoxConfig as String
dim FileHand as integer

filehand = freefile
open "chkcnfg.txt" for input as #filehand
input #filehand, CheckBoxConfig
close #filehand

if its a control array then do this

for i = 0 to NumberCheckboxes - 1
chkChkBox(i).Value = IIf(Mid(CheckBoxConfig, i+1, 1) = "1", vbChecked, vbUnchecked)
next i
[if its not a control array then do this]
chkChkBox01.Value = IIf(Mid(CheckBoxConfig, 1, 1) = "1", vbChecked, vbUnchecked)
chkChkBox02.Value = IIf(Mid(CheckBoxConfig, 2, 1) = "1", vbChecked, vbUnchecked)
chkChkBox03.Value = IIf(Mid(CheckBoxConfig, 3, 1) = "1", vbChecked, vbUnchecked)
chkChkBox04.Value = IIf(Mid(CheckBoxConfig, 4, 1) = "1", vbChecked, vbUnchecked)


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
thank you for your reply I will try this
my checkboxes are in an arry (I will have three sets) but I dont think the method will change any for for more than one arry
again thankyou







 
I have tried it and it works a treat now I have shown below (this was just to test it with 4 chkbxs on a form)
now I had to include a cmd button to update the file can I do this when any of the chkbxs is clicked I tried but because itwas an arry couldnt get it on anyother but the first chkbox (prob me being stupid)


Private Sub Command1_Click()
Dim CheckBoxConfig As String
Dim FileHand As Integer

CheckBoxConfig = ""
For i = 0 To 3
CheckBoxConfig = CheckBoxConfig & IIf(Check1(i).Value = vbChecked, "1", "0")
Next i
FileHand = FreeFile
Open "chkcnfg.txt" For Output As #FileHand
Print #FileHand, CheckBoxConfig
Close #FileHand

End Sub

Private Sub Form_Load()
FileHand = FreeFile
Open "chkcnfg.txt" For Input As #FileHand
Input #FileHand, CheckBoxConfig
Close #FileHand



For i = 0 To 3

Check1(i).Value = IIf(Mid(CheckBoxConfig, i + 1, 1) = "1", vbChecked, vbUnchecked)
Next i

End Sub
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top