0

guyz I need help regarding declarations of global variable.. I created a module here is the script.

Module modGlobalvar
    Public name As String
-----------------------------------------------------------------------------------

'here is the code in my login form

Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        Try
            sqlcon.Close()
            scmd = New SqlCommand("SELECT * FROM KUSERS WHERE USERIDNAME = '" & txtUsername.Text & "' AND USERIDCODE = '" & txtPassword.Text & "'", sqlcon)
            sqlcon.Open()
            scmd.CommandType = CommandType.Text
            dr = scmd.ExecuteReader

            dr.Read()

            If dr.HasRows = True Then
                txtUsername.Text = ""
                txtPassword.Text = ""
                Me.Hide()
                Name = dr(3).ToString
                frmMain.Show()

            Else
                MsgBox("Invalid user. Please check username and password", MsgBoxStyle.Critical)
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
----------------------------------------------------------------------------------

'here is the code in my Main form

 Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = Name
    End Sub
---------------------------------------------------------------------------------

End Module

and then I set the value of that variable in my Login form and then my PROBLEM is when accessing it on the my Main form and I want to display the data of that variable in a textbox, the variable does'nt hold the value that I already set. Help me guyz. I'm waiting for replies!

Attachments Login.JPG 8.13 KB Main.JPG 27.27 KB
2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by Lee21
0

Qualify the variable with modulename.

modGlobalvar.Name=dr(3).ToString

and

TextBox1.Text =modGlobalvar.Name
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.