Solved

Application restarting at the same location

Posted on 1998-08-04
5
147 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…

776 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