+ Reply to Thread
Results 1 to 21 of 21

Need Tutoring help with array and 1 for loop problem.

  1. #1
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Need Tutoring help with array and 1 for loop problem.

    Create a module that will do the following:
    Set Option Base to 1 (I googled how to do this and I get the general idea of what it means.)
    Create an array to handle the Months of the year (use a variant data type and assign the value to the array manually in the code using the Array function)
    Please Login or Register  to view this content.
    Create a second array to show total days in each month (again use a variant data type and assign manually using Array function) I think it's the same as above but days instead? I just don't know if it means write out everyday for the whole month.
    Call a procedure to output the data to the spreadsheet ( I have no clue how to call a procedure, I think it has to do with writing different procedures and using call function but I don't know how to do that)
    Inside the new procedure, use a 1 For loop to output the Months across the top of the spreadsheet and the days of the month on the next line below (make sure they correspond) Cross this bridge as we get there.

    Any help is appreciated. Cheers!
    Last edited by sean089; 10-30-2014 at 12:34 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Question I'm trying to solve from textbook using arrays and loops. Details within

    home work?
    Nothing is more frustrating than to be working on homework and to get stuck. Without guidance, you might have no hope of finishing the assignment before the deadline. The Internet can be a big help in that respect, but without learning how to get the right answer, asking others to solve your homework questions for you simply becomes a downward spiral (and it's cheating).

    We do not want to contribute to you cheating yourself out of your education, but we also acknowledge that seeking assistance to learn a concept is a legitimate request.

    If you are genuinely interested in receiving help in the form of tutoring or coaching, then please rephrase the title of your original post to clearly indicate you are seeking coaching or tutoring help. Any forum members (who are willing to assist as a tutor) will modify their responses accordingly to facilitate your learning. Tutors don't tell you the answers, they help you figure it out for yourself; so don't expect answers, expect suggestions, or just plain hints. Also, be specific in describing the function/formula or technique you trying to learn, and tell us what you have attempted so far. Otherwise, expect your plea for homework answers to be ignored.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    Hi Martin,

    I know you're right. And I apologize for coming across as I did earlier. I am willing to put in the work to understand how to do it. I just feel like I ask the most irrelevant questions in class and now i'm barely above water. But thank you for not giving me the easy way out. Whoever's willing to help me is probably going to get frustrated but please be patient. Thank you!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    In a classroom setting, designed to provide the platform for asking anything, your teacher should be making it easy on you to ask, and re-ask, any questions you need. There's nothing irrelevant about honestly trying to grasp new concepts. More often than not, a pupil simply needs more and more "examples" of the concept, each one making it clearer and clearer to the eye what you're seeing. Repetition is your friend.

    Your first example is correct. Once you've filled your array Months with your 12 entries, those will now be located in positions 0-11 of the array, not 1-12 like we would think. The array is zero-based, so the count starts at zero.

    You can thus refer to January as Months(0), and December is Months(11).
    Please Login or Register  to view this content.
    -------------
    Create a second array showing the total days in each month
    This would also be an array with 12 elements in it, however the value in each element would be the number of days for each of the months listed in the original array.

    So if you wanted to list the Days in January, that's 31, right? So what would the array declaration and code look like, using your existing Months example, to create a second array of 12 answers called Days?

    -------------------
    Call A Procedure

    You have the idea, it sounds. A macro can be any length, so it is common to write a short macro (subroutine) to accomplish a specific task, then "Call" that macro by name as needed. A generic example:

    Please Login or Register  to view this content.
    Now that can be called at anytime from another macro by simply using it's name:
    Please Login or Register  to view this content.
    Each of those subroutines above would be executed in the order they are called.

    -------------
    For/Next Loops
    Can you give us examples showing your current understanding of FOR/NEXT loops?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need Tutoring help with array and 1 for loop problem.

    @ Jerry

    if he is using OPtion Base 1 (like he mentions in post #1), wouldn't that be positions 1-12 in the Month array?

    I could be confused
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    Nope, you're absolutely right. Missed that completely. So the element positions will be 1-12, much easier on the eye.

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need Tutoring help with array and 1 for loop problem.

    no problem....thanks for the verification....

  8. #8
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    Hi guys.. Thanks! Sorry just got back. So for the second part
    Create a second array to show total days in each month
    Please Login or Register  to view this content.
    So I read that the array(a,b) means that it's 2 dimensional and a would be the row and b would be the column? I'm not sure if this is correct but it's the only thing I could think of.
    Also I'm guessing a call sub has to be from the same module?

  9. #9
    Registered User
    Join Date
    01-31-2014
    Location
    London
    MS-Off Ver
    Excel 2003, 2010
    Posts
    12

    Re: Need Tutoring help with array and 1 for loop problem.

    You may find this page helpful;

    http://www.homeandlearn.org/excel_vba_and_arrays.html

    And yes, an array(a,b) wold be a two dimensional array. e.g dim array(1 to 12, 1 to 2) as variant would define you an array 12 row x 2 column array.

    I would recommend you use option explicit (avoids variable declaration issues /typos in variable names) (Tools -> Option -> Editor: Require Variable Declaration)
    When debugging things, I am sure you are already aware of break points, but also make sure you have the immediate and locals windows showing (View -> select 'Immediate Window' and 'Locals Window')

    Also generally using option base 1 is bad practice; a recipe for chaos on bigger projects, although in this case it designed to try and make your life simple.
    Last edited by nb-; 10-28-2014 at 08:30 PM.

  10. #10
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Need Tutoring help with array and 1 for loop problem.

    Hi..

    Sounds like they want you to manually create a second array just for the days..

    So.. when you said this:
    I think it's the same as above but days instead?
    You were on the right path..

    Something like: (I have just done the first 5 months)

    Please Login or Register  to view this content.
    Then.. hint on your loop...

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-31-2014
    Location
    London
    MS-Off Ver
    Excel 2003, 2010
    Posts
    12

    Re: Need Tutoring help with array and 1 for loop problem.

    The alternative way of doing the days (similar could be done with month names) is to do something like this;

    It defines an array of integer numbers, resizes it to the correct size, then iterates through all array filling it with the last day of the month for the element number.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    So this is what I have so far

    Please Login or Register  to view this content.
    My get the concept of for/next loops. basically loops through the code and each time adds one to it. but how do i get the code inside the loop. Give me a different hint (not the code) just something that'll help explain the logic behind the code?
    Since i'm trying to generate data to the right and down I was thinking perhaps i'd have to use xlRight and xlDown

    Thanks for all the help guys. I know it's probably like teaching a toddler. but it's much appreciated
    Last edited by sean089; 10-28-2014 at 11:04 PM.

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    You don't need quotes around the numbers in your DAYS array, they are numbers, not text. Text is put in quotes.

  14. #14
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Need Tutoring help with array and 1 for loop problem.

    Hi..

    This is actually harder than just giving you the answer..

    Let me try.. (I will just use the first 4 months as examples..

    Please Login or Register  to view this content.
    Just also include your Days values within the same loop (but on different row of course)..

  15. #15
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    Ha! so I understand what we did there but for the days it's counting 31, 28, 31 under January only.. how do i get it to count from 1 to 31... etc. under each month based on the number of days in that month?

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    Why would you need to count from 1-31 in January? The assignment stated the goal was to list the Months in one row, and the total number of days in each month in the next row down.

    Please Login or Register  to view this content.
    So you only need the two arrays and a way to LOOP through the 12 elements of each, inserting the values from MONTHS into row1 and DAYS into row2.

  17. #17
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    oh i understand what you mean. I guess I misread the question.

  18. #18
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    I think this should work but for some reason it's not and it's not even giving any error so i don't know what the problem might be.
    Please Login or Register  to view this content.

  19. #19
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    You declared your arrays in one sub, then ran the "loop" in a completely separate sub. Put the loop up into the first sub so the scope of the arrays can be seen by the loop. Then your second macro is merely a "call" of the first calendar sub.

  20. #20
    Registered User
    Join Date
    10-11-2014
    Location
    Iowa
    MS-Off Ver
    2013
    Posts
    19

    Re: Need Tutoring help with array and 1 for loop problem.

    Thanks guys!! this was kinda fun!

  21. #21
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Tutoring help with array and 1 for loop problem.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Loops and arrays
    By LadyB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-12-2013, 04:28 PM
  2. Need help with loops and arrays in VBA Macro
    By lealea1982 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 08-26-2011, 08:51 AM
  3. VBA Loops + Arrays
    By Kengh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-26-2010, 07:41 PM
  4. Loops and Arrays
    By v2jtb in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-29-2010, 12:09 PM
  5. VBA excel using arrays and loops
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2006, 08:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1