|
-
Apr 25th, 2012, 10:24 AM
#1
Thread Starter
New Member
[RESOLVED]Problem regarding listbox and textbox

As you can see at the above picture, im trying to make a program in which if the textbox text and the listbox text are the same order, which they are in the picture, a bluie fonted text saying well done appears. However only the red text appears which is only meant to come when the order of the text in both listbox and textbox isnt the same.
Here is the code that i used for this:
listarrays = name of listbox
textbox1 = name of textbox
l is the name of the label for correct answer(blue font)
label3 is name of label with red font which should only appear for wrong answer
Code:
Dim text As String = Me.TextBox1.Text
For Each item As Object In listarrays.Items
If item.ToString = Me.TextBox1.Text Then
l.Visible = True
Else
Label3.Visible = True
End If
Next
Some people told me to use another textbox instead of the listbox but thats just making itmuch harder for me as I already made the full code working with the listbox. My lecturer told me i need to convert both in string so both textbox and listbox are compatible and i did so (see code above) but the correct label doesnt show;p
Any help would be appreciated
Last edited by SOMALIA; Apr 27th, 2012 at 10:22 AM.
-
Apr 25th, 2012, 12:17 PM
#2
Re: Problem regarding listbox and textbox
You would want to go through each index of the 'text' variable (as a New String())
And compare with each corresponding Index of the Listbox.
You are close, just need to rework it a little
-
Apr 25th, 2012, 06:43 PM
#3
Re: Problem regarding listbox and textbox
Couple things:
Are those numbers in the TextBox seperated by spaces ?
Do you want to display the labels after all the numbers have been entered or do evaluate the order while entering it into the TextBox ?
-
Apr 25th, 2012, 06:46 PM
#4
Re: Problem regarding listbox and textbox
Good points Niya
-
Apr 26th, 2012, 04:44 AM
#5
Thread Starter
New Member
Re: Problem regarding listbox and textbox
when the button 'go' is clicked it sorts the numbers which are in each button(made an array for that) and displays them into the listbox and at the same time the label should appear depending on whether the answer is correct (if the textbox answer is the same as the listbox in terms of order or not).
I would like the labels to appear at the same time the go button is clicked, so that the listbox with the correct answers and the appropriate label are shown at the same time.
Also yeah, the textbox displays the text in each button when they are clicked and there is a space of 10 between each number in the textbox.
Also as each number in the texbox will be different as there is a random number generator to geenrate 6 random numbers in the 6 buttons, and then each button is clicked and they appear in the textbox. So how would i make each number in the textbox as a strnig as they aren't constants;p
Last edited by SOMALIA; Apr 26th, 2012 at 04:49 AM.
-
Apr 26th, 2012, 06:50 AM
#6
Re: Problem regarding listbox and textbox
Does the child or mentally challenged adult click on the label of numbers to have it entered into the textbox?
I could charge 500 USD for that sort of question in a Fortune 500 Co.
-
Apr 26th, 2012, 09:24 AM
#7
Thread Starter
New Member
Re: Problem regarding listbox and textbox
No. The six buttons are initially enabled and they each have one number, which when clicked appear in the textbox in the order of clicking. the labels only show at the end.
-
Apr 26th, 2012, 09:33 AM
#8
Re: Problem regarding listbox and textbox
Oh, I see. I like that 
Did you write any more code relevant to your problem since you started this thread, may I ask?
-
Apr 26th, 2012, 09:35 AM
#9
Thread Starter
New Member
Re: Problem regarding listbox and textbox
I tried a few stuff but they didnt work lol, im thinking now to compare the first item of listbox with first item of textbox and so forth for the remaining items but do not know the code to do that lol;p Would you happen to know the general code to compare items in listbox and textbox man
-
Apr 26th, 2012, 09:58 AM
#10
Re: Problem regarding listbox and textbox
vb Code:
' Dim x As Integer Dim s As String() = New String(5) {"0", "8", "3", "7", "7", "5"} ListBox1.Items.AddRange(s) TextBox1.Text = "0 2 3 5 7 8" For Each item In ListBox1.Items If item.ToString = TextBox1.Text.Split(" ")(x) Then MsgBox("matching " + item.ToString) End If X += 1 Next
Last edited by proneal; Apr 26th, 2012 at 10:02 AM.
Reason: commented ' what should not have been
-
Apr 26th, 2012, 11:16 AM
#11
Thread Starter
New Member
Re: Problem regarding listbox and textbox
The problem is that on line 3 it has fixed numbers, whereas in this program there are random generated numbers which are the text for each button here are the codes for each button and and the code for the go button which is meant to:
1) show the listbox with sorted of the 6 buttons in ascending order which it does nicely.
2)display either blue or red fonted label depending if both listbox and textbox text match.
Code for go button:
Code:
Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click
strnumbers(0) = CStr(btnNumberButton1.Text)
strnumbers(1) = CStr(btnNumberButton2.Text)
strnumbers(2) = CStr(btnNumberButton3.Text)
strnumbers(3) = CStr(btnNumberButton4.Text)
strnumbers(4) = CStr(btnNumberButton5.Text)
strnumbers(5) = CStr(btnNumberButton6.Text)
For num As Integer = 0 To strnumbers.Length - 1
Array.Sort(strnumbers)
listarrays.Items.Add(strnumbers(num))
Next
Dim x As Integer
Dim s As String() = New String(5) {strnumbers(0), strnumbers(1), strnumbers(2), strnumbers(3), strnumbers(4), strnumbers(5)}
listarrays.Items.AddRange(s)
TextBox1.Text = "0 2 3 5 7 8"
For Each item In listarrays.Items
If item.ToString = TextBox1.Text.Split(" ")(x) Then
MsgBox("matching " + item.ToString)
End If
x += 1
Next
ProgressBar1.Increment(+12.8)
listarrays.Visible = True
lblAnswer.Visible = True
End Sub
code for button(its the same for all the buttons)
Code:
Private Sub btnNumberButton1_Click(sender As System.Object, e As System.EventArgs) Handles btnNumberButton1.Click
TextBox1.Text = TextBox1.Text + " " + btnNumberButton1.Text
btnNumberButton1.Enabled = False
ProgressBar1.Increment(+12.8)
btnPlay.Enabled = False
End Sub
the bolded bit is the bit im stuck on everything else is smooth.
-
Apr 26th, 2012, 12:15 PM
#12
Re: Problem regarding listbox and textbox
Are you wanting something similar to this?
vb Code:
Dim matched As Integer For Each item In ListBox1.Items If item.ToString = s(x) Then matched += 1 End If x += 1 Next If matched = 6 Then lblAnswer.Visible = True MsgBox("Number of matches: " + matched.ToString) End If
-
Apr 27th, 2012, 05:03 AM
#13
Thread Starter
New Member
Re: Problem regarding listbox and textbox
Thanks man it works and shows the correct label but the code you gave me shows the blue fonted label even if the order is different, since both boxes have the same numbers, just in different order. Would it be possible to add something to that code that would only show the blue label if the order of both boxes are the same;p Thanks alot btw man i think im almost there

