Results 1 to 6 of 6

Thread: passing variables to other windows

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    passing variables to other windows

    When I double click on a name a pop up window appears with this person's data (method show()) how can I pass a variable to that new window from the window I double clicked on?

    Thanks in advance.

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    like this?
    VB Code:
    1. Private Sub Label1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.DoubleClick
    2.         Dim f As New Form5()
    3.         f.Label1.Text = Me.Label1.Text
    4.         f.Show()
    5.     End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70
    Well almost, the thing is that the variable isn't to be shown it is just an internarl ID number to retriever information from a database. So i want to pass it to do, in the popping form, something like "select * from customers where idcustomers=variable".

    Hey thanks.

  4. #4
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    this sample
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim f As New Form5()
    3.         f.generateId(Me.TextBox1.Text)
    4.         f.Show()
    5.     End Sub
    in Form5:
    VB Code:
    1. Dim cn As New SqlConnection("user id=sa; password=password; initial catalog=northwind")
    2.  
    3.     Sub generateId(ByVal s As String)
    4.         Dim cmdText As String = "select* from student where Idno = '" & s & "'"
    5.         cn.Open()
    6.         Dim cm As New SqlCommand(cmdText, cn)
    7.         Dim dr As SqlDataReader = cm.ExecuteReader
    8.         While dr.Read
    9.             TextBox1.Text = dr.GetValue(1).ToString 'lastname
    10.         End While
    11.         dr.Close()
    12.         cn.Close()
    13.     End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70
    alright that sure helps, thanks lots

  6. #6
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    no probs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width