Noobie Question on Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sorry to have to ask this but...

I have a form that asks for SQL connection information. I want to close the
form when I click Save and then open the login form.

I can Hide the form but it keeps the form open. If i try and use
form.close() then it ends the program even though I've used newForm.Show()
and newForm.Activate() before the form.Close().

Thank you for your time.
Ron.
 
Capt_Ron said:
I can Hide the form but it keeps the form open. If i try and use
form.close() then it ends the program even though I've used newForm.Show()
and newForm.Activate() before the form.Close().

\\\
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run()
End Sub
///

In a button:

\\\
Dim f2 As New Form2()
f2.Show()
Me.Close()
///

You can exit the application by calling 'Application.ExitThread'. Take a
look at the 'ApplicationContext' class too.
 
THank you for your response.

However, I'm a bit confused.
Where do I put the Sub Main? In a module? or do I add that code to Form1's
Sub Main?

Ron.
 
Ron

The most simple one is in my opinon to do something as this in the load
event of your main form.

In the load event is as long that you don't do me.show the mainform not
showed.

see this as pseudo
sub load
dim frm1 as new SQLForm
if frm1.showdialog = dialog.ok then
myconnectionstring = frm1.textbox1.text 'Although that this is a very
uncommon method
dim frm2 as new LoginForm
if frm2.showdialog = dialog.ok then
user = frm2.textboxuser.text
password = frm2.textboxpassword.text
check login password
if password = false then
me.close.
end if
frm2.dispose
end if
frm1.dispose
end if

///

Again that asking of the connection string in this way is rare.

I hope this helps something.

Cor
 
Thank you.

I've combine what you said with the other response and was able to get it
working.
I have a module that has a sub Main()
in the sub main I check for a registry entry for the application
If it does not exist then I open a form and ask for the Server, Database,
Username and Password so I can build a SQL connection string.
Then I validate the string and close the form and open the login form.
I use the Application.run() method to keep the application going when I
close the forms.

The only problem I have now is that if you close either the Connection
String form or the login form then the Application.Exit() method does not
fire and it remains in memory

Thanks
Ron.
 
Ron,

Did you try the sample I gave, in that is not an Sub Main module, that is
not by accident.

Cor
 
Capt_Ron said:
Thank you.

I've combine what you said with the other response and was able to get it
working.
I have a module that has a sub Main()
in the sub main I check for a registry entry for the application
If it does not exist then I open a form and ask for the Server, Database,
Username and Password so I can build a SQL connection string.

I'm just wondering whether it's really a good idea to write the user's
password to the registry.
Is their registry on a server rather than their machine?
 
My next step is to encrypt it. I'm trying to get each step working before I
try and get fancy. The Login is for the SQL Server. I've set up a SQL
Username and Password that has the bare minimum rights to do what they need.
The registry entry is on their machine. SQL is on another.

Thanks
Ron.
 
Ron,

Decrypting/Encrypting from a password to use as an automatic logon will not
help you.
Somewhere you would have the encrypting key on that workstation and because
there is more it mostly easy to find for those who want to have it.

A password needs that the user types it in himself or has a disconnected
device (or whatever) that he can use as a key.

Just my thought,

Cor
 
COr,
Thank you for your comments and help.

I went back to the project and midified it to use your pseudocode.
It works quite well. I had to make a few tweaks to work, but I like it.
Fairly simple and straightforward. And less code too. :-)

In regards to the Encryption. I was planning on having the key inside a DLL.
I'm not really concerned with this, mostly because it's a specific
application for a specific company. It's not for mainstream distribution.

I would like to delv in further after this project is done to find the best
way to save SQL login information. But for now I think I'll run the password
through a key stored in a DLL. If even that. I may just leave it clear text
and be done with it. It all depends on the time I'm given.

As always I appreciate the help you've given.

Thank you
Ron.
 
Cor,

I put the code in a While loop and checked for success. While it is not
successfull it disposes and rebuilds the form. However it won't allow the
use of the X to close the window. How can I have the user close the window
if they decide not to login?

Ron.
 
Ron,

I know that there is a bug in that part of the dialogform. Depending from
your code of course and if you use the form.cancelbutton and/or acceptbutton

We can try to find that, however even nicer is when you put on your
dialogforms a cancel button and than set in those forms me.controlbox =
false.

Than you have direct the real dialogbox situation.

You can as well use the closing event in those forms and than force the
return in the dialogresult with
Me.DialogResult = DialogResult.Cancel

(or something else)

Cor
 
Cor,
THanks again. I think I got it. I have a Cancel button on both the forms
and they close just fine now.
Thanks
Ron.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top