473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

vb program

8
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
Dec 9 '06 #1
15 1743
devonknows
137 100+
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,

Expand|Select|Wrap|Line Numbers
  1. Private days(12) As String
  2.  
  3. Private Sub form_load()
  4. days(1) = "On the first day"
  5. days(2) = "On the second day"
  6. days(3) = "On the third day"
  7. days(4) = "On the fourth day"
  8. days(5) = "On the fifth day"
  9. days(6) = "On the sixth day"
  10. days(7) = "On the seventh day"
  11. days(8) = "On the eighth day"
  12. days(9) = "On the ninth day"
  13. days(10) = "On the tenth day"
  14. days(11) = "On the twelth day"
  15. days(12) = "On the thirteenth day"
  16. End Sub
  17. Private Sub command1_click()
  18. Dim i As Integer
  19. i = 1
  20. Do While i <= Text1.Text
  21. MsgBox days(i)
  22. i = i + 1
  23. Loop
  24. End Sub
  25.  
Dec 9 '06 #2
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,

Expand|Select|Wrap|Line Numbers
  1. Private days(12) As String
  2.  
  3. Private Sub form_load()
  4. days(1) = "On the first day"
  5. days(2) = "On the second day"
  6. days(3) = "On the third day"
  7. days(4) = "On the fourth day"
  8. days(5) = "On the fifth day"
  9. days(6) = "On the sixth day"
  10. days(7) = "On the seventh day"
  11. days(8) = "On the eighth day"
  12. days(9) = "On the ninth day"
  13. days(10) = "On the tenth day"
  14. days(11) = "On the twelth day"
  15. days(12) = "On the thirteenth day"
  16. End Sub
  17. Private Sub command1_click()
  18. Dim i As Integer
  19. i = 1
  20. Do While i <= Text1.Text
  21. MsgBox days(i)
  22. i = i + 1
  23. Loop
  24. End Sub
  25.  
Hi there,

Umm, what happened to the eleventh day of Christmas
Dec 10 '06 #3
devonknows
137 100+
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.
Dec 10 '06 #4
Killer42
8,435 Expert 8TB
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
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...

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...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long
  2. For I = 1 To Days
  3.   Debug.Print I;
  4. Next
  5. Debug.Print
  6.  
A couple of things to keep in mind...
  • 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.
Dec 10 '06 #5
nym11
8
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,

Expand|Select|Wrap|Line Numbers
  1. Private days(12) As String
  2.  
  3. Private Sub form_load()
  4. days(1) = "On the first day"
  5. days(2) = "On the second day"
  6. days(3) = "On the third day"
  7. days(4) = "On the fourth day"
  8. days(5) = "On the fifth day"
  9. days(6) = "On the sixth day"
  10. days(7) = "On the seventh day"
  11. days(8) = "On the eighth day"
  12. days(9) = "On the ninth day"
  13. days(10) = "On the tenth day"
  14. days(11) = "On the twelth day"
  15. days(12) = "On the thirteenth day"
  16. End Sub
  17. Private Sub command1_click()
  18. Dim i As Integer
  19. i = 1
  20. Do While i <= Text1.Text
  21. MsgBox days(i)
  22. i = i + 1
  23. Loop
  24. End Sub
  25.  

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.
Dec 11 '06 #6
devonknows
137 100+
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.
make 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.
Dec 11 '06 #7
Killer42
8,435 Expert 8TB
Just a quick heads-up. They're called dimensions, not tiers. Sticking with the correct terms may reduce confusion later.
Dec 11 '06 #8
nym11
8
make 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.
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. thanks
Dec 12 '06 #9
nym11
8
make 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.
also keep in mind i am using the previous information you gave me with the do while loop and other array
Dec 12 '06 #10
nym11
8
make 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.
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.
Dec 12 '06 #11
Killer42
8,435 Expert 8TB
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.
See my response in the other thread https://bytes.com/showthread.php?t=550538

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.
Dec 12 '06 #12
nym11
8
See my response in the other thread https://bytes.com/showthread.php?t=550538

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.
didnt get that to work but do you know how to embed a song into the vb program?
Dec 12 '06 #13
nym11
8
See my response in the other thread https://bytes.com/showthread.php?t=550538

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.
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 crashes
Dec 12 '06 #14
devonknows
137 100+
Just a quick heads-up. They're called dimensions, not tiers. Sticking with the correct terms may reduce confusion later.
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.

Kind Regards,
Devon
Dec 12 '06 #15
devonknows
137 100+
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 crashes
you need to check if the value of text1.text doesnt equal "", the code below shows how to check if its null and then check the values of text1.text, of course as always change to your own.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. If Text1.Text <> "" Then
  3.     If Text1.Text >= "1" And Text1.Text <= "10" Then
  4.         MsgBox "Textbox has more than null value", vbInformation, "Info"
  5.     Else
  6.         MsgBox "Value has to be between or equal to 1 and 10.", vbInformation, "Info"
  7.     End If
  8. Else
  9.   MsgBox "You need to input a value", vbCritical, "Error"
  10. End If
  11. End Sub
  12.  
Hope this help,
kind Regards
Devon.
Dec 12 '06 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.