Question

Locked

How can I transfer variables from one form to many forms in .NET?

By vikfrank ·
I am preparing a project on vb .net. in which i need to pass login name and password of the user to other forms.I am able to pass it by inheritance but when i use to access these values by other form then these values are null.for eg:- A,B,C are 3 forms where c is inherited by A and B.A uses to pass login name to form C.On button click of form A form B appears and when from form B I call Form C,passed values by form A doesn't exist for Form B...Thus I am stucked that how to pass value from A to C and use these values through calling Form B....If possible please help me out.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

You are confusing class and instance

by Tony Hopkinson In reply to How can I transfer variab ...

You child forme get the logic surrounding username and password, because they all have the same paranet class. However when you instantiate one ( create it) they get their 'own copy' of those properties which obviously haven't been set.

There are few ways of getting what you want, the simplest is to add a constructor which takes user name an password as a parameters and then use it to create all the child forms.

Personally however I'd tuck all the username and password (login log out etc) in it's own class and then either access that through a singleton pattern (google singleton vb.net). Or again add a constructor to the parent form that took the 'user' class.

Key questions to ask yourself are

Should an unauthorised user be able to even access the form.
Can you have more than one form up at once, and if so are they all having their own login session. do you want to pass the login between forms and last but not least are you happy with password being so readily available cross all your code. I wouldn't be.

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums