[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

keeping track of option buttons value

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
ute
Asked:
ute
1 Solution
 
BabyFaceCommented:
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
 
InteqamCommented:
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
 
hddp666Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
a111a111a111Commented:
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
 
hddp666Commented:
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
 
hddp666Commented:
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
 
uteAuthor Commented:
well hddp666, your codes worked well... you can propose your answer...
0
 
hddp666Commented:
Thanks.
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now