|
-
Nov 14th, 2006, 08:24 PM
#1
Thread Starter
Addicted Member
Listbox position question
I have a listbox with:
Steve
John
Kara 1
Bridget 1
Sam 1
I need to add a new name between the name without the 1 and with the 1.
how can I loop through the listbox and find that position and and add the new name in that spot.
thanks
-
Nov 14th, 2006, 08:29 PM
#2
Re: Listbox position question
Here is one of my search functions for a combo box.
http://vbforums.com/showpost.php?p=1820829&postcount=4
Then use the AddItem and specify the index position at which to insert the new item at.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 14th, 2006, 08:43 PM
#3
Lively Member
Re: Listbox position question
VB Code:
Dim number as Integer
For j = 0 To List1.ListCount
frmtstr = Right(List1.List(j), 2)
If frmtstr = " 1" Then
Laber1.Caption = j
Exit Sub
End If
Next j
It returns position to label1. Then you just have to add item to listbox like
List1.AddItem "newitem", number
-
Nov 14th, 2006, 08:44 PM
#4
Re: Listbox position question
If you have a large list then it will slow down because of the looping.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 14th, 2006, 08:46 PM
#5
Lively Member
Re: Listbox position question
 Originally Posted by RobDog888
If you have a large list then it will slow down because of the looping.
Yes, I unfortunatelly cannot deny that .
-
Nov 14th, 2006, 08:48 PM
#6
Re: Listbox position question
If you dont have any or many loops then it really wont affect your apps performance too much but if you have many of them then it will definately be visible.
By creating a function and using the API non-looping method you are only makinging one call to directly find the item. If you place the function in a module and make it public then you can use it repeatly throughout your program. Less code, centralized, easier management.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 14th, 2006, 09:20 PM
#7
Thread Starter
Addicted Member
Re: Listbox position question
thanks djk, im going to work with it and see if it matches what im doing...any problems ill post.
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
|