Number Prefix Lookup Table in MDB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John R

    Number Prefix Lookup Table in MDB

    Hi all,

    I'm trying to get my VB6 app to look up prefixes for a phone number out of
    an MDB file along with an associated price etc.

    For example the phone number could be 9802xxxx, and the MDB file will have
    the record 9802 with an associated price.

    I am used to connecting to databases via ADO, but my problem is that the MDB
    file may contain prefixes from 1 to 5 chars in length and i'm not sure how
    to get VB to find the best match.

    I'm assuming it can be done with a very large nested IF statement, is there
    a better way?

    Cheers,
    John


  • Bob Butler

    #2
    Re: Number Prefix Lookup Table in MDB

    "John R" <johnr_lives@SP AMhotmail.com> wrote in message news:<3fcb48ba$ 0$13968$afc38c8 7@news.optusnet .com.au>...[color=blue]
    > Hi all,
    >
    > I'm trying to get my VB6 app to look up prefixes for a phone number out of
    > an MDB file along with an associated price etc.
    >
    > For example the phone number could be 9802xxxx, and the MDB file will have
    > the record 9802 with an associated price.
    >
    > I am used to connecting to databases via ADO, but my problem is that the MDB
    > file may contain prefixes from 1 to 5 chars in length and i'm not sure how
    > to get VB to find the best match.[/color]

    he exmaple you give matches the first 4 digits of an 8-character code
    against a field that is an exact match. That seems like a simple
    query. You then say it can be 1-5 characters and you want the "best
    match" but don't explain what the possible matches are or which would
    be better than others... can you elaborate with some more examples
    include good/better/best matches?

    Comment

    • John R

      #3
      Re: Number Prefix Lookup Table in MDB

      Thanks for the reply Bob, let me see if i can explain it a bit better.

      I am trying to parse an output file from a PABX phone system. I have an MDB
      file with aprox 200 prefixes which rance from 1-5 chars in length (eg:
      country codes, national & local telephone codes).

      as an example, an international number dialled might be: 001161290000000 ,
      and this would correspond to the record '0011' (int. call prefix) in the
      MDB file. yet a local number would be just 90000000, and correspond to the
      record '9' as long as there is no record '90' etc. So you can see my dilemma
      with length of strings.

      It will always be an exact match, but i may have the strings "9" "90" and
      "901", the number "9058321" would have to be matched to "90" in the
      database and "921345" would have to match just "9".

      I was thinking of a large IF statement starting with LEFT(string,5), if it
      finds no match move on to LEFT,4 and etc all the way to 1.

      Is there a better way? if not whats the best way of organising an if
      statement that large?

      Cheers,
      John R.

      "Bob Butler" <butlerbob@eart hlink.net> wrote in message
      news:fa10fb0.03 12020617.16eaf9 92@posting.goog le.com...[color=blue]
      > he exmaple you give matches the first 4 digits of an 8-character code
      > against a field that is an exact match. That seems like a simple
      > query. You then say it can be 1-5 characters and you want the "best
      > match" but don't explain what the possible matches are or which would
      > be better than others... can you elaborate with some more examples
      > include good/better/best matches?[/color]


      Comment

      • J French

        #4
        Re: Number Prefix Lookup Table in MDB

        On Thu, 4 Dec 2003 23:57:34 +1100, "John R"
        <johnr_lives@SP AMhotmail.com> wrote:
        [color=blue]
        >Thanks for the reply Bob, let me see if i can explain it a bit better.
        >
        >I am trying to parse an output file from a PABX phone system. I have an MDB
        >file with aprox 200 prefixes which rance from 1-5 chars in length (eg:
        >country codes, national & local telephone codes).
        >
        >as an example, an international number dialled might be: 001161290000000 ,
        >and this would correspond to the record '0011' (int. call prefix) in the
        >MDB file. yet a local number would be just 90000000, and correspond to the
        >record '9' as long as there is no record '90' etc. So you can see my dilemma
        >with length of strings.
        >
        >It will always be an exact match, but i may have the strings "9" "90" and
        >"901", the number "9058321" would have to be matched to "90" in the
        >database and "921345" would have to match just "9".
        >
        >I was thinking of a large IF statement starting with LEFT(string,5), if it
        >finds no match move on to LEFT,4 and etc all the way to 1.
        >
        >Is there a better way? if not whats the best way of organising an if
        >statement that large?[/color]

        If you only have 200 prefixes to deal with, then I would pull the lot
        out into an Array
        - pound them into a standard format
        - and do a Binary Chop

        If I understand your problem correctly, you need to re-format the data
        and the search key (using the same routine)

        At which point the problem disappears
        eg:
        A single '9'
        would find its best match if it were looking for '9' + Chr$(32)

        Comment

        • John R

          #5
          Re: Number Prefix Lookup Table in MDB

          Can you explain this 'routine' a little better?

          Cheers,
          John R[color=blue]
          > If you only have 200 prefixes to deal with, then I would pull the lot
          > out into an Array
          > - pound them into a standard format
          > - and do a Binary Chop
          >
          > If I understand your problem correctly, you need to re-format the data
          > and the search key (using the same routine)
          >
          > At which point the problem disappears
          > eg:
          > A single '9'
          > would find its best match if it were looking for '9' + Chr$(32)[/color]


          Comment

          • Steve Gerrard

            #6
            Re: Number Prefix Lookup Table in MDB


            "John R" <johnr_lives@SP AMhotmail.com> wrote in message
            news:3fcfac9e$0 $13968$afc38c87 @news.optusnet. com.au...[color=blue]
            > Can you explain this 'routine' a little better?
            >
            > Cheers,
            > John R[color=green]
            > > If you only have 200 prefixes to deal with, then I would pull the[/color][/color]
            lot[color=blue][color=green]
            > > out into an Array
            > > - pound them into a standard format
            > > - and do a Binary Chop
            > >
            > > If I understand your problem correctly, you need to re-format the[/color][/color]
            data[color=blue][color=green]
            > > and the search key (using the same routine)
            > >
            > > At which point the problem disappears
            > > eg:
            > > A single '9'
            > > would find its best match if it were looking for '9' + Chr$(32)[/color]
            >
            >[/color]

            1. Load the 200 prefixes into a recordset, and sort them by Len(Prefix)
            DESC, so the longest are first.
            2. Copy the records into an array.
            3. Run through the phone number records, and for each one, scan the
            array for a match.
            4. Store the correct prefix in each phone number record, so you don't
            have to do it again.
            5. The loop for one record might look something like
            For n =1 to 200
            If (Left(rs("Phone Number"),Len(ar rayPrefix(n)) =
            arrayPrefix(n) Then
            rs("Prefix") = arrayPrefix(n)
            rs.Update
            Exit For
            next n
            6. Make the array and matching function available for new and edited
            records, so they get their prefix assigned when they are entered or
            updated.





            Comment

            • John R

              #7
              Re: Number Prefix Lookup Table in MDB

              Thats a good way of doing it! Thankyou all.



              [color=blue][color=green][color=darkred]
              > > > If you only have 200 prefixes to deal with, then I would pull the[/color][/color]
              > lot[color=green][color=darkred]
              > > > out into an Array
              > > > - pound them into a standard format
              > > > - and do a Binary Chop
              > > >
              > > > If I understand your problem correctly, you need to re-format the[/color][/color]
              > data[color=green][color=darkred]
              > > > and the search key (using the same routine)
              > > >
              > > > At which point the problem disappears
              > > > eg:
              > > > A single '9'
              > > > would find its best match if it were looking for '9' + Chr$(32)[/color]
              > >
              > >[/color]
              >
              > 1. Load the 200 prefixes into a recordset, and sort them by Len(Prefix)
              > DESC, so the longest are first.
              > 2. Copy the records into an array.
              > 3. Run through the phone number records, and for each one, scan the
              > array for a match.
              > 4. Store the correct prefix in each phone number record, so you don't
              > have to do it again.
              > 5. The loop for one record might look something like
              > For n =1 to 200
              > If (Left(rs("Phone Number"),Len(ar rayPrefix(n)) =
              > arrayPrefix(n) Then
              > rs("Prefix") = arrayPrefix(n)
              > rs.Update
              > Exit For
              > next n
              > 6. Make the array and matching function available for new and edited
              > records, so they get their prefix assigned when they are entered or
              > updated.
              >
              >
              >
              >
              >[/color]


              Comment

              Working...