Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,442 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,319 people online right now. Registration is fast and FREE... Join Now!




retrieving data from a closed form

 
Reply to this topicStart new topic

retrieving data from a closed form, solved

wamp
29 Nov, 2007 - 08:26 AM
Post #1

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 2


My Contributions
Hi. I'll try to be as structured as possible in this question.. but this is my first post, so please be gentle wink2.gif
The problem: showing an extra button in a form if the administrator is logged in

The question: is it possible to retrieve information from a closed form?

What I've done:
I have created a login form with the usernames in a ComboBox called loginbox1
When a user logs in, it opens a 2nd form (using the command mainform.Show() )

The first thing my mainform does is close the loginform (using the command loginform.Close()
Then the next thing my form is supposed to do, is check whether an administrator is logged in or not

CODE

        loginform.Close()
10:
        If loginform.loginbox1.Text == "Administrator" Then GoTo 20
        GoTo 30
20:
        adminbutton.Show : MsgBox ("IT WORKS!!") ' for testing only
30:
        MsgBox ("not admin") ' for testing only


Problem is that even if the username is Administrator, it seems as if it can't read that.
I've tried googling for answers with no luck.

There is of course no need to say that I am a complete beginner to VB, so I hope that even if the solution might be quite obvios, I hope you can help me out, or at least give me some hints/tips on what to google/search for.

Kenneth

(I'll also post the code of the loginform just in case it helps understanding the problem)
CODE

Public Class loginform
    Dim password As String = "secretpassword"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login1.Click
        If loginbox1.Text = "" Then MsgBox("You need to log in") : GoTo 10
        If loginbox1.Text = ("Administrator") And loginbox2.Text = password Then
            adminform.Show()
        ElseIf loginbox1.Text = ("Administrator") And loginbox2.Text <> password Then
            MsgBox("wrong password")
        Else : mainform.Show()
        End If
10:

    End Sub


This post has been edited by wamp: 30 Nov, 2007 - 03:51 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Retrieving Data From A Closed Form
29 Nov, 2007 - 10:51 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You could create a public property on the form that is staying open once the person is logged in, like

CODE

Private _isAdmin As Boolean
Public Property IsAdmin() As Boolean
    Get
        Return _isAdmin
    End Get
    Set(ByVal value As Boolean)
        _isAdmin = value
    End Set
End Property


Then when the form is closing, using the Form_Closing Event to set the value of that property, something like

CODE

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim f2 As Form2
    Form2.IsAdmin = True 'or false is not an admin
End Sub


This is the best route as when the form closes it's contents are cleaned from memory using Garbage Collection.

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

wamp
RE: Retrieving Data From A Closed Form
30 Nov, 2007 - 03:49 AM
Post #3

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 2


My Contributions
That worked. thanks for the help :-)

(I didn't know that the form cleaned out on closing so a dirty fix would be to simply hide the form, but your solution was definately better smile.gif)



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 02:10PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month