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
15 1743
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, -
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
-
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, -
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,
Umm, what happened to the eleventh day of Christmas
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.
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... -
Dim I As Long
-
For I = 1 To Days
-
Debug.Print I;
-
Next
-
Debug.Print
-
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.
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, -
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.
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.
Just a quick heads-up. They're called dimensions, not tiers. Sticking with the correct terms may reduce confusion later.
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
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
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.
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.
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?
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
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
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. -
Private Sub Command1_Click()
-
If Text1.Text <> "" Then
-
If Text1.Text >= "1" And Text1.Text <= "10" Then
-
MsgBox "Textbox has more than null value", vbInformation, "Info"
-
Else
-
MsgBox "Value has to be between or equal to 1 and 10.", vbInformation, "Info"
-
End If
-
Else
-
MsgBox "You need to input a value", vbCritical, "Error"
-
End If
-
End Sub
-
Hope this help,
kind Regards
Devon.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
...
|
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...
|
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 >>...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |