Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 26th, 2005, 3:13 PM   #1
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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 Sub


At 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
Attached Files
File Type: zip Loops - Small.zip (38.6 KB, 14 views)
fox123 is offline   Reply With Quote
Old Jul 26th, 2005, 3:56 PM   #2
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
try
Private Sub lblLJ_Click(Index As Integer)
       Number = 0
        Do 
        lblLJ(Number).Caption = lstTeams.Text
            Number = Number + 1 

Loop While Number < 8
jim mcnamara is offline   Reply With Quote
Old Jul 26th, 2005, 4:33 PM   #3
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
Quote:
Originally Posted by jim mcnamara
try
Private Sub lblLJ_Click(Index As Integer)
       Number = 0
        Do 
        lblLJ(Number).Caption = lstTeams.Text
            Number = Number + 1 

Loop While Number < 8
Thanks, But htis just replicates the one in the 1st column in all 8.
fox123 is offline   Reply With Quote
Old Jul 26th, 2005, 4:57 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jul 26th, 2005, 5:28 PM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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 Sub

Anyways, 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!
Pizentios is offline   Reply With Quote
Old Jul 27th, 2005, 12:19 PM   #6
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old Jul 27th, 2005, 1:12 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Jul 27th, 2005, 1:16 PM   #8
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old Jul 27th, 2005, 4:11 PM   #9
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old Jul 28th, 2005, 10:25 AM   #10
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
Thumbs up

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
Thanks for your ideas
fox123 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC