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.
Printable View
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.
How are you displaying the items??? In a listbox, combobox ....????
im displaying them in a lable.
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
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:
Dim strLabel As String strLabel = "This is the sample" Dim tmp1 As String Dim tmp2 As String Dim intLen As String Dim strSearch As String strSearch = "the" intLen = InStr(1, strLabel, strSearch) tmp1 = Left(strLabel, intLen - 1) tmp2 = Right(strLabel, Len(strLabel) - Len(tmp1) - Len(strSearch)) 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
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.
step through that code, it will become clearer
You could also put your project in a zip file and attach it to a post so we could look at it.
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
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.
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...Quote:
Originally Posted by stevevb6
Khanjan
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.
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
Thanks, i have an idea and i think it may work. Thanks for all your help.
could you not use checkbox on change
then put
VB Code:
if checkbox.value = true then label.text = "Whatever you want to display here" 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.Quote:
Originally Posted by Mitch_s_s
im not really sure what i should do.
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.VB Code:
if checkbox.value = true ?????????? if label1.text = "xxxxx" then Dim i As Integer Randomize i = Rnd(List1.ListCount) * List1.ListCount Label4.Caption = List1.List(i) end if
i also just tried this but it didnt work.
VB Code:
If chkboxuf1.Value = True Then With List1 .RemoveItem "AAA" End With End If
I have the lists load with the form, like this
VB Code:
Private Sub Form_Load() With List1 .AddItem "AAA" .AddItem "BBB" .AddItem "CCC" .AddItem "DDD" End With
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:
Dim lngIndex As Long For lngIndex = List1.ListCount - 1 To 0 Step -1 If List1.List(lngIndex) = "AAA" Then List1.RemoveItem lngIndex End If Next
Do i just replace what i have with that?
VB Code:
If chkboxuf1.Value = True Then Dim lngIndex As Long For lngIndex = List1.ListCount - 1 To 0 Step -1 If List1.List(lngIndex) = "AAA" Then List1.RemoveItem lngIndex End If Next
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
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.
how can i add an item to the list by clicking the check box,
like this?VB Code:
If chkboxuf1.Value = True Then Dim lngIndex As Long End If For lngIndex = List1.ListCount - 1 To 0 Step -1 If List1.List(lngIndex) = "UF1" Then List1.AddItem lngIndex End If Next
Try something like this
VB Code:
Option Explict mstrSave As String If chkboxuf1.Value = True Then Dim lngIndex As Long For lngIndex = List1.ListCount - 1 To 0 Step -1 If List1.List(lngIndex) = "AAA" Then [HL="#FFFF80"]mstrSave = List1.List(lngIndex).List[/HL] List1.RemoveItem lngIndex End If Next
And then in the Click sub
List1.AddItem mstrSave
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.
i got this one on my own. i used this code.And thenVB Code:
Dim s As Integer For s = 0 To List1.ListCount - 1 If List1.Selected(s) Then List3.AddItem List1.List(s) End If NextIroned out a few wrinckles, and all is well. Thanks for all your help!VB Code:
Dim i As Integer Randomize i = Rnd(List1.ListCount) * List3.ListCount Label4.Caption = List3.List(i)