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!

Qualify the variable with modulename.

modGlobalvar.Name=dr(3).ToString

and

TextBox1.Text =modGlobalvar.Name

thanx for the knowledge! ^_^ it works...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.