Solved

Application restarting at the same location

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 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