vb program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nym11
    New Member
    • Dec 2006
    • 8

    vb program

    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
  • devonknows
    New Member
    • Nov 2006
    • 137

    #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,

    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

    Comment

    • swatmajor1
      New Member
      • Oct 2006
      • 40

      #3
      Originally posted by devonknows
      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,

      Umm, what happened to the eleventh day of Christmas

      Comment

      • devonknows
        New Member
        • Nov 2006
        • 137

        #4
        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

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by nym11
          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...
          Code:
          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.

          Comment

          • nym11
            New Member
            • Dec 2006
            • 8

            #6
            Originally posted by devonknows
            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

            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

            • devonknows
              New Member
              • Nov 2006
              • 137

              #7
              Originally posted by nym11
              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.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Just a quick heads-up. They're called dimensions, not tiers. Sticking with the correct terms may reduce confusion later.

                Comment

                • nym11
                  New Member
                  • Dec 2006
                  • 8

                  #9
                  Originally posted by devonknows
                  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

                  Comment

                  • nym11
                    New Member
                    • Dec 2006
                    • 8

                    #10
                    Originally posted by devonknows
                    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

                    Comment

                    • nym11
                      New Member
                      • Dec 2006
                      • 8

                      #11
                      Originally posted by devonknows
                      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.

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Originally posted by nym11
                        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://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

                        • nym11
                          New Member
                          • Dec 2006
                          • 8

                          #13
                          Originally posted by Killer42
                          See 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.
                          didnt get that to work but do you know how to embed a song into the vb program?

                          Comment

                          • nym11
                            New Member
                            • Dec 2006
                            • 8

                            #14
                            Originally posted by Killer42
                            See 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.
                            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

                            Comment

                            • devonknows
                              New Member
                              • Nov 2006
                              • 137

                              #15
                              Originally posted by Killer42
                              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

                              Comment

                              Working...