Results 1 to 3 of 3

Thread: Perplexed Newbie with array question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    2

    Unhappy

    Hi all I am trying to take this correspondence course on vb
    (btw I do not recommend Harcourt Learning Direct as they used to be ICS) anyway the instructors refuse to help if you can't do one of the programming excersises because the are "like a test". Now I am pretty bad at math but am trying to fill an array with the balance gained for each percent of interest over various time spans. I can get the array filled but it only fills with zeros 8(

    I know my code is horrid but can someone tell me where I am going wrong?

    Code:
     'Resize the array for the balances
     ReDim arrPeriods(Rates + 1, Rows + 1) As Long
     
      
     For I = 1 To Rates
     For B = 1 To Rows
     arrPeriods(I, 0) = InvesAmt * (1 + Rates) * Periods
     arrPeriods(0, B) = InvesAmt * (1 + Rates) * Periods / Years
      Next B
     Next I
    Won't this fill the array correctly? or at least shouldn't when I display the array on the grid I not get zeros even if I have the formulas wrong?

    Sadil

    [Edited by Sadil on 04-15-2000 at 11:56 PM]

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    2
    NM I think part of my problem lies higher up in my code..what is really confusing me is they want my rows to display as:

    1
    5
    10
    15
    etc

    I am having a problem figuring out how to fill the array using a variable loop to start with one then jump to 5 and go to multiples of 5 from there. That is where I think part of the problem is becuase now I have the grid diplaying a total it is just the same total for every row,col hehe

    Sadil

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    well your nested loops don't do anything. you need to try to do something like this:

    Code:
    Dim TotalBins As Long
    
    Dim cnt As Long
    
    Dim DataArr() As Long
    
    TotalBins = 10
    
    '' assumed zero based array
    ReDim DataArr(TotalBins) As Long
    
    '' Fill Bin 0 with the intial value
    DataArr(0) = 0
    
    '' now loop through all other bins 1 to 9
    '' adding 5 to the previous bin and placing the new
    '' value in the current bin
    For cnt = 1 To (TotalBins - 1)
      DataArr(cnt) = DataArr(cnt - 1) + 5
    Next cnt
    
    '' the array should now contain 0,5,10,15,20,etc..
    -Shickadance

Posting Permissions

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



Click Here to Expand Forum to Full Width