Loop D Loop

Discussion in 'ASP General' started by Tim:.., Apr 6, 2004.

  1. Tim:..

    Tim:.. Guest

    Can someone please tell me what I'm doing wrong here

    I'm trying to give the variable sStart a new name on each loo
    EG
    sStart1 = value1
    sStart2 = value

    however the following piece of code doesn't work

    Thank

    set oNodes=xml.selectNodes("/Project/Tasks/Task/Start"
    for each oNode in oNode
    sStart=oNode.tex
    response.write("<BR>"
    for i=0 to 10
    response.Write(sStart(i)
    nex
    next
    Tim:.., Apr 6, 2004
    #1
    1. Advertising

  2. Tim:..

    Maarten Guest

    You can't use sStart as singel variable and as list.
    use myStart or something else
    Maarten, Apr 6, 2004
    #2
    1. Advertising

  3. Tim:..

    Tim:.. Guest

    Something like this you mean

    I get a Type mismatch: 'myStart

    Any ideas? Thanks for the response but I could use a little more detailed discription

    Thank

    set oNodes=xml.selectNodes("/Project/Tasks/Task/Start"
    for each oNode in oNode
    sStart=oNode.tex
    response.write("<BR>"
    for i=0 to 10
    myStart(i) = sStar
    response.Write(myStart(i)
    nex
    next
    Tim:.., Apr 6, 2004
    #3
  4. Tim:..

    Maarten Guest

    First: i know almost nothing about xml. I suppose you wish to retrieve the
    notes in a xml file. But why you need the loop and the 101 times the name of
    this node? Or do you want to cache the names of the nodes in strings? In
    this case the name of the second node overwrites the first, etc...

    Dim myNodes(200,100)

    node=-1

    set oNodes=xml.selectNodes("/Project/Tasks/Task/Start")

    for each oNode in oNodes
    node=node+1
    for i=0 to 100
    myNodes(node,i) = oNode.text
    next
    response.Write(myNotes(node,0)) & "<br>"
    next
    Maarten, Apr 6, 2004
    #4
  5. Tim:.. wrote:
    > This doesn't work!
    >
    > I think it might be because it is the XML messing it up! I have been
    > having serious problems with it!
    >
    > I get an error:
    > Type mismatch: 'myNodes'
    >
    > Thanks anyway!


    We can't help without knowing the structure of your sml document. How about
    posting a couple nodes so we know how to construct the xpath query.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Apr 6, 2004
    #5
  6. Tim:.. wrote:
    > Hi,
    >
    > OK here is an extract from the XML document!
    >
    > ..XML..
    >

    <Project>
    <Name>Test1</Name>
    <Version>1.0</Version>
    <Tasks>
    <Task>
    <ID>1</ID>
    <Start>2004-03-26T08:00:00</Start>
    <Finish>2004-03-28T17:00:00</Finish>
    </Task>
    <Task>
    <ID>2</ID>
    <Start>2004-03-29T08:00:00</Start>
    <Finish>2004-03-30T17:00:00</Finish>
    </Task>
    </Tasks>
    </Project>
    >
    > ..CODE..
    >
    > Dim myNodes(200,100)
    >
    > node=-1
    >
    > set oNodes=xml.selectNodes("/Project/Tasks/Task/Start")
    >
    > for each oNode in oNodes
    > node=node+1
    > for i=0 to 100
    > myNodes(node,i) = oNode.text
    > next
    > response.Write(myNotes(node,0)) & "<br>"
    > next
    >
    > This code produces a Type Mismatch error for 'myNodes'
    >

    The Response.Write line does not look correct. For one thing: it says
    "myNotes" instead of "myNodes". For another, don't use parentheses around
    the response.write argument: it can only screw you up. Try this:
    response.Write myNodes(node,0) & "<br>"

    FWIW, when I use this code with your xml document:

    set oNodes=xmldoc.selectNodes("/Project/Tasks/Task/Start")

    for each oNode in oNodes
    Response.Write oNode.text & "<BR>"
    next

    I get the desired results:
    2004-03-26T08:00:00
    2004-03-29T08:00:00

    So we can be sure your xpath syntax is correct.

    What is the goal here? I don't understand the purpose of the myNodes array.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Apr 6, 2004
    #6
  7. "Bob Barrows [MVP]" <> wrote in message
    news:%23gKsn7%...
    > Tim:.. wrote:
    > > Hi,
    > >
    > > OK here is an extract from the XML document!
    > >
    > > ..XML..
    > >

    > <Project>
    > <Name>Test1</Name>
    > <Version>1.0</Version>
    > <Tasks>
    > <Task>
    > <ID>1</ID>
    > <Start>2004-03-26T08:00:00</Start>
    > <Finish>2004-03-28T17:00:00</Finish>
    > </Task>
    > <Task>
    > <ID>2</ID>
    > <Start>2004-03-29T08:00:00</Start>
    > <Finish>2004-03-30T17:00:00</Finish>
    > </Task>
    > </Tasks>
    > </Project>
    > >
    > > ..CODE..
    > >
    > > Dim myNodes(200,100)
    > >
    > > node=-1
    > >
    > > set oNodes=xml.selectNodes("/Project/Tasks/Task/Start")
    > >
    > > for each oNode in oNodes
    > > node=node+1
    > > for i=0 to 100
    > > myNodes(node,i) = oNode.text
    > > next
    > > response.Write(myNotes(node,0)) & "<br>"
    > > next
    > >
    > > This code produces a Type Mismatch error for 'myNodes'
    > >

    > The Response.Write line does not look correct. For one thing: it says
    > "myNotes" instead of "myNodes". For another, don't use parentheses

    around
    > the response.write argument: it can only screw you up. Try this:
    > response.Write myNodes(node,0) & "<br>"
    >
    > FWIW, when I use this code with your xml document:
    >
    > set oNodes=xmldoc.selectNodes("/Project/Tasks/Task/Start")
    >
    > for each oNode in oNodes
    > Response.Write oNode.text & "<BR>"
    > next
    >
    > I get the desired results:
    > 2004-03-26T08:00:00
    > 2004-03-29T08:00:00
    >
    > So we can be sure your xpath syntax is correct.
    >
    > What is the goal here? I don't understand the purpose of the myNodes

    array.

    Once the Response.Write statement is fixed, the OP is likely to
    encounter a "subscript out of range" error.

    for i = 0 to 100

    should read

    for i = 0 to 99

    Although I agree with Bob. I don't understand what the purpose of
    myNodes is.

    -Chris Hohmann
    Chris Hohmann, Apr 6, 2004
    #7
    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?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,377
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,223
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    686
    Remon van Vliet
    Jun 15, 2005
  4. Byte
    Replies:
    4
    Views:
    412
  5. Isaac Won
    Replies:
    9
    Views:
    363
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page