Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 4th, 2012, 12:41 AM
m712 m712 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 m712 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 37 sec
Reputation Power: 0
Question Adding two arrays

I'm trying to add two arrays together and getting error code is like this:
For x = 0 to 180
For y = 0 to 180
Total = Array 1(1,x,y) + Array2 (1,x,y)
Next x
Next y

I get a subscript out of range error

I want to add each element of array1 to its corresponding element
In array2, then have a variable "total" that is the sum of all the elements that are the sum of those two
Arrays.

Reply With Quote
  #2  
Old October 4th, 2012, 02:40 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 166 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 53 m 29 sec
Reputation Power: 43
It should not work at all. For a starter, your for/next loops are nested wrong. It should read :

For x = 0 to 180
For y = 0 to 180
Total = Array1(1, x, y) + Array2(1, x, y)
Debug.Print Array1(1, x, y), Array2(1, x, y), Total
Next y
Next x

If you want to save the total in Array2, you would have to add a fourth dimension to it.

J.A. Coutts

Reply With Quote
  #3  
Old October 19th, 2012, 11:36 AM
Incidentals Incidentals is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 89 Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 23 m 19 sec
Reputation Power: 156
Your problem stems from youtr looping as suggested above

the x is 0 and the y loop is 0 the x moves throu its values and ends 1 larger than the loop value

this means when you try to look at the nexty value you are looking too far and have an out of bounds error

simply change the order of the next statments

and as long as you have dimensioned the arrays correctly you should have no problems

here to help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Adding two arrays

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap