Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a default on form load

Status
Not open for further replies.

kevinf2349

Technical User
Sep 12, 2002
367
US
Hi

I want a user to be able to select a file (or files) that will be used the very first time they use an application. This value will be stored in the registry until changed by the user.

The application program startup is set to Form1 and the Form1 load event establishs some defaults and when it finds the registry key for the input value is blanks it pops up another form (frmSelection) with the ShowDialog method.

This is working fine, however control never seems to return to the Form1 load procedure. If I use Dispose then Form1 gets loaded but none of the buttons work and I have to nix the program from task manager.

The form frmSelection is also used to change the selected file at anytime after the intial launch.

What am I doing wrong? How can I throw up a selection form and still get Form1 to continue loading?

Any help greatly appreciated.
 
I want to be able to invoke the form frmSelection the very first time the user runs the application so that they can select an input file to use.

The form (frmselection) may be used on any subsequent execution to change the input file (or even during the first execution after the main form has been displayed).

The idea is to force the user to select an input file that will be used as a default.

I could always the use of the shipped sample input file but I was trying to cut out extraneous steps. It may be more trouble than it is worth to do that though.
 
Code:
        Dim VeryFirstTime As String = GetSetting("AppName", "AnyYourSECTION", "AnyYourKEY")

        If VeryFirstTime = Nothing Then
            'App runs first time at this pc.
            Dim frm As New frmselection
            frm.Show() 'or .ShowDialog()
            'In frmselection at button "Ok" for example:
            SaveSetting("AppName", "AnyYourSECTION", "AnyYourKEY", "theStringSettingToSave")
        Else
            ... = GetSetting("AppName", "AnyYourSECTION", "AnyYourKEY")
        End If


Example: Want to store a textbox's text in registry:

Save it first... SaveSetting("MyAppName!!","LoadAtStartUp","Text1", Text1.Text)

To get it..... Text1.Text = GetSetting("MyAppName!!","LoadAtStartUp","Text1")


-bclt
 
kevinf2349 said:
This is working fine, however control never seems to return to the Form1 load procedure.

If I understand correctly:
(1)
On Form Load:
IF a certain registry key contains a value THEN
use it
ELSE
display a dialog to set the value
END IF

(2)
At any time:
The user can open the dialog to change the value in this registry key

The problem:
After the dialog has been dislpayed the code at use it is not run again.

If I have understood correctly then -
Move the code at use it to a separate procedure in Form1
During the Form Load event - replace the code with a call to this procedure.
When the dialog is opened by Form Load, the code immediately after return from dialog calls this procedure.
The OnClick event for the button that opens the dialog ends with a call to this procedure.

This way, the code at use it will always be called when it is needed.

I hope I understood this correctly, and that this solution helps.
 
Well I split it out and it does drive the code and displays he 'selection' dialog, it then displays the 'main form' but it just hangs the application. Non eof the buttons respond on the form, however the clock ticks along just fine. The only way I can terminate the application is to kill it with task manager.

I am sure it is me doing something stupid but I am hanged if I can see what it is.....so I have a pretty basic question....does the form load process get redriven on a form refresh?
 
Never mind....I have sorted it out. It was a rogue timer that was causing the issue.

Thanks for all your help folks. :)
 
....does the form load process get redriven on a form refresh?

No.

Could you post the code from the function that displays the selection dialog and sets the registry value?



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Doh! One minute too late!


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top