SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    add 2 strings numerically

    i have 2 strings: a value in an array and a variable from some xml.

    I need to numeriaclly add them together, as they are both strings, using + doesn't work. I have tried cStr but it errors

    what do I do?

    cheers

    monkey
    monkey - the rest is history

  2. #2
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just tried adding 1 to one of the values and then minus 1 of the end, but it appears it an xml error. I have:

    myVar=(xmlDoc.selectSingleNode("DataReturn/DataBatch").xml)

    myNum=myArray(0) + myVar

    but the page seems to always read the xml value fresh, rather then just setting myVar to the value of DataBatch - how can i sort this?

    cheers

    monkey
    monkey - the rest is history

  3. #3
    SitePoint Enthusiast Vedran Vuleta's Avatar
    Join Date
    May 2005
    Location
    Croatia
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try with &
    string3 = string1 & string2

  4. #4
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    & is for concatenation not addition
    monkey - the rest is history

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xmlDoc.selectSingleNode("DataReturn/DataBatch").xml

    is not a number, its a string representation of the node, so it's likely to be something like
    "<DataBatch>22</DataBatch>"
    or maybe even
    "<DataBatch>22<childNode>somevalue</childNode></DataBatch>"

    Try
    CDbl(xmlDoc.selectSingleNode("DataReturn/DataBatch").text)
    to return a numeric value of what's contained in some node

    Don't forget to use Response.Write(thingie) if you're not sure about what (thingie) contains.

    I also suggest you install the documentation from the latest MSXML object and refer to that!

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    CLng()
    CDbl()
    CInt()

    ???
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used CDbl because it'll work regardless of whether the number has decimals or not.

  8. #8
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    superstars!!!!

    I am booked onto a course, so hopefully I will be able to learn a lot from that and stop asking what are probably stupid question!

    cheers
    monkey - the rest is history

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser View Post
    I used CDbl because it'll work regardless of whether the number has decimals or not.
    I wasn't questioning your post, merely showing other type conversion functions - look at the post timestamps.
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at the post timestamps
    Huh, we keep doing that today.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •