Solved

Saving options on a form

Posted on 1998-09-03
16
176 Views
Last Modified: 2010-04-30
I have nine frames on a form & each frame containes 5 array option buttons that change the color of a command button when you click on the option button. Each option button represents a different color.  How do I save the changes each time an option button is selected and the color of the command button changes.  Or at least save the current properties prior to unloading the form?
0
Comment
Question by:tbrasher
  • 11
  • 5
16 Comments
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 100 total points
ID: 1432837
Hi,
You have to use an external file.

use Text file to write and then read the information from
or an INI file or enev the registry..

I hope it helps.

0
 

Author Comment

by:tbrasher
ID: 1432838
Could you give me more information on how to use an external file?  I'm not sure I understand how the color will be saved on the command button.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432839
Hi,
Open file for output ' Write into a text file.


Befor exit the program or in Qureyunload"
 or
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
record your vars
place out file here
End Sub

to record your color use this :
Private Sub Command2_Click()
Dim a
a = Form1.BackColor
MsgBox Hex(a)
End Sub

then print #1 , ' the var in this example  it is a

and when you start the program again
use in Form_Load
1. load the text file
2. restore the colors.
3. place the color in the objects as
label1.backcolor = a

if you need more help here let me know.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:tbrasher
ID: 1432840
I have a total of 39 forms, do I need to do this for every form? Also, in the Private Sub Form_Query Unload what is "record your vars"??  Is this the syntax?  When you start the program again in the Form_Load is the 1, 2, and 3 the actual syntax or can I find this in the help files?

I'm new at this and have a deadline of September 12 - I can use all of the help I can get.  I appreciate it!
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432841
Okay I will make a sample project for you and I will post the concept here and
I will give you a URL that you can download the complete project ...Soon..

I am going to work on that a about 1/2 an hour..

0
 

Author Comment

by:tbrasher
ID: 1432842
I appreciate your help - Thanks very much!
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432843
Hi, I am working on the project and will call you soon.

Shay.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432844
Hi, There is a nice progress here stand by in 1/2 an hour.

0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432845
Okay the example is here:

and you can download the complete project from http://www.hili.com/~shay/savecolor.zip

============= start ===========

Option Explicit

Private Sub cmdExit_Click()
Dim AColor
AColor = Command1.BackColor
Open "SaveColor.txt" For Output As #1
Print #1, Command1.BackColor 'AColor
Close #1
Unload Me ' You can delete this line
End Sub

Private Sub Form_Load()
Dim ColorLine
Dim AColor
On Error Resume Next
Open "SaveColor.txt" For Input As #1
While Not EOF(1)
    Line Input #1, ColorLine
Wend
Close #1
AColor = ColorLine
Command1.BackColor = AColor
End Sub

' You don't need this Sub. It is an example only.
Private Sub optBlue_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(0, 0, 255)

End Sub
' You don't need this Sub. It is an example only.
Private Sub optGreen_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(0, 255, 0)

End Sub
' You don't need this Sub. It is an example only.
Private Sub optRed_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(255, 0, 0)
End Sub


============ end =============


shay.
0
 

Author Comment

by:tbrasher
ID: 1432846
I tried to get to the URL that you provided but I get an error message saying it doesn't exist.  I went to your homepage but can't find the file to download.  Help!

Thanks so much for helping me out - you're a lifesaver!

Traci
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432847
Okay the url is there now.

code correction:

============== start here =============

Option Explicit

Private Sub cmdExit_Click()
Dim AColor
AColor = Command1.BackColor
Open "SaveColor.txt" For Output As #1
Print #1, Command1.BackColor 'AColor
Close #1
Unload Me ' You can delete this line
End Sub

Private Sub Form_Load()
Dim ColorLine
Dim AColor
Dim ErrorHandler
On Error GoTo ErrorHandler
Open "SaveColor.txt" For Input As #1
While Not EOF(1)
    Line Input #1, ColorLine
Wend
Close #1
AColor = ColorLine
Command1.BackColor = AColor
 
ErrorHandler:
Exit Sub
End Sub

' You don't need this Sub. It is an example only.
Private Sub optBlue_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(0, 0, 255)

End Sub
' You don't need this Sub. It is an example only.
Private Sub optGreen_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(0, 255, 0)

End Sub
' You don't need this Sub. It is an example only.
Private Sub optRed_Click(Index As Integer)
Dim a
 Command1.BackColor = RGB(255, 0, 0)
End Sub


========= end here =========
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432848
the correction is here :

ErrorHandler:
       Exit Sub
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432849
Sorry guys.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432850
You must run the code twice for the first time;
Why?
It create a data (text) file to be use later.

I just hope to GAJS.
0
 

Author Comment

by:tbrasher
ID: 1432851
I tried your sample project and then incorporated it into my project - I'm only on form 1 but it is working so far!  I do have one more question: Do I have to open a seperate file for every command button?  As I said earlier, I have nine frames per page which includes a command button per frame.  Can't thank you enough for all of your help~
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432852
Well in general if you named the forms with Form1, Form2, Form3...Formn

You can use one data File and specify the form name and it's properties.

Shay.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

832 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