Getting User data from a dialog form.

D

dgleeson3

Hello all

I have used the LoginForm1 class in a Visual studio 2005 VB
application.
Its the standard Username, Pasword request for user input.


I was hoping to use property procedures to get back the user input in
the two boxes but its not working out.


The key sections of code is below. When Im debugging this and break
in
the property procedure I just get Nothing for Username_property
and Username.


Im used to doing this in C++ and can see there is something missing
but dont know what that is.


---------------------------------------------------------------------------­--
' First we put up Login form
' set the DialogResult for both buttons
If LoginForm_1.ShowDialog() <> DialogResult.OK Then
'close application
Environment.Exit(0)
' They did not want to log in so return to quit the
program
Return False


End If


---------------------------------------------------------------------------­--


< THEN LATER in the same function I want to use the values from the
form as follows. >


If
(DataBase_Manager1.CheckPassword(LoginForm1.Username_property,
LoginForm1.Password_property)) Then
'User failed to log in, either let him/her try again
'or end the program. In this case I just end the program.
Return False
End If


---------------------------------------------------------------------------­-
< I even have a private variable called Username taking the value
from
the text box when OK is pressed>


Private Username As String


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OK.Click
Username = UsernameTextBox.Text


End Sub
---------------------------------------------------------------------------­-
ReadOnly Property Username_property() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.


Return Username


End Get
End Property


---------------------------------------------------------------------------­--


Many thanks for all input.


Regards


Denis
______________________
Denis Gleeson
http://www.CentronSolutions.com
 
A

amdrit

Are your properties wired to your textbox controls?

it would seem to me that if you wanted to ask frmLogin for the username it
would look like this:

public class LoginForm

public readonly property UserName as string
get
return Me.txtUsername.text
end get
end property

'optionally you could make this read/write

public property UserName as string
get
return Me.txtUsername.text
end get

set (value as string)

if string.compare(me.txtusername.text,value) <> 0 then
me.txtusername.text = value
else
'no changes were made
exit property
end if

end set
end property

End Class


Hello all

I have used the LoginForm1 class in a Visual studio 2005 VB
application.
Its the standard Username, Pasword request for user input.


I was hoping to use property procedures to get back the user input in
the two boxes but its not working out.


The key sections of code is below. When Im debugging this and break
in
the property procedure I just get Nothing for Username_property
and Username.


Im used to doing this in C++ and can see there is something missing
but dont know what that is.


---------------------------------------------------------------------------­--
' First we put up Login form
' set the DialogResult for both buttons
If LoginForm_1.ShowDialog() <> DialogResult.OK Then
'close application
Environment.Exit(0)
' They did not want to log in so return to quit the
program
Return False


End If


---------------------------------------------------------------------------­--


< THEN LATER in the same function I want to use the values from the
form as follows. >


If
(DataBase_Manager1.CheckPassword(LoginForm1.Username_property,
LoginForm1.Password_property)) Then
'User failed to log in, either let him/her try again
'or end the program. In this case I just end the program.
Return False
End If


---------------------------------------------------------------------------­-
< I even have a private variable called Username taking the value
from
the text box when OK is pressed>


Private Username As String


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OK.Click
Username = UsernameTextBox.Text


End Sub
---------------------------------------------------------------------------­-
ReadOnly Property Username_property() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.


Return Username


End Get
End Property


---------------------------------------------------------------------------­--


Many thanks for all input.


Regards


Denis
______________________
Denis Gleeson
http://www.CentronSolutions.com
 
A

amdrit

My mistake, I didn't see

Private Sub OK_Click(...) Handles OK.Click
Username = UsernameTextBox.Text
End Sub

So, um yes this is odd.

Put a break point on Username = UsernameTextBox.Text and test the value of
UsernameTextBox.Text.
 
D

dgleeson3

Hi

Thanks for your input.

Private Sub OK_Click(...) Handles OK.Click
Username = UsernameTextBox.Text
End Sub

This works fine. Username becomes the correct text string.

But by the time I try to return Username from the property procedure
Username has become nothing. Ive done a search and Im not setting it
to nothing anywhere.

Its something to do with the property procedure that I dont understand
or the persistance of values
in the instance of the dialog object after the dialog has been closed.

Many thanks for all input.


Regards


Denis
______________________
Denis Gleeson
http://www.CentronSolutions.com
 
C

Cor Ligthert[MVP]

Hi,

You are right, you have first to pass back the username to the dialogform to
get what you want.

'Although that you can get the username direct from the environment.username
and it is even more comfortable for your client to use the normal way using
the role bases security.

http://msdn2.microsoft.com/en-us/library/52kd59t0(VS.71).aspx

However to come back on your code problem

The normal contstruct of a dialogform is

\\\
dim dlg as New myDialogform
If LoginForm_1.ShowDialog() <> DialogResult.OK Then
Environment.Exit(0)
end if
Whatever = dlg.Username
dlg.Dispose
///

To use the dispose here is one of the exceptions where it is usefull,
because of the nature of a dialogform.

While I normally always use properties do I normally use (if possible)
direct Friend members for the dialogforms.

Cor
 
D

dgleeson3

Hi Cor

Yes more like C++ than I guessed.
Although Im not using the property procedures. Dialog forms are
probably not the place to use these.

Thanks for your help
Regards


Denis
______________________
Denis Gleeson
http://www.CentronSolutions.com
 

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

Top