Code:
Dim x As Integer
Dim s As String() = New String(5) {strnumbers(0), strnumbers(1), strnumbers(2), strnumbers(3), strnumbers(4), strnumbers(5)}
Dim matched As Integer
For Each item In listarrays.Items
If item.ToString = s(x) Then
matched += 1
End If
x += 1
Next
If matched = 6 Then
l.Visible = True
Else
Label3.Visible = True
End If
This is what I got atm. Thing is i think i gotta replace the New String(5) {strnumbers(0), strnumbers(1), strnumbers(2), strnumbers(3), strnumbers(4), strnumbers(5)}
with each item in the textbox but i dunno how to identify them
PLZ HELP ME i have to hand this in soon and this is the only bit left (literally 99% done);p
Last edited by SOMALIA; Apr 27th, 2012 at 06:22 AM.
-
Apr 27th, 2012, 06:19 AM
#14
Re: Problem regarding listbox and textbox
Array.Sort(s)?
lblAnswer was not descriptive, and so I guessed if that was the correct label that shows correct blue message.
I take it Label3 is for red, and l for blue?
-
I wont be back for several hours, so...sorry if Array.Sort(s) is not helping.
Niya is subscribed to this Thread.
Niya knows the solution. 
Good Luck!
-
Apr 27th, 2012, 06:25 AM
#15
Thread Starter
New Member
Re: Problem regarding listbox and textbox
yeah label3 is for red and l is for blue;p
What i think is either i can replace the:
Dim s As String() = New String(5) {strnumbers(0), strnumbers(1), strnumbers(2), strnumbers(3), strnumbers(4), strnumbers(5)} with
Dim s As String() = New String(5) {put each item of the textbox inside here but i dunno how to call each indiviual item)}
Since the strnumbers are for each button and of course the listbox will have each of the button text just in a different number. So i need to replace them with each item in the textbox.
And yh lol, array.sort(s) doesnt work, it gives error lol
Some info about the textbox:
When each button is clicked the text in there appears from the text. the textbox itself has no coding only the buttons have coding which i posted a few posts ago(post#11) and they are coded to show there text in the textbox.
Last edited by SOMALIA; Apr 27th, 2012 at 06:45 AM.
-
Apr 27th, 2012, 10:21 AM
#16
Thread Starter
New Member
Re: Problem regarding listbox and textbox
managed to fix it guys, thanks.
-
Apr 27th, 2012, 02:23 PM
#17
Re: [RESOLVED]Problem regarding listbox and textbox
Well, hells bells, alrighty then!
Great!
Woo hoo!
Good Luck!
-
Apr 27th, 2012, 07:23 PM
#18
Re: Problem regarding listbox and textbox
 Originally Posted by proneal
Niya is subscribed to this Thread.
Niya knows the solution. 
I was away for almost 12 hours. Daddy had to use my monitor almost the entire day today so I wasn't able to check on this. Looks like you got it solved though. Congrats
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
|