Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Searching a multidemensional array...

Searching a multidemensional array...

Scheduled Pinned Locked Moved Database
questionalgorithmsdata-structuresregex
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix 0
    wrote on last edited by
    #1

    I am working on a customized Excel VBA function. I have developed a two dimensional array consisting of two fields. The first element is a Date field and the second field is an Integer field. The problem is that now I need to search through the array using the first field, and when a match is found to return the second field as the result. The name of the array is arrArray. It is a static array with a set number of records. How should I go about searching the array? As an example, let us assume that there are ten elements and that they are properly loaded like this:

       Dim arrArray(10, 1)
    
       arrArray(#1/1/2006#, 1)
       arrArray(#1/2/2006#, 4)
    

    How do I search through the first element field for a match, and when a match is found to return the second element? :confused::confused::confused:

    R 1 Reply Last reply
    0
    • N new_phoenix 0

      I am working on a customized Excel VBA function. I have developed a two dimensional array consisting of two fields. The first element is a Date field and the second field is an Integer field. The problem is that now I need to search through the array using the first field, and when a match is found to return the second field as the result. The name of the array is arrArray. It is a static array with a set number of records. How should I go about searching the array? As an example, let us assume that there are ten elements and that they are properly loaded like this:

         Dim arrArray(10, 1)
      
         arrArray(#1/1/2006#, 1)
         arrArray(#1/2/2006#, 4)
      

      How do I search through the first element field for a match, and when a match is found to return the second element? :confused::confused::confused:

      R Offline
      R Offline
      riced
      wrote on last edited by
      #2

      Assuming you have filled the array with something like:

      arrArray(1, 0) = "#1/1/2006#"
      arrArray(1, 1) = 1
      arrArray(2, 0) = "#1/2/2006#"
      arrArray(2, 1) = 4

      Then something like this should do it

      Dim retVal
      Dim match
      Dim i

      match = "#1/2/2006#"
      For i = 1 To 10
      If arrArray(i, 0) = match Then
      retVal = arrArray(i, 1)
      End If
      Next i

      Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups