Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Noob question- how to get the same control to run in multiple forms


Reply
 
Thread Tools Display Modes
  #1  
Old 11-04-2003, 12:34 AM
johnh johnh is offline
Freshman
 
Join Date: Nov 2003
Posts: 31
Default Noob question- how to get the same control to run in multiple forms


I have a project with multiple forms, and I would like the same listbox to appear in separate forms. How would I link them together or make it so that the same listbox and data appeared in multiple forms?
Thanks for the help!
Reply With Quote
  #2  
Old 11-04-2003, 01:24 AM
Dremandred's Avatar
Dremandred Dremandred is offline
Junior Contributor
 
Join Date: Aug 2002
Location: London
Posts: 238
Default

Quote:
Originally Posted by johnh
I have a project with multiple forms, and I would like the same listbox to appear in separate forms. How would I link them together or make it so that the same listbox and data appeared in multiple forms?
Thanks for the help!




The simplest idea would to have a listbox control on each form and to then populate the listbox with the same list as the previous listbox

something like:
Code:
Private Sub Form2_FormLoad() Dim iCount AS Integer With Form1 For iCount = 1 To .Listbox1.ListCount ListBox2.AddItem = .Listbox.Index(iCount) Next iCount End With End Sub
Note: Listbox1 is on Form1 and Listbox2 is on Form2

Hope this helps
__________________
"The more I practice, the luckier I get." - Gary Player
Reply With Quote
  #3  
Old 11-04-2003, 01:42 AM
johnh johnh is offline
Freshman
 
Join Date: Nov 2003
Posts: 31
Default Still have an error

Thanks for the help. I typed in your code, but I am still getting the error, "wrong number of arguments or invalid property assignment."
The part that is highlighted is
Private Sub Form_Load() and .Index

Here is my code

Private Sub Form_Load()

Dim iCount As Integer

With frmGrades
For iCount = 1 To .lstStudents.ListCount
lstStudent.AddItem = .lstStudents.Index(iCount)
Next iCount
End With
End sub

Do you know what could be giving me the error?

Thanks a lot for your help!
Reply With Quote
  #4  
Old 11-04-2003, 01:43 AM
Csharp's Avatar
Csharp Csharp is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
Default

change this ... For iCount = 1 To .lstStudents.ListCount
to this ....
Code:
For iCount = 0 To .lstStudents.ListCount -1
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
Reply With Quote
  #5  
Old 11-04-2003, 01:44 AM
zanth_quareni's Avatar
zanth_quareni zanth_quareni is offline
Senior Contributor
 
Join Date: Aug 2003
Location: Tomarria
Posts: 905
Default

Instead of
Code:
For iCount = 1 To frmGrades.lstStudents.ListCount
do this:
Code:
For iCount = 0 To frmGrades.lstStudents.ListCount - 1

//EDIT of course i was a minute late.....
__________________
...leben ohne sinn...
Reply With Quote
  #6  
Old 11-04-2003, 06:56 AM
Dremandred's Avatar
Dremandred Dremandred is offline
Junior Contributor
 
Join Date: Aug 2002
Location: London
Posts: 238
Default

Whoops, Sorry for the blups.
I blame it on a rough night at the pub.
__________________
"The more I practice, the luckier I get." - Gary Player
Reply With Quote
  #7  
Old 11-04-2003, 08:17 AM
johnh johnh is offline
Freshman
 
Join Date: Nov 2003
Posts: 31
Default I don't think that is what is giving me the error

The listbox on my first form is named lstStudents, and the name of the listbox on the third form lstStudent. Here is my code on the third form.

Private Sub Form_Load()

Dim iCount As Integer

With frmGrades
For iCount = 0 To .lstStudents.ListCount - 1
lstStudent.AddItem = .lstStudents.Index(iCount)
Next iCount
End With

The same part of the code is being highlighted as before, I think there is a problem with this line
lstStudent.AddItem = .lstStudents.Index(iCount)
Do I need to change .lstStudents.Index(icount) to something else?
Thanks a lot for the help!
Reply With Quote
  #8  
Old 11-04-2003, 10:05 AM
IGBP IGBP is offline
Junior Contributor
 
Join Date: Oct 2003
Location: So. Calif
Posts: 342
Default

I suspect that form1 objects are out of scope.
Try this..
Code:
For iCount = 0 To [B]Form1[/B] .lstStudents.ListCount - 1 lstStudent.AddItem = [B]Form1[/B].lstStudents.Index(iCount) Next iCount
Reply With Quote
  #9  
Old 11-04-2003, 11:00 AM
johnh johnh is offline
Freshman
 
Join Date: Nov 2003
Posts: 31
Default Still can't get it to work

Thanks for the replies and the help. However, The program still won't work. The error message "Wrong number of arguments or invalid property assignment" is still coming up, and the same areas are being highlighted. Do I need do declare something as a string in a module?

Here is my code:

Private Sub Form_Load()

Dim iCount As Integer

With frmGrades
For iCount = 0 To frmGrades.lstStudents.ListCount - 1
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
Next iCount
End With


Thank you all for the help
Reply With Quote
  #10  
Old 11-05-2003, 02:18 AM
Dremandred's Avatar
Dremandred Dremandred is offline
Junior Contributor
 
Join Date: Aug 2002
Location: London
Posts: 238
Default

Quote:
Originally Posted by johnh
Thanks for the replies and the help. However, The program still won't work. The error message "Wrong number of arguments or invalid property assignment" is still coming up, and the same areas are being highlighted. Do I need do declare something as a string in a module?

Here is my code:

Private Sub Form_Load()

Dim iCount As Integer

With frmGrades
For iCount = 0 To frmGrades.lstStudents.ListCount - 1
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
Next iCount
End With


Thank you all for the help



Sorry, I think this is my mistake again.

instead of :
Code:
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
takeout the =
Code:
lstStudent.AddItem frmGrades.lstStudents.Index(iCount)
Also when you want code to be shown on this forum use [ then VB then ] and close vb code with [ then / then VB then ] (take out the thens of course and no spaces.
It just makes reading code easier
__________________
"The more I practice, the luckier I get." - Gary Player

Last edited by Dremandred; 11-05-2003 at 02:27 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multi connections, one port? burningodzilla Communications 5 08-02-2005 05:04 PM
Displaying a VB app on the web (multiple forms, etc???) mfw5978 General 1 09-05-2002 01:37 PM
WinSock vbsupernewbie Communications 1 09-12-2001 10:20 PM
Control Arrays: What, Why and How BillSoo Tutors' Corner 0 07-13-2001 12:46 PM
Control of Forms eBunnyman General 1 06-26-2001 05:17 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->