![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
Loops!!
I am creating an athletics scoreboard,
I have a list with team names that once clicked will fill the position with the team name, i then want the loop to move onto the Second position (lblLJ(1).caption)(User click name), Third Position and so on. This is the code i have used Private Sub lblLJ_Click(Index As Integer)
Number = "0"
Do
lblLJ(Number).Caption = lstTeams.Text
Number = Number + 1 [color=Green]' number on array increases so text is placed into next positionCOLOR=Green]
Loop While Number > 8
End SubAt the moment the name just keeps changing in the First posistion box (lblLJ(0).Caption) Any Ideas Thanks P.S I have attatched a picture which, might make things easier to explain |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
try
Private Sub lblLJ_Click(Index As Integer)
Number = 0
Do
lblLJ(Number).Caption = lstTeams.Text
Number = Number + 1
Loop While Number < 8 |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You're indexing the destination with "Number", but I don't see where you're changing the text. Consequently, the same text will prolly go in all the columns....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
the reason that it only replicates the on in teh 1st colum into all the colums is because (or my guess any ways) you only have one selected in the list box. lstTeams.Text returns only what the user selected nothing else. so what is happening is (Note this is for jim's code):
1) user selects a team from list box. 2) clicks lblLJ 3) Number is set to 0 4) Enters a do while loop that will run untill Number >= 8 5)puts lstTeams.Text into the lblLJ(Number).Caption The problem is that lstTeams.Text is the same value each time the loop runs through. Now, since a list box can have multiple things selected at once, your in luck. This code assumes that the user has to select 8 teams. Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const LB_GETSELCOUNT = &H190
Private Const LB_GETSELITEMS = &H191
Private Sub lblLJ_Click(Index As Integer)
Dim sSelected(0 to 7) as Long
Dim Number as Integer
Number = 0
if lstTeams.SelCount == 8 then
Call SendMessage(lstTeams.hwnd, LB_GETSELITEMS, lstTeams.SelCount, sSelected(1)) 'grabs the selected items.
Do
lblLJ(Number).Caption = sSelected(Number)
Number = Number + 1
Loop While Number <= 7
elseif lstTeams.SelCount > 8 then
MsgBox "You Selected To Many Teams!"
Exit Sub
else
MsgBox "You Didn't Select Enough Teams!"
Exit Sub
end if
End SubAnyways, i haven't tested this and my vb is kinda rusty, let me know how it worked out. PS: there's another way to do it where you loop through each list item and check to see if it's selected, but depending on how long your listbox is, the program can slow down a bunch. This way is a little more advanced, but requires less resources from teh computer it's being run on. This is a tutorial on how to use SendMessage to do it :-) that where i got my idea for the code in this post.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
Pizentios, could you please tell me about the other way, as i am very novice and would like to keep things simple. There is 4 teams in the list box. but 8 positions because two people compete in each team.
Thanks |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() |
Ok, so if i get this right, the person selects 4 teams, and the player's names get put into the labels?
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
There is only 4 Teams e.g Blue, Green, Red and Yellow. So for the 1st position the user will click the team in the list box and then the 1st posistion label lblLJ(0). Then for the second one he would click the team in the listbox and then lblLJ(1) and so forth up to 8th Pos lblLJ(7)
Yes the team name is placed in the label Hope that helps Thanks |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
To put it simply i want the user to select a team, then select which label that team goes into
Thanks to Pinzentios for wording it so well |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
I have managed to solve this problem. If anyone wants to know the code was:
Private Sub lblLJ_Click(Index As Integer) If lstTeams.ListIndex <> -1 Then lblLJ(Index).Caption = lstTeams.List(lstTeams.ListIndex) End Sub |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|