By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Noobie Question on Forms

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
"Capt_Ron" <Ca*****@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
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.

"Herfried K. Wagner [MVP]" wrote:
"Capt_Ron" <Ca*****@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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.

"Cor Ligthert" wrote:
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

Nov 21 '05 #5

P: n/a
Ron,

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

Cor
Nov 21 '05 #6

P: n/a
"Capt_Ron" <Ca*****@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
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?
--
Regards,
Andy O'Neill
Nov 21 '05 #7

P: n/a
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.

"Andy O'Neill" wrote:
"Capt_Ron" <Ca*****@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
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?
--
Regards,
Andy O'Neill

Nov 21 '05 #8

P: n/a
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
Nov 21 '05 #9

P: n/a
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 Ligthert" wrote:
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

Nov 21 '05 #10

P: n/a
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.
"Cor Ligthert" wrote:
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

Nov 21 '05 #11

P: n/a
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
Nov 21 '05 #12

P: n/a
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.
"Cor Ligthert" wrote:
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

Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.