If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Need help with String comparsion. (should be easy but...)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-04, 04:44
Mirador Mirador is offline
Registered User
 
Join Date: Jan 2004
Location: Oslo
Posts: 45
Arrow 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>
----------------------------------------------
__________________
Best regards
Mirador

Last edited by Mirador; 10-21-04 at 04:46.
Reply With Quote
  #2 (permalink)  
Old 10-21-04, 18:52
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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....
Reply With Quote
  #3 (permalink)  
Old 10-22-04, 03:06
Mirador Mirador is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On