Parse record, convert to session variables

Discussion in 'ASP General' started by Brandon, Jun 9, 2004.

  1. Brandon

    Brandon Guest

    Greetings,

    I have a database with records that contain data like the following:

    "vendor" - "phone number" - "city", "state" "problem."

    For example:
    xyzcompany - 800-123-4567 - new york, ny tp.

    The line above is one record, the company names will differ (but are
    limited to a dozen), the format of the number will always be with a dash
    seperating the area code and number, the city and state will be in
    place, and the problem will be a two letter code followed by a period.

    I need to be able to parse that record into seperate session variables
    such as Session("vendor"), Session("area_code"), Session("number"), and
    on with the city, state, and problem.

    What is the best method to use in VBScript/ASP to break this record down
    into pieces?

    I appreciate any help you can give.

    Thanks,
    Brandon


    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Brandon, Jun 9, 2004
    #1
    1. Advertising

  2. Brandon

    Alan Howard Guest

    You say the data below is a record - assuming that you are still able to
    address the individual fields, use something like:

    For Each objField In objRS.Fields

    Session (CStr(objField.Name)) = CStr(objField.Value)

    Next

    - or are you asking how to split a single string??


    "Brandon" <bdreilingATmac.com> wrote in message
    news:%...
    > Greetings,
    >
    > I have a database with records that contain data like the following:
    >
    > "vendor" - "phone number" - "city", "state" "problem."
    >
    > For example:
    > xyzcompany - 800-123-4567 - new york, ny tp.
    >
    > The line above is one record, the company names will differ (but are
    > limited to a dozen), the format of the number will always be with a dash
    > seperating the area code and number, the city and state will be in
    > place, and the problem will be a two letter code followed by a period.
    >
    > I need to be able to parse that record into seperate session variables
    > such as Session("vendor"), Session("area_code"), Session("number"), and
    > on with the city, state, and problem.
    >
    > What is the best method to use in VBScript/ASP to break this record down
    > into pieces?
    >
    > I appreciate any help you can give.
    >
    > Thanks,
    > Brandon
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Alan Howard, Jun 9, 2004
    #2
    1. Advertising

  3. Alan Howard wrote:
    >
    > For Each objField In objRS.Fields
    >
    > Session (CStr(objField.Name)) = CStr(objField.Value)
    >
    > Next


    CStr is unnecessary with [Name]...
    http://msdn.microsoft.com/library/en-us/ado270/htm/mdproname.asp


    ....and possibly unwanted with [Value], depending on the data type.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jun 9, 2004
    #3
  4. Brandon

    Mark Schupp Guest

    If your format and delimiters are fixed (unchanging) then

    a1 = split( strRecord, ",")
    a2 = split( a1(0), "-")
    a3 = split( a1(1), " ")

    vendor = a2(0)
    areacode = a2(1)
    phonenum = a2(2) & "-" a2(3)
    city = a2(4)
    state = a3(0)
    prob = a3(1)


    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Brandon" <bdreilingATmac.com> wrote in message
    news:%...
    > Greetings,
    >
    > I have a database with records that contain data like the following:
    >
    > "vendor" - "phone number" - "city", "state" "problem."
    >
    > For example:
    > xyzcompany - 800-123-4567 - new york, ny tp.
    >
    > The line above is one record, the company names will differ (but are
    > limited to a dozen), the format of the number will always be with a dash
    > seperating the area code and number, the city and state will be in
    > place, and the problem will be a two letter code followed by a period.
    >
    > I need to be able to parse that record into seperate session variables
    > such as Session("vendor"), Session("area_code"), Session("number"), and
    > on with the city, state, and problem.
    >
    > What is the best method to use in VBScript/ASP to break this record down
    > into pieces?
    >
    > I appreciate any help you can give.
    >
    > Thanks,
    > Brandon
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Mark Schupp, Jun 9, 2004
    #4
  5. Brandon

    Alan Howard Guest

    > CStr is unnecessary with [Name]...
    > ...and possibly unwanted with [Value], depending on the data type.


    Habit - easier than second-guessing variant sub-types.

    Alan

    "Dave Anderson" <> wrote in message
    news:...
    > Alan Howard wrote:
    > >
    > > For Each objField In objRS.Fields
    > >
    > > Session (CStr(objField.Name)) = CStr(objField.Value)
    > >
    > > Next

    >
    > CStr is unnecessary with [Name]...
    > http://msdn.microsoft.com/library/en-us/ado270/htm/mdproname.asp
    >
    >
    > ...and possibly unwanted with [Value], depending on the data type.
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
     
    Alan Howard, Jun 9, 2004
    #5
  6. Brandon

    Brandon Guest

    Thanks, that did the trick!

    Brandon
    _________________________________________

    If your format and delimiters are fixed (unchanging) then

    a1 = split( strRecord, ",")
    a2 = split( a1(0), "-")
    a3 = split( a1(1), " ")

    vendor = a2(0)
    areacode = a2(1)
    phonenum = a2(2) & "-" a2(3)
    city = a2(4)
    state = a3(0)
    prob = a3(1)


    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com

    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Brandon, Jun 10, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Retrieving Record Key while creating the record.

    =?Utf-8?B?SnVzdGlu?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    637
    =?Utf-8?B?SnVzdGlu?=
    Oct 5, 2004
  2. André
    Replies:
    0
    Views:
    3,751
    André
    Jun 25, 2006
  3. MRW
    Replies:
    0
    Views:
    380
  4. THurkmans
    Replies:
    2
    Views:
    606
  5. Frits van Soldt

    How to insert a new record in detailsview when there are no record

    Frits van Soldt, Nov 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    751
    Frits van Soldt
    Nov 17, 2005
Loading...

Share This Page