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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transferring parameter between forms in vb.net 1

Status
Not open for further replies.

FatEric

IS-IT--Management
Nov 8, 2007
58
BE
Hi everyone,

I'm new to vb.net. I recently started programming a new program for the company I work for. I now have a simple login screen (with a login and password). The password I have encrypted with MD5 (and works), but the MD5 code it has to be compared to is now hardcoded. Is there a better possibility to change the hardcoded part?? (But this is not the biggest problem)

My real question. So I have made the login screen. When clicked on a button, there will open an new form. But depending on the loginname some buttons and fields must not show up in the new form (admin must have different rights then a user). So I want to transfer the loginname or something else so I can check who is logged in and so I can show the right buttons, ... Is there a possibility to transfer the loginname or how can this problem be solved?

Anyone who has a good idea? If more info needed please ask.

Thanks in advance,
FatEric
 
All you need is a global variable to hold the value of the login name. I would add a module to your project that just has the global variable declaration in it. Declare the variable as "Friend" so the other forms in your app can access it.

Code:
Friend g_strLoginName as String

On your login form, assign the value to the variable...

Code:
g_strLoginName = Me.NameOfLoginNameTextbox.Text

Then you can just check the value of the global variable wherever you need to do so.
 
Thanks very much rjoubert,

It works really well.

Cheers, FatEric
 
Ideally, you want to create private variables and public variables. If you create a global variable, you can unintentionally change it's contents from another form.

A good example of passing information between forms would be:

Code:
#Region " Private Variables "
    Private privVariable As String
#End Region

#Region " Public Properties "
    Public ReadOnly Property pubVariable() As String
        Get
            Return privVariable
        End Get
    End Property
#End Region

Then on the main form you could use:

mytempVariable = form1.pubVariable
 
Hi Qamgine,

Your solution does not seem to work. I have a module that opens a form (the login from with a tb_login as String). Then when I click on the loginbutton, I open a new form and close the loginform. So when I type in "loginform.getLogin" it becomes blue underline (so it's fault). Please some feedback.

Thanks, FatEric
 
Eric -

Can you post a little bit of the code involved?

Most importantly how you are opening the login form, and how you are exposing the property getLogin from this login form?

This will help people to point you in the right direction.

Hope this helps

Alex


[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
Yes I can.

When I open the program, this module is executed first:

Module Module1
Sub Main()
Dim frmLogin As New frm_inloggen
frmLogin.Show()
Application.Run()
End Sub
End Module

Within the class I put this code in frm_inloggen:

Public ReadOnly Property getLogin() As String
Get
Return tb_login.Text()
End Get
End Property

When I click on a button in the frm_inloggen form, I execute this code which opens a new form (frm_werkkledij):

Dim frmWerk1 As New frm_werkkledij
frmWerk1.Show()
Me.Close()

In this last form, I did this:

lbl_user.Text() = "USER: " & frm_inloggen.getLogin()

Hope this code helps you much more than just text. Thanks for any advice.

Cheers, FatEric
 
Forms should NEVER pass state information. Create a class, and use that.

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
Hi dglienna,

Could you give me some more info please, because I am new to vb.net.

Thanks, FatEric
 
Hi guys,

I wrote it on a different way, and it works.

In the first form a make a new instance of the second form. In the second form there is a public function setLogin, which sets a private variable within the second form with the param of that function. After making the new second form in the first one, i call the setLogin function with the login parameter and set it in the second. Then i show the second form and close the first.

That works well for me.

Thanks for all replies.

FatEric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top