Home All Groups Group Topic Archive Search About

Newbie: remember chkbox from closed form

Author
15 Oct 2005 4:29 PM
stanto123
Hi, i want to set up an Options menu.
So i created the form and put a checkbox.

In order for the program to remember wether the chkbox is set or not, i
guess i'll have to read from an INI or the registry. Thats fine. But I
cannot get it to remember during the same session:

Main form -> Menu-Options -> Options form open and i check the chkbox
and close the small Options form. Back to Main. If I click on the
Options again, the check box is unchecked. I guess because i
reinitialize the form.

Whats the shortest/easiest way to do that? I dont want to store on an
ini file every during the same session of the program.

Thanx in advance
-steve

Author
15 Oct 2005 4:33 PM
AGP
keep the option in a variable and only save it when you exit the program.
And when you start the program , read the INI into the variable.

AGP

<stanto***@hotmail.com> wrote in message
Show quoteHide quote
news:1129393753.186770.258840@g49g2000cwa.googlegroups.com...
> Hi, i want to set up an Options menu.
> So i created the form and put a checkbox.
>
> In order for the program to remember wether the chkbox is set or not, i
> guess i'll have to read from an INI or the registry. Thats fine. But I
> cannot get it to remember during the same session:
>
> Main form -> Menu-Options -> Options form open and i check the chkbox
> and close the small Options form. Back to Main. If I click on the
> Options again, the check box is unchecked. I guess because i
> reinitialize the form.
>
> Whats the shortest/easiest way to do that? I dont want to store on an
> ini file every during the same session of the program.
>
> Thanx in advance
> -steve
>
Author
15 Oct 2005 7:27 PM
DanS
"AGP" <sindizzy.***@softhome.net> wrote in news:Mba4f.2721$tV6.2353
@newssvr27.news.prodigy.net:

> keep the option in a variable and only save it when you exit the program.
> And when you start the program , read the INI into the variable.
>
> AGP
>

save it whenever you press the OK button to close your options form.
Author
15 Oct 2005 9:45 PM
Larry Serflaten
<stanto***@hotmail.com> wrote
Show quoteHide quote
> Hi, i want to set up an Options menu.
> So i created the form and put a checkbox.
>
> In order for the program to remember wether the chkbox is set or not, i
> guess i'll have to read from an INI or the registry. Thats fine. But I
> cannot get it to remember during the same session:
>
> Main form -> Menu-Options -> Options form open and i check the chkbox
> and close the small Options form. Back to Main. If I click on the
> Options again, the check box is unchecked. I guess because i
> reinitialize the form.
>
> Whats the shortest/easiest way to do that? I dont want to store on an
> ini file every during the same session of the program.


One easy method is to pass in the current set to a function on the
form, that passes back a new set of option, including any changes.
For example, add a module and a Form2 to a new project.  On Form1
add a command button, and on Form2 add a command button and
two text boxes.  Paste in the code below, and see if that will fit your
need:  (If there is only one value needed, you can skip using a Type
and only pass the single value back and forth.  The Type just makes
it easy to pass several related values, such as user options)

LFS

'[ Module1]
Public Type Options
  X As Long
  Y As Long
End Type


'[ Form1]
Option Explicit
Private User As Options

Private Sub Command1_Click()
  User = Form2.GetOptions(User)
  MsgBox CStr(User.X) & ", " & CStr(User.Y)
End Sub


'[ Form2]
Option Explicit
Private User As Options

Private Sub Command1_Click()
  User.X = Val(Text1.Text)
  User.Y = Val(Text2.Text)
  Unload Me
End Sub

Private Sub Form_Load()
  Command1.Caption = "Accept"
End Sub

Friend Function GetOptions(Current As Options) As Options
  User = Current
  Text1.Text = User.X
  Text2.Text = User.Y
  Me.Show vbModal
  GetOptions = User
End Function