1

I have a large file of data that will parse and will be putted into Array1 and Array2 to perform a computation but the twist is some of the data doesn't have a computation so the thing that should do is to copy the current data (which is in the Array2) of those data that doesn't have a computation. Below is the sample of what should I do and my problem:

This are the Legend name that have a computation: [A, B, C]

Example:

Legend Array1   Array1 Data        Legend Array2         Array2 Data
A[0]              45[0]            A[0]                   50[0]
B[1]              10[1]            C[1]                   25[1]
C[2]              15[2]            E[2]                   10[2]
D[3]             143[3]            F[3]                    0[3]
E[4]               0[4]            B[4]                   11[4]
                                   D[5]                  150[5]

In the example above you will see a different length of Arrays and that is my problem because I need to get the difference of the data that has a legend name "A","B" and "C" but as you can see there position in the array are different so the tendency is I WILL GET A WRONG COMPUTATION OR WRONG ANSWER. What should I do to fix that problem? How can I match the 2 Arrays to get the correct answers in the computation? Thank you in advance for the help very appreciated. :)

bebebe
  • 339
  • 2
  • 7
  • 20
  • Please rewrite this. Why are you using names like Array1 and Array2? That is not descriptive. What do you mean by "some of the data doesn't have a computation so the thing that should do is to copy the current data ..."? That sentence is very confusing. – Mark Bertenshaw Jun 10 '14 at 12:24
  • @MarkBertenshaw I just want to emphasize that that is an Array.. The only data that has a computation are those data that have a Legend name [A,B,C] and the rest doesn't have a computation you just copy there current data which is in the Array 2. Did you understand my explanation? – bebebe Jun 11 '14 at 03:55

2 Answers2

0

One way to solve this would be to sort the arrays by the legend. I'm not going to give a sample here as it's too long but searching for 'VB6 sort array' will get you some help.

Try the answers from this question.

Community
  • 1
  • 1
UserEleventyOne
  • 252
  • 1
  • 11
  • How about the data? Could it possibly be sorted same as the legend? – bebebe Jun 10 '14 at 07:39
  • You have to sort the data _with_ the legend otherwise you end up with garbage – UserEleventyOne Jun 10 '14 at 07:40
  • I have another problem, the legend above is just a sample. What if I got a legend name in Array 1 like "Apple[0]" and in the Array 2 it has a legend like "Apart[0], Apple[1]" so the tendency is it will also end up to a wrong computation, right? – bebebe Jun 10 '14 at 08:09
  • Yes, if you have different data in each array then you will need to sort first and then go down each array one element at a time matching the right item in one to the right item in the other. That problem would be worth adding as a separate question as it's different to your original question. – UserEleventyOne Jun 12 '14 at 06:01
0

Rather than storing the values in an array you can store them in a custom collection and key the collection by the Legend. For example you would have a class with properties called Legend (string), X (int), Y(int). You would have a custom collection called calcSources.

  • As you read each item from the file, you check to see does that legend already exist in your collection (by seeing does the key exist, this is really fast).
  • If it does exist then you add your values in X or Y as appropriate
  • If it does not exist you create a instance of the class , set it's values and then add it to the collection, using the legend as a key.
  • Once you have all the values loaded, you can check to see if you have valid values in each row and only calculate on those where you do.

Have a look at these articles for help on creating custom collections in VB6 http://anturcynhyrfus.blogspot.ie/2009/03/creating-custom-collection-object.html

VB 6 How to make Custom Collection Class to support For Each

Sorry but don't have VB6 any more otherwise would do an example for you.

Community
  • 1
  • 1
Bigtoe
  • 3,372
  • 1
  • 31
  • 47