To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Jan 30th, 2007, 04:25 PM   #1
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Resolved [RESOLVED] check box to remove items from list?

I have made this progam that picks random things from two lists and displays them on a form. I was wondering if there is a way i can have it so when i check a check box labled one of the items in one of the lists will not show up anymore.
stevevb6 is offline   Reply With Quote
Old Jan 30th, 2007, 04:40 PM   #2
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

How are you displaying the items??? In a listbox, combobox ....????
__________________
Hey... If you found this post helpful please rate it.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 04:46 PM   #3
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

im displaying them in a lable.
stevevb6 is offline   Reply With Quote
Old Jan 30th, 2007, 04:51 PM   #4
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

Well since you are using a label, it gets complicated.
1. First you gotta use the InStr function to find where the string you want to remove is at in the labels caption.
2. Once you get the start number of that string, you use the Left function to take apart everything from before the string you want to remove and assign it to a temporary variable
3. You can use the Len function to find the length of the string you want to remove and add that to the starting value from Step 2 and then use the Right function to take everything from after the string you want to remove and assign it to another temporary variable.
4. Now combine the first and the second variable and display in the label.

I'll try to post the code... but if you can do it on your own... good for you

Khanjan
__________________
Hey... If you found this post helpful please rate it.

Last edited by khanjan_a2k; Jan 30th, 2007 at 06:16 PM.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 05:10 PM   #5
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

I think this should work... however I am missing a space somewhere in the final output... anyways this is a sample, you maybe be able to use it...
VB Code:
  1. Dim strLabel As String
  2.     strLabel = "This is the sample"
  3.     Dim tmp1 As String
  4.     Dim tmp2 As String
  5.     Dim intLen As String
  6.     Dim strSearch As String
  7.     strSearch = "the"
  8.     intLen = InStr(1, strLabel, strSearch)
  9.     tmp1 = Left(strLabel, intLen - 1)
  10.     tmp2 = Right(strLabel, Len(strLabel) - Len(tmp1) - Len(strSearch))
  11.     MsgBox tmp1 & tmp2

Or you could try loading each and every item into an array and then load it into the label. And if you want to remove an item, just don't display that string array. Its much easier!!!!!!!! Ask if you want a sample
__________________
Hey... If you found this post helpful please rate it.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 05:16 PM   #6
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

can i have a smaple of the easier way, im pretty new to this and the first example goes waaaay over my head. thanks for you help though.
stevevb6 is offline   Reply With Quote
Old Jan 30th, 2007, 05:20 PM   #7
Mitch_s_s
Addicted Member
 
Join Date: Jan 07
Location: England
Posts: 228
Mitch_s_s is on a distinguished road (20+)
Re: check box to remove items from list?

step through that code, it will become clearer
Mitch_s_s is offline   Reply With Quote
Old Jan 30th, 2007, 05:48 PM   #8
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: check box to remove items from list?

You could also put your project in a zip file and attach it to a post so we could look at it.
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Jan 30th, 2007, 05:57 PM   #9
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

Well... I did come up with the code but there is a little or big bug in there somewhere... I am losing the count of the arrays in there somewhere.... However, if you don't really care about each of those items throughout the rest of the program and really aren't tracking each item individually, then just use the first piece of code... the second one is if you want to track each item individually....
Anyways I have attached the second "prototype"... see if you can find the bug... I bet steve will appreciate it

Khanjan
Attached Files
File Type: rar Example.rar (1.4 KB, 17 views)
__________________
Hey... If you found this post helpful please rate it.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 06:05 PM   #10
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: check box to remove items from list?

Do you have to use a label to display the array? Why not a Listbox? In any case please tell me the exact steps to reproduce the problem and specifically what the problem is.
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Jan 30th, 2007, 08:27 PM   #11
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

Thats a neat little sample, thanks. However it is not really what im looking for. I never really explained it well enough. It is a randomizing program that when you click the "GO!" button, it will pick one word from one list, and one word from another list. The first word will appear in the first label, and the second word in the second label. I want to have a list of check boxes that are labeled the words in the list. ie each word has its own check box, then when the check box is checked, the word it represents is not an option to come up in the respective label. I think that is a much better explanation.
stevevb6 is offline   Reply With Quote
Old Jan 30th, 2007, 08:30 PM   #12
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

Quote:
Originally Posted by stevevb6
Thats a neat little sample, thanks. However it is not really what im looking for. I never really explained it well enough. It is a randomizing program that when you click the "GO!" button, it will pick one word from one list, and one word from another list. The first word will appear in the first label, and the second word in the second label. I want to have a list of check boxes that are labeled the words in the list. ie each word has its own check box, then when the check box is checked, the word it represents is not an option to come up in the respective label. I think that is a much better explanation.
I understand everything upto the "in the second label." After that I get a little lost... can you be more specific please.... I know it it frustrating but I really can't help unless I understand you...

Khanjan
__________________
Hey... If you found this post helpful please rate it.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 08:56 PM   #13
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

There are 2 lists and 2 labels. i'll call them "list a" and "list b". The lists are in the code and the user cannot see them. The program will select one word from "list a" and one word from "list b" and put them in "label a" and "label b". I want to make it so i have a checkbox for each word from "list a" and a check box for each word in "list b", and when the user clicks the checkbox, it disables one word from the list, so it will not appear in the label. i think that should help. if not ill put my whole project there.
stevevb6 is offline   Reply With Quote
Old Jan 30th, 2007, 09:02 PM   #14
khanjan_a2k
Hyperactive Member
 
Join Date: Dec 05
Location: Toronto, Canada
Posts: 357
khanjan_a2k is on a distinguished road (10+)
Re: check box to remove items from list?

Ok about the lists... I'll tell you what... the easiest and most effiecient way for this is to use a listbox control, change its Style property to 1 - Checkbox... This gives you are checkbox for each of the items in the listbox... The rest... I hope you know how to use a listbox lol...

Khanjan
__________________
Hey... If you found this post helpful please rate it.
khanjan_a2k is offline   Reply With Quote
Old Jan 30th, 2007, 09:34 PM   #15
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

Thanks, i have an idea and i think it may work. Thanks for all your help.
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 02:40 AM   #16
Mitch_s_s
Addicted Member
 
Join Date: Jan 07
Location: England
Posts: 228
Mitch_s_s is on a distinguished road (20+)
Re: check box to remove items from list?

could you not use checkbox on change
then put
VB Code:
  1. if checkbox.value = true then
  2.   label.text = "Whatever you want to display here"
  3. end if

or am i missing the point?
Mitch_s_s is offline   Reply With Quote
Old Jan 31st, 2007, 10:29 AM   #17
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

Quote:
Originally Posted by Mitch_s_s
could you not use checkbox on change
then put
VB Code:
  1. if checkbox.value = true then
  2.   label.text = "Whatever you want to display here"
  3. end if

or am i missing the point?
That is similar to the idea i have, however i want it so when the checkbox.value = true and the checkbox is for a certain word in the list, and the word comes up as the label.text, it randomizes again. but i cant get it to work.
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 10:39 AM   #18
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

im not really sure what i should do.
VB Code:
  1. if checkbox.value = true ??????????
  2. if label1.text = "xxxxx" then
  3. Dim i As Integer
  4.    
  5.     Randomize
  6.     i = Rnd(List1.ListCount) * List1.ListCount
  7.     Label4.Caption = List1.List(i)
  8. end if
im not sure if that is how i should do it. im not sure what i need to put in the area with the "????" or if this is the best way of doing this, or even if this way is possible.
i also just tried this but it didnt work.
VB Code:
  1. If chkboxuf1.Value = True Then
  2.     With List1
  3.         .RemoveItem "AAA"
  4.         End With
  5.         End If

I have the lists load with the form, like this
VB Code:
  1. Private Sub Form_Load()
  2. With List1
  3.     .AddItem "AAA"
  4.     .AddItem "BBB"
  5.     .AddItem "CCC"
  6.     .AddItem "DDD"
  7.    
  8.     End With

Last edited by stevevb6; Jan 31st, 2007 at 11:07 AM.
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 11:14 AM   #19
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: check box to remove items from list?

You can't remove an item from a listview based solely on it's value. You need to know the index of the value. The following does that. I go through the list backward in case there is more than one entry with the same value.

VB Code:
  1. Dim lngIndex As Long
  2.    
  3.     For lngIndex = List1.ListCount - 1 To 0 Step -1
  4.         If List1.List(lngIndex) = "AAA" Then
  5.             List1.RemoveItem lngIndex
  6.         End If
  7.     Next
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Jan 31st, 2007, 11:17 AM   #20
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

Do i just replace what i have with that?

VB Code:
  1. If chkboxuf1.Value = True Then
  2.     Dim lngIndex As Long
  3.    
  4.     For lngIndex = List1.ListCount - 1 To 0 Step -1
  5.         If List1.List(lngIndex) = "AAA" Then
  6.             List1.RemoveItem lngIndex
  7.         End If
  8.     Next
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 11:20 AM   #21
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: check box to remove items from list?

Yes, and of course the line


If List1.List(lngIndex) = "AAA" Then

could be changed to something like

If List1.List(lngIndex) = Text1.Text Then
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Jan 31st, 2007, 11:49 AM   #22
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

it isnt going to work for what i want it for. that code removes the item from the list, and when the checkbox is unchecked, it does not come back. i need something to make the program randomize again when the label1.caption = the caption of the check box, only when the checkbox.value = true.

Last edited by stevevb6; Jan 31st, 2007 at 12:11 PM.
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 12:23 PM   #23
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

how can i add an item to the list by clicking the check box,
like this?
VB Code:
  1. If chkboxuf1.Value = True Then
  2.       Dim lngIndex As Long
  3.     End If
  4.     For lngIndex = List1.ListCount - 1 To 0 Step -1
  5.         If List1.List(lngIndex) = "UF1" Then
  6.             List1.AddItem lngIndex
  7.                End If
  8.     Next
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 01:31 PM   #24
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: check box to remove items from list?

Try something like this
VB Code:
  1. Option Explict
  2. mstrSave As String
  3. If chkboxuf1.Value = True Then
  4.     Dim lngIndex As Long
  5.    
  6.     For lngIndex = List1.ListCount - 1 To 0 Step -1
  7.         If List1.List(lngIndex) = "AAA" Then
  8.             [hl="#FFFF80"]mstrSave = List1.List(lngIndex).List[/hl]
  9.             List1.RemoveItem lngIndex
  10.         End If
  11.     Next

And then in the Click sub

List1.AddItem mstrSave
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Jan 31st, 2007, 02:38 PM   #25
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

http://hx.pri.ee/dsrc/dice.php
this is actually very close to the program i want to make. It is for a game that i play, some guy wanted it on the forum of the site and i figured it is a good way to get some vb6 skills.

Last edited by stevevb6; Jan 31st, 2007 at 02:49 PM.
stevevb6 is offline   Reply With Quote
Old Jan 31st, 2007, 07:17 PM   #26
stevevb6
Lively Member
 
Join Date: Jan 07
Posts: 93
stevevb6 is an unknown quantity at this point (<10)
Re: check box to remove items from list?

i got this one on my own. i used this code.
VB Code:
  1. Dim s As Integer
  2. For s = 0 To List1.ListCount - 1
  3. If List1.Selected(s) Then
  4. List3.AddItem List1.List(s)
  5. End If
  6. Next
And then
VB Code:
  1. Dim i As Integer
  2.    
  3.     Randomize
  4.     i = Rnd(List1.ListCount) * List3.ListCount
  5.     Label4.Caption = List3.List(i)
Ironed out a few wrinckles, and all is well. Thanks for all your help!

Last edited by stevevb6; Feb 2nd, 2007 at 07:36 AM.
stevevb6 is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:31 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.