Results 1 to 13 of 13

Thread: [RESOLVED] Transfering data from one form to another

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Resolved [RESOLVED] Transfering data from one form to another

    Hi Everyone,

    How do I create a button on Form1 called "Command1" that will output data to a listbox called "list1" on Form2?


    I'm sure this is an easy one, but I've never transfered data from one form to another. Thank you all in advance.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Transfering data from one form to another

    Something like....

    VB Code:
    1. Form2.TextBox1.Text = "dee-u"
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Transfering data from one form to another

    Hi dee,

    That code works for a textbox, but how do I change it to populate a list box?

    It works fine like this:
    VB Code:
    1. ListApps.List1 = Text1 & strValue1 & vbNewLine

    But when I try to convert it to this it doesn't work. I get a compile error "expected function or variable"

    VB Code:
    1. If strValue1 <> "" Then
    2.      ListApps.List1 = List1.AddItem(strValue1)
    3.   End If

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Transfering data from one form to another

    VB Code:
    1. Form1.List1.Additem "dee-u"

  5. #5

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Transfering data from one form to another

    Hack,

    Here is the code I have. I'm trying to have it populate the listbox on the different form w/ a lot more than one line of data.

    VB Code:
    1. Private Sub ttt_Click()
    2. ListApps.Show
    3. Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    4.  
    5. strComputer = txtLookup
    6. strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    7. strEntry1a = "DisplayName"
    8.  
    9.  
    10. Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
    11. objReg.EnumKey HKLM, strKey, arrSubkeys
    12.  
    13. For Each strSubkey In arrSubkeys
    14.  
    15.    intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
    16.    strEntry1a, strValue1)
    17.      
    18.   If strValue1 <> "" Then
    19.      'ListApps.Text1 = Text1 & strValue1 & vbNewLine
    20.      ListApps.List1 = List1.AddItem(strValue1) '<----- Gives the error "expected function or variable"
    21.   End If
    22. Next
    23.  
    24. End Sub
    Last edited by skakels; Apr 25th, 2006 at 07:19 AM.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Transfering data from one form to another

    I do not recognize any standard naming conventions in your code, so you need to tell me what is the name of your form and what is the name of your listbox and where in that code are you trying to populate the listbox now?

  7. #7

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Transfering data from one form to another

    ListsApps = my other form
    List1 = the listbox on ListApps

    I'm trying to populate the liste box in thise code:


    VB Code:
    1. If strValue1 <> "" Then
    2.      'ListApps.Text1 = Text1 & strValue1 & vbNewLine
    3.      ListApps.List1 = List1.AddItem(strValue1) '<----- Gives the error "expected function or variable"
    4.   End If

    Let me know if you need anything else. I'm very new to vb, so I could be doing the populating all wrong.
    Last edited by skakels; Apr 25th, 2006 at 07:19 AM.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Transfering data from one form to another

    It should be
    VB Code:
    1. ListApps.List1.AddItem strValue1

  9. #9

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Transfering data from one form to another

    That gives me the error, "Method or data member not found"

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Transfering data from one form to another

    ListApps is a form name, right?
    List1 is a Listbox on the form Listapps, right?

    Then, that should work.

    Zip your project and attach it.

  11. #11
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Transfering data from one form to another

    Is the form Listapps loaded yet? If not you won't be able to add to the listbox on the form. You are better off saving to a public variable and populating when the form is actually loaded.

  12. #12

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Transfering data from one form to another

    Hack,

    I figured it out. I moved the code from my master form and put it in the formload section of my slave form. Below is my working code:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    4.  
    5. strComputer = gethost.txtLookup
    6.  
    7. strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    8. strEntry1a = "DisplayName"
    9.  
    10.  
    11. Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
    12. objReg.EnumKey HKLM, strKey, arrSubkeys
    13.  
    14. For Each strSubkey In arrSubkeys
    15.  
    16.    intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
    17.    strEntry1a, strValue1)
    18.      
    19.   If strValue1 <> "" Then
    20.      List1.AddItem strValue1
    21.      End If
    22. Next
    23. End Sub

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: [RESOLVED] Transfering data from one form to another

    Outstanding. Good job.

    I've always believed that when you figure stuff out for yourself, it will stay with you!

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