Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    Oslo
    Posts
    45

    Arrow Unanswered: Need help with String comparsion. (should be easy but...)

    Hi there and thanx for reading my post

    I'm a bit confused here, after trying all known possibilities to make this work, but yet.. nono.. no success

    Either way i put it i get either

    1) "Missing Default property" cause it seems i need totSak(0) and not totSak.
    2) Type Mismatch or Type Mismatch '[string ""]'

    Where should i use :

    1) cStr ?
    2) totSak(0) VS totSak ?

    Therefore i humbly ask someone for help, to see if someone can see what's wrong with this :
    Any code completion of this mess would be perfect !

    ---------------INFO-----------------
    ASP -> MS SQL database
    saksomr is a int (field in table)
    saksomrade is a string (field in table)
    -------------------------------------

    --------------SQL QUERY---------------
    //before this comes the connection and everything.. and that works perfect//
    Dim objRS
    objCommand.CommandText = "SELECT enavn,fnavn,prof,arbsted,adr,postnr,poststed,tlfnr ,mobnr,epost,passiv,saksomr,fagkomp,funksjoner,ste d,fylke,pd,kontaktpers,fritekst from KONTAKT"
    set objRs = objCommand.Execute
    ----------------------------------------

    -----------THE COMPARSION-------------
    Dim totSak, tmpSak
    totSak = "0"
    tmpSak = "0"

    if cStr(objRs("saksomr")) = "1" then
    objCommand.CommandText = "SELECT saksomrade FROM SAKSOMR WHERE SID = 1"
    set tmpSak=objCommand.Execute

    if cStr(totsak) = "0" then
    totSak = tmpSak
    else
    totSak = totSak & "<br>" & tmpSak
    end if
    end if

    // PS ! There are 4 IF checks like this for the 4 different saksomr.
    // if there's more than one saksomr on one post, it just uses tmpSak to add
    // to Totsak with a <br> between...
    ---------------------------------------------

    -------------PRINTING OUT-------------------
    <td class="litentekst_gra"><% Response.Write(totSak) %></td>
    ----------------------------------------------
    Last edited by Mirador; 10-21-04 at 05:46.
    Best regards
    Mirador

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    okie, looks like you are getting yourself a little confused in this section
    Code:
    Dim totSak, tmpSak
    totSak = "0"
    tmpSak = "0"
    
    if cStr(objRs("saksomr")) = "1" then
      objCommand.CommandText = "SELECT saksomrade FROM SAKSOMR WHERE SID = 1"
      set tmpSak=objCommand.Execute
    
      if cStr(totsak) = "0" then
        totSak = tmpSak
      else
        totSak = totSak & "<br>" & tmpSak
      end if
    end if
    the key mistake is the tmpSak is a recordset, not a simple string variable. So you need to do something like this...
    Code:
    Dim totSak, tmpSak
    totSak = "0"
    tmpSak = "0"
    
    if cStr(objRs("saksomr")) = "1" then
      objCommand.CommandText = "SELECT saksomrade FROM SAKSOMR WHERE SID = 1"
      set tmpSak=objCommand.Execute
    
      if cStr(totsak) = "0" then
        totSak = tmpSak("saksomrade")
      else
        totSak = totSak & "<br>" & cstr(tmpSak("saksomrade"))
      end if
    end if
    this means that totSak will become the value of the first record returned by "SELECT saksomrade FROM SAKSOMR WHERE SID = 1"

    One thing I am not sure about though is why you have this line...
    Code:
    if cStr(totsak) = "0" then
    from the sample you have given this will always be true....

  3. #3
    Join Date
    Jan 2004
    Location
    Oslo
    Posts
    45
    Hi there and thanx for the answer

    Well.. the reason for the :
    if cStr(totsak) = "0" then
    .... is just to reset the totsak before i start the if sentences.. (u see.. i have one if for each choice in the table...) It might be that it's not placed right though

    I finally understood it though, thanx to your example !!..

    Was very helpful...

    Have a great day
    Best regards
    Mirador

Posting Permissions

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