Solved

keeping track of option buttons value

Posted on 1998-12-29
8
184 Views
Last Modified: 2010-05-03
I have a few forms which call each other and they have the "next" and " back" button. Each form contains a few options button. So when i presses "next", i unload the previous form and "show" the current form.
But when i presses "back" the values of the options button is gone. How do i keep track of it?
0
Comment
Question by:ute
8 Comments
 
LVL 1

Expert Comment

by:BabyFace
ID: 1453143
Hi,

You could declare a member variable which holds the index of the option button selected.
In the Unload Event of the form, you could scan the option button control array to
find which option button is currently selected. Store it's index in the previously
declared member variable. In the Load event of the form, set the option button, with
the index of the member variable, to true.

That is how u do it.
Or instead of unloading the form.
You could hide it.
Ex:
Form1.hide
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1453144
Why don't you use "SSPanel"s instead of multi_form ,
you can replace more than one panel in one form , and they behave as you want.
and without the problem you mentioned.

0
 
LVL 1

Expert Comment

by:hddp666
ID: 1453145
I would use public variables, declared in a module, to hold the value of the options. When the form first loads, the design-time values (default values) of the options are stored in the global variables. When the user clicks an option to select or deselect it, the global variables are updated. When the form is unloaded, the global variables are updated again. When the form is reloaded, the old values are used to set the option values where they were.

' PUT THIS INTO A MODULE (NOT A FORM)
Option Explicit

Public Form1State(5) As Boolean ' Option On/Off variable
Public Form2State(5) As Boolean
Public Form3State(5) As Boolean

Public FormLoad(3) As Boolean ' "Form loaded before?" variable

Option Explicit

' Put this in the first form to load, an invisible form,
' copyright notice, or whatever (no options). If your Options are
' in MDI child forms, put this in the MDI parent.
' Notice that arrays are counted 0, 1, 2, 3...

Private Sub Form_Load()
Dim i As Integer

   For i = 0 To 2
      FormLoad(i) = False ' None of the option forms loaded yet
   Next i
   Unload Me ' Delete this if placed in an MDI Parent form
End Sub


' Paste copies of these two subs into each form that has
' Options. Change the number '1' as needed to correspond to the
' form's number. You can set whatever default values you want for
' the Options at design time, and they will be the first values
' stored in the public variables.

Private Sub Form_Load()
Dim i As Integer

   If FormLoad(1) = False Then ' First time form loaded
      For i = 0 To 4 ' Store the design value in the public variable
         Form1State(i) = Option1(i).Value
      Next i
   ElseIf Form1Load(1) = True Then ' Form loaded before
      For i = 0 To 4 ' Get the value from the public variable
         Option1(i).Value = Form1State(i)
       Next i
   End If
   Option1(i).Visible = True
   FormLoad(1) = True ' The form has loaded

End Sub
   

Private Sub Form_QueryUnload()

   For i = 0 To 4
      If Option1(i).Value = True Then
         Form1State(i) = True
      Else
         FormState(i) = False
      End If
   Next i

End Sub

Private Sub Option1_Click(Index As Integer)

   For i = 0 To 4
      If Option1(i).Value = True Then
         Form1State(i) = True
      Else
         FormState(i) = False
      End If
   Next i

End Sub


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:a111a111a111
ID: 1453146
The best way to keep the value of an object is on-disk storage.

use text file, datebase or the registry to do so.

Write the value to a file and later read the value from the file.

sample:

set the value of a property:
Object.PropertyName = PropertyValue

retrieve the value of a property:
propertyValue = Object.PropertyName

You can do so for your option buttons.

I hope it helps.
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1453147
Ute, the proposed answer appears to assume that the options on a given form are mutally-exclusive, like radio buttons. My solution does not have this limitation.

alllalllalll, I don't think such permanent storage of the option values is what is needed here. The only need is for run-time storage of the options while the program is in use. Your answer is similar to storing recently visited websites in a cache, or temporary internet files directory. A good solution, but maybe overkill.
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1453148
Ute, I forgot to mention a couple of minor errors in the code I sent. First, get rid of the line near the middle of the code:

Option1(i).Visible = True

I have NO idea where that came from (left field?).

Also, the Form_QueryUnload event has some variables that are passed to it. Here are the declarations from the VB online help:

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
Private Sub MDIForm_QueryUnload(cancel As Integer, unloadmode As Integer)


0
 

Author Comment

by:ute
ID: 1453149
well hddp666, your codes worked well... you can propose your answer...
0
 
LVL 1

Accepted Solution

by:
hddp666 earned 50 total points
ID: 1453150
Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question