Solved

Application restarting at the same location

Posted on 1998-08-04
5
144 Views
Last Modified: 2010-05-03
I want my application to start at the same location from where it is closed. To be brief if the user moves the window to some other location and quit the application, when he restarts the application it should start from where it is quited.
 I want to konw how I can get the co-ordinates while applicaiton termination, save them in registry and use them while restart.
0
Comment
Question by:monalisa
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
cymbolic earned 10 total points
ID: 1467727
You have to define your own scheme for detailing where you are in your program.  VB does not support any identification method regarding which routine you are in.  Your best bet is to have a common variable, that you set each time you enter a routine, then save when the app is terminated.  On the front end, you'll need a case statement to start the saved routine when your program is loaded.  

You are on the right track for human useability.  It's unfortunate that so many of our expensive commercial programs are too dumb to do the same thing.

In terms of saving and restoring your memory variable, you can use the registry by using the GetSetting and SaveSetting routines provided in VB. These are in the help system and provide direct update and access to the registry.  Also, you could just as well use a small file saved in your App.Path directory to retain and return your variable, accessed and updated by file i/o.  
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467728
In the main form's unload event, place the following code:
Private Sub Form_Unload(Cancel As Integer)
  SaveSetting appname := "MyApp", section := "Startup", key := "Top", setting := Me.Top
  SaveSetting appname := "MyApp", section := "Startup", key := "Left", setting := Me.Left
  SaveSetting appname := "MyApp", section := "Startup", key := "Height", setting := Me.Height
  SaveSetting appname := "MyApp", section := "Startup", key := "Width", setting := Me.Width
End Sub

Then, in the code which starts your app (Sub Main?), place the following code:
Sub Main()

  Dim fTop As Single
  Dim fLeft As Single
  Dim fHeight As Single
  Dim fWidth As Single

  fTop = GetSetting(appname := "MyApp", section := "Startup", key := "Top", default := Form1.Top)
  fLeft = GetSetting(appname := "MyApp", section := "Startup", key := "Left", default := Form1.Left)
  fHeight = GetSetting(appname := "MyApp", section := "Startup", key := "Height", default := Form1.Height)
  fWidth = GetSetting(appname := "MyApp", section := "Startup", key := "Width", default := Form1.Width)

  Form1.Move fLeft, fTop, fWidth, fHeight
End Sub
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467729
cymbolic:
Huh?
0
 

Author Comment

by:monalisa
ID: 1467730
I am sorry for the delayed response, lot of thanks for your help.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467731
Unless you understood cymbolic's answer (I believe it was an answer to another question), please reject it sp that I may post my answer.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

758 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

16 Experts available now in Live!

Get 1:1 Help Now