Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Application restarting at the same location

Posted on 1998-08-04
5
Medium Priority
?
154 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 20 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

963 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