?
Solved

keeping track of option buttons value

Posted on 1998-12-29
8
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 total points
ID: 1453150
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 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