• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Complicated Array Use


Hopefully someone here can help me along with this....

I have a multi-dimension array which would look something like this:

B   N27   W38
F   N10   E11
N   S13   W18

etc etc

I now need to do something like the following with it:

For each "row" in the array
   Do calculation on the number part of Column 2
          IF N assign +ive sign to the answer
          IF S assign -ive sign to the answer
   Do calculation on the number part of column 3
          IF E assign +ive sign to the answer
          IF W assign -ive sign to the answer

   Draw Point (Answer2, Answer1)
    IF column 1 = B  draw in red
    IF column 1 = F  draw in green
    IF column 1 = N  draw in blue

NEXT "row"

If anyone can give me some pointers as to how i go about this, that would be great. I've been trying to do this for days :-)

  • 2
1 Solution
' use user defined types.

Option Explicit

Private Type MyType
   Field1 as string
   Field2 as string
   field3 as string

Private MyData(100) as MyType
Private MyDataCount as long

Private Sub DoCalculations()
   Dim i as long
   Dim Answer1 as long
   Dim Answer2 as long

   for i = 0 to MyDataCount - 1
        IF (Left(MyData(i).Field2, 1) = "N") then
              Answer1 = Val(mid(MyData(i).Field2, 2))
        ElseIF (Left(MyData(i).Field2, 1) = "S") then
              Answer1 = -Val(mid(MyData(i).Field2, 2))
        end if
        IF (Left(MyData(i).Field3, 1) = "E") then
              Answer1 = Val(mid(MyData(i).Field3, 2))
        ElseIF (Left(MyData(i).Field3, 1) = "W") then
              Answer1 = -Val(mid(MyData(i).Field3, 2))
        end if

       DrawPoint Answer2, Answer1

       IF (column 1 = B) then drawColour = vbred
       IF (column 1 = F) then drawColour = vbgreen
       IF (column 1 = N) then drawColour = vbBlue
   next i
End Sub

' Good luck!
codeheavenAuthor Commented:
Thanks supunr!

Just one thing though... how do i populate this user defined type from my array? If the array name is something like strResults()?
MyDataCount = 10

for i = 0 to MyDataCount-1
   MyData(i).Field1 = "B"
   MyData(i).Field2 = "N123"
   MyData(i).Field3 = "E120"
   ' etc.
next i

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now