i have to make a 12 days of christmas program using arrays and loops and im stuck.  if someone types the number 12 in it has to display 1 2 3 4 5 6 7 8 9 10 11 12.  anyone knows how to do this let me know.  thanks
							
						
					vb program
				
					Collapse
				
			
		
	X
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
If you want a message box to appear for each day to appear dpepend on what the user put in the text box then look below somet i whipped up real quick for ya, it assigns each day to a variable, then loops through, so you if you put 5 in, you would get 5 consecutive msgbox's say first day, second, third etc.
let me know how you get on witht aht
Kind Regards,
Devon,
Code:Private days(12) As String Private Sub form_load() days(1) = "On the first day" days(2) = "On the second day" days(3) = "On the third day" days(4) = "On the fourth day" days(5) = "On the fifth day" days(6) = "On the sixth day" days(7) = "On the seventh day" days(8) = "On the eighth day" days(9) = "On the ninth day" days(10) = "On the tenth day" days(11) = "On the twelth day" days(12) = "On the thirteenth day" End Sub Private Sub command1_click() Dim i As Integer i = 1 Do While i <= Text1.Text MsgBox days(i) i = i + 1 Loop End Sub
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
Hi there,Originally posted by devonknowsIf you want a message box to appear for each day to appear dpepend on what the user put in the text box then look below somet i whipped up real quick for ya, it assigns each day to a variable, then loops through, so you if you put 5 in, you would get 5 consecutive msgbox's say first day, second, third etc.
let me know how you get on witht aht
Kind Regards,
Devon,
Code:Private days(12) As String Private Sub form_load() days(1) = "On the first day" days(2) = "On the second day" days(3) = "On the third day" days(4) = "On the fourth day" days(5) = "On the fifth day" days(6) = "On the sixth day" days(7) = "On the seventh day" days(8) = "On the eighth day" days(9) = "On the ninth day" days(10) = "On the tenth day" days(11) = "On the twelth day" days(12) = "On the thirteenth day" End Sub Private Sub command1_click() Dim i As Integer i = 1 Do While i <= Text1.Text MsgBox days(i) i = i + 1 Loop End Sub
Umm, what happened to the eleventh day of ChristmasComment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
lol dont ask was early monrning i think, i dont know but ive finished that project rof, starts on the 13th december, each day it plays the next verse of the ok song, and it automatically copies itsself as soon as it loads, and changes registry keys just to be anoying, plus it silently loads for anything over 180 secs to 3600 seconds so to give the user a nice suprise. haha. lol but i think ive put the eleventh in on mine lol.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
I see you've had some potentially useful responses. But a very simple answer to your "display 1 2 3..." question would be as follows...Originally posted by nym11i have to make a 12 days of christmas program using arrays and loops and im stuck. if someone types the number 12 in it has to display 1 2 3 4 5 6 7 8 9 10 11 12. anyone knows how to do this let me know. thanks
Assuming the number that the user typed in is in variable Days, a simple loop from 1 to Days shjould do the trick. for example...
A couple of things to keep in mind...Code:Dim I As Long For I = 1 To Days Debug.Print I; Next Debug.Print
- This is just printing to the immediate window, because I don't know exactly where it's supposed to go.
 - This is written for VB6 - you didn't say what version you're using.
 
Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
Originally posted by devonknowsIf you want a message box to appear for each day to appear dpepend on what the user put in the text box then look below somet i whipped up real quick for ya, it assigns each day to a variable, then loops through, so you if you put 5 in, you would get 5 consecutive msgbox's say first day, second, third etc.
let me know how you get on witht aht
Kind Regards,
Devon,
Code:Private days(12) As String Private Sub form_load() days(1) = "On the first day" days(2) = "On the second day" days(3) = "On the third day" days(4) = "On the fourth day" days(5) = "On the fifth day" days(6) = "On the sixth day" days(7) = "On the seventh day" days(8) = "On the eighth day" days(9) = "On the ninth day" days(10) = "On the tenth day" days(11) = "On the twelth day" days(12) = "On the thirteenth day" End Sub Private Sub command1_click() Dim i As Integer i = 1 Do While i <= Text1.Text MsgBox days(i) i = i + 1 Loop End Sub
That worked great but now i have another problem. i have an array with prices in it and i need the prices to add. for example the 3 french hens costs $15 each, 2 turtle doves cost 20 each and 1 partrige in a pair tree costs 149.99. how would i make it so that if the person enters 3 it takes the three numbers and adds them together.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
make a second step in your array, for exampleOriginally posted by nym11That worked great but now i have another problem. i have an array with prices in it and i need the prices to add. for example the 3 french hens costs $15 each, 2 turtle doves cost 20 each and 1 partrige in a pair tree costs 149.99. how would i make it so that if the person enters 3 it takes the three numbers and adds them together.
private days(12, 1) as string
days(1, 0) = "On the first day of christmas my true love sent to me"
days(1, 1) = "5"
days(2, 0) = "on the second day of christmas my true love sent to me"
days(2, 1) = "10"
then all you do when to call it is
msgbox "" & days(1, 0) & vbcrlf & "" & days(1, 1)
or you could do
stramount = clng(days(1,1) + days(2,1))
which will add the totals together etc etc..
hope this help
P.S. you can go more tiers in aswell for example -
private days(12, 1, 1) as string
but dont foget to change all of your days() to incorparate the third tier
days(1, 1, 0) = "on the third day of xmas"
Kind Regards
Devon.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
anyway to do it say with a seperate array rather then doing 2 demnsional. i am better single arrays and will be easier for me. thanksOriginally posted by devonknowsmake a second step in your array, for example
private days(12, 1) as string
days(1, 0) = "On the first day of christmas my true love sent to me"
days(1, 1) = "5"
days(2, 0) = "on the second day of christmas my true love sent to me"
days(2, 1) = "10"
then all you do when to call it is
msgbox "" & days(1, 0) & vbcrlf & "" & days(1, 1)
or you could do
stramount = clng(days(1,1) + days(2,1))
which will add the totals together etc etc..
hope this help
P.S. you can go more tiers in aswell for example -
private days(12, 1, 1) as string
but dont foget to change all of your days() to incorparate the third tier
days(1, 1, 0) = "on the third day of xmas"
Kind Regards
Devon.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
also keep in mind i am using the previous information you gave me with the do while loop and other arrayOriginally posted by devonknowsmake a second step in your array, for example
private days(12, 1) as string
days(1, 0) = "On the first day of christmas my true love sent to me"
days(1, 1) = "5"
days(2, 0) = "on the second day of christmas my true love sent to me"
days(2, 1) = "10"
then all you do when to call it is
msgbox "" & days(1, 0) & vbcrlf & "" & days(1, 1)
or you could do
stramount = clng(days(1,1) + days(2,1))
which will add the totals together etc etc..
hope this help
P.S. you can go more tiers in aswell for example -
private days(12, 1, 1) as string
but dont foget to change all of your days() to incorparate the third tier
days(1, 1, 0) = "on the third day of xmas"
Kind Regards
Devon.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
Pretty much what i have to do is make an array and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.Originally posted by devonknowsmake a second step in your array, for example
private days(12, 1) as string
days(1, 0) = "On the first day of christmas my true love sent to me"
days(1, 1) = "5"
days(2, 0) = "on the second day of christmas my true love sent to me"
days(2, 1) = "10"
then all you do when to call it is
msgbox "" & days(1, 0) & vbcrlf & "" & days(1, 1)
or you could do
stramount = clng(days(1,1) + days(2,1))
which will add the totals together etc etc..
hope this help
P.S. you can go more tiers in aswell for example -
private days(12, 1, 1) as string
but dont foget to change all of your days() to incorparate the third tier
days(1, 1, 0) = "on the third day of xmas"
Kind Regards
Devon.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
See my response in the other thread https://post.bytes.com/node/487198Originally posted by nym11Pretty much what i have to do is make an array and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.
If you need to reverse the loop to count down to 1 instead of the other way, just reverse the starting and ending values, and add Step -1 to the end of the For statement.
To show the total for the whole twelve days, just repeat the calculation loop in some way. Or do the loop from 12 to 1, and make the Print statement conditional on If I <= D. That way you can get everything done with the one loop. However, I think you would then need to add up two separate totals.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
didnt get that to work but do you know how to embed a song into the vb program?Originally posted by Killer42See my response in the other thread https://post.bytes.com/node/487198
If you need to reverse the loop to count down to 1 instead of the other way, just reverse the starting and ending values, and add Step -1 to the end of the For statement.
To show the total for the whole twelve days, just repeat the calculation loop in some way. Or do the loop from 12 to 1, and make the Print statement conditional on If I <= D. That way you can get everything done with the one loop. However, I think you would then need to add up two separate totals.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
also one more question, how do i make it so if they put no value in the text box the program doesnt crash. i have it set so if they put a number above or below the array it gives a message box but if they do not put a number it crashesOriginally posted by Killer42See my response in the other thread https://post.bytes.com/node/487198
If you need to reverse the loop to count down to 1 instead of the other way, just reverse the starting and ending values, and add Step -1 to the end of the For statement.
To show the total for the whole twelve days, just repeat the calculation loop in some way. Or do the loop from 12 to 1, and make the Print statement conditional on If I <= D. That way you can get everything done with the one loop. However, I think you would then need to add up two separate totals.Comment
 - 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
Yes my apologies Killer42, i spent ten minutes trying to think of the name and was just not for happening at early hours of the morning, but the general gist was sent across but thanks for the update has been bugging me since, just coulnt think of the word, so my apologies if any confusions were made.Originally posted by Killer42Just a quick heads-up. They're called dimensions, not tiers. Sticking with the correct terms may reduce confusion later.
Kind Regards,
DevonComment
 
Comment