Simple unusual variable problem

Discussion in 'ASP General' started by Bramo, Sep 24, 2004.

  1. Bramo

    Bramo Guest

    Hi guru guys,

    I have serious problem. At first sight it looks very simple but i dont
    have any idea how to solve it.

    With this statement 'If len(rs_cit) = 0 then rs_cit = 0' I cant put
    into variable 'rs_cit' value '0' if it is clean. There is no value in
    html displayed.

    Here is code:

    ....
    Dim rs_customer, rs_cit, rs_total, rs_manual

    i = 1
    Do While Not RS.Eof

    rs_customer = RS("customer")
    rs_account = RS("account")
    rs_cit = RS("cit")
    rs_total = RS("total")
    rs_manual = rs_total - rs_cit

    If len(rs_cit) = 0 then rs_cit = 0
    'neither this does not work: If rs_cit = "" then rs_cit = 0


    response.write ("<tr>")
    response.write ("<td bgcolor='black' align='right'>" & i & ".</td>")
    i = i + 1
    response.write ("<td bgcolor='black'>" & rs_account & "</td>")
    response.write ("<td bgcolor='black'>" & rs_customer & "</td>")
    response.write ("<td align='center' bgcolor='#666666'>" & rs_cit &
    "</td>")
    response.write ("<td align='center' bgcolor='#666666'>" & rs_manual &
    "</td>")
    response.write ("<td align='center' bgcolor='#666666'>" & rs_total &
    "</td>")
    response.write ("</tr>")
    RS.MoveNext
    Loop
    ....
     
    Bramo, Sep 24, 2004
    #1
    1. Advertising

  2. Bramo

    David Morgan Guest

    rs_cit = RS("cit") might be null. In some cases using Len can be
    unreliable.

    Try

    If IsNull(rs_cit) Or Len(rs_cit) = 0 Then rs_cit = 0


    "Bramo" <> wrote in message
    news:...
    > Hi guru guys,
    >
    > I have serious problem. At first sight it looks very simple but i dont
    > have any idea how to solve it.
    >
    > With this statement 'If len(rs_cit) = 0 then rs_cit = 0' I cant put
    > into variable 'rs_cit' value '0' if it is clean. There is no value in
    > html displayed.
    >
    > Here is code:
    >
    > ...
    > Dim rs_customer, rs_cit, rs_total, rs_manual
    >
    > i = 1
    > Do While Not RS.Eof
    >
    > rs_customer = RS("customer")
    > rs_account = RS("account")
    > rs_cit = RS("cit")
    > rs_total = RS("total")
    > rs_manual = rs_total - rs_cit
    >
    > If len(rs_cit) = 0 then rs_cit = 0
    > 'neither this does not work: If rs_cit = "" then rs_cit = 0
    >
    >
    > response.write ("<tr>")
    > response.write ("<td bgcolor='black' align='right'>" & i & ".</td>")
    > i = i + 1
    > response.write ("<td bgcolor='black'>" & rs_account & "</td>")
    > response.write ("<td bgcolor='black'>" & rs_customer & "</td>")
    > response.write ("<td align='center' bgcolor='#666666'>" & rs_cit &
    > "</td>")
    > response.write ("<td align='center' bgcolor='#666666'>" & rs_manual &
    > "</td>")
    > response.write ("<td align='center' bgcolor='#666666'>" & rs_total &
    > "</td>")
    > response.write ("</tr>")
    > RS.MoveNext
    > Loop
    > ...
     
    David Morgan, Sep 24, 2004
    #2
    1. Advertising

  3. Bramo wrote:
    > With this statement 'If len(rs_cit) = 0 then rs_cit = 0' I cant put
    > into variable 'rs_cit' value '0' if it is clean. There is no value in
    > html displayed.
    > ...
    > rs_cit = RS("cit")
    > ...
    > If len(rs_cit) = 0 then rs_cit = 0
    > 'neither this does not work: If rs_cit = "" then rs_cit = 0


    For what it's worth, this is all you need to meet your needs in JScript:

    rs_cit = RS.Fields("cit").Value || 0


    It is sufficient because JScript coerces null and empty string values into
    false boolean values when used in conditional assignment constructions.



    --
    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, Sep 24, 2004
    #3
    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. William A. Sempf

    Unusual performance problem.

    William A. Sempf, Aug 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    378
    William A. Sempf
    Aug 27, 2003
  2. Dan

    Unusual problem with smartnav

    Dan, Jan 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    S. Justin Gengo
    Jan 6, 2006
  3. Jacob Arthur
    Replies:
    1
    Views:
    472
    =?Utf-8?B?RFdT?=
    Mar 1, 2006
  4. Rasika WIJAYARATNE

    Very unusual re-direction problem

    Rasika WIJAYARATNE, Feb 25, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    489
    Rasika WIJAYARATNE
    Feb 25, 2007
  5. DLitgo
    Replies:
    0
    Views:
    356
    DLitgo
    Mar 6, 2009
Loading...

Share This Page