Solved

keeping track of option buttons value

Posted on 1998-12-29
8
181 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now