-
Apr 24th, 2006, 09:41 PM
#1
Thread Starter
Registered User
[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.
-
Apr 24th, 2006, 09:46 PM
#2
Re: Transfering data from one form to another
Something like....
VB Code:
Form2.TextBox1.Text = "dee-u"
-
Apr 25th, 2006, 06:43 AM
#3
Thread Starter
Registered User
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:
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:
If strValue1 <> "" Then
ListApps.List1 = List1.AddItem(strValue1)
End If
-
Apr 25th, 2006, 06:48 AM
#4
Re: Transfering data from one form to another
VB Code:
Form1.List1.Additem "dee-u"
-
Apr 25th, 2006, 06:51 AM
#5
Thread Starter
Registered User
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:
Private Sub ttt_Click()
ListApps.Show
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = txtLookup
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If strValue1 <> "" Then
'ListApps.Text1 = Text1 & strValue1 & vbNewLine
ListApps.List1 = List1.AddItem(strValue1) '<----- Gives the error "expected function or variable"
End If
Next
End Sub
Last edited by skakels; Apr 25th, 2006 at 07:19 AM.
-
Apr 25th, 2006, 06:56 AM
#6
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?
-
Apr 25th, 2006, 07:01 AM
#7
Thread Starter
Registered User
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:
If strValue1 <> "" Then
'ListApps.Text1 = Text1 & strValue1 & vbNewLine
ListApps.List1 = List1.AddItem(strValue1) '<----- Gives the error "expected function or variable"
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.
-
Apr 25th, 2006, 07:22 AM
#8
Re: Transfering data from one form to another
It should be
VB Code:
ListApps.List1.AddItem strValue1
-
Apr 25th, 2006, 07:24 AM
#9
Thread Starter
Registered User
Re: Transfering data from one form to another
That gives me the error, "Method or data member not found"
-
Apr 25th, 2006, 07:27 AM
#10
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.
-
Apr 25th, 2006, 07:29 AM
#11
Frenzied Member
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.
-
Apr 25th, 2006, 07:32 AM
#12
Thread Starter
Registered User
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:
Private Sub Form_Load()
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = gethost.txtLookup
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If strValue1 <> "" Then
List1.AddItem strValue1
End If
Next
End Sub
-
Apr 25th, 2006, 07:41 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|