Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2003, 11:38 AM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default Simple but not working IF THEN statement

CODE BELOW
Someone give me some more eyes to see what I am screwing up. I have done 1000 of these but this one doesn't work properly... Here is the scenario. I am pulling field data from an access db. When there is data in the fields (MEMO field type due to size) the information from each field is displayed on web page as coded after each ELSE statement. But when there is no data in field (I delete it) then nothing is displayed on the page but the beginning of the wrong outputted text (Your company contact is: NOTHING HERE , as in first IF THEN statement).

I have already tried replacing the "" with NULL in the IF statement and also tried to use ... IF ISEMPTY(txtCompanyContact) THEN ... but identical result. I want to give the user a reminder if this info has not been completed or display it if it is already in the db. Does the memo field type effect this? Is NULL or "" not appropriate for checking for existing data in a field? I know the db connection and vars are working because the vars txtCompanyContact, etc. are displayed if they exist in db. But if DB is empty then it displays the second message after ELSE incompletely (Your company contact is: ______ )

Sorry for the lengthy explanation - appreciate any advice...



IF txtCompanyContact = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site contact is: <strong>" & txtCompanyContact & "</strong><BR>"
END IF

IF txtSitePhone = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site phone is: <strong>" & txtSitePhone & "</strong><BR>"
END IF

IF txtSiteEmail = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site e-mail is: <strong>" & txtSiteEmail & "</strong><BR>"
END IF
 
Old June 5th, 2003, 01:44 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

Correction - they are TEXT fields in access...
 
Old June 5th, 2003, 05:12 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Are you sure this isn't caused by Access's "spaces for empty fields" feature? Often an apparently empty field contains a space.

Here's what you can try:

If Trim(txtCompanyContact) & "" = "" Then
    Response.Write "You have not yet completed your public information profile."
Else
    Response.Write "" & _
    "Your site contact is: <strong>" & _
    txtCompanyContact & "</strong><BR>"
End If


How do you assign txtCompanyContact a value? Are you sure it contains the right info from the database??

Cheers,

Imar
 
Old June 5th, 2003, 06:51 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

I use

Dim txtCompanyContact
txtCompanyContact = objRS("txtCompanyContact")

after creating a dsn connection. I knew it was working because when the field had a name it appeared on the page -

Your contact name is : NAME HERE

But when the field was empty the page would just display

Your contact name is:

I did what you said and understand the trim function and it worked great, sincere thanks. But one last question. I have used trim but dont quite understand the method/syntax you used.

If Trim(txtCompanyContact) & "" = "" Then

What is concatenated with the '&'... and "" ...?

I will try to figure it out but thanks very much, it works now...

Nick
 
Old June 5th, 2003, 09:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If txtCompanyContact contains a NULL value, then you can't compare it to a zero-length-string: "" and still return True. Imar is doing an implicit conversion of the NULL value to a zero-length-string by appending a ZLS to the possible NULL value. Then when you compare it to another ZLS, you will get True.
 
Old June 6th, 2003, 01:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Ken,

Good to "see" you again. It's been quite some time.....

Thanks for taking care of the explanation.

Cheers,

Imar
 
Old June 6th, 2003, 10:26 AM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

you guys rock, thanks!

Nick





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with simple JOIN statement zoltac007 SQL Server ASP 1 May 31st, 2007 10:09 AM
Simple Question - SQL Statement mrideout BOOK: Beginning ASP.NET 1.0 2 January 11th, 2005 09:28 AM
simple but not working! Adam H-W Classic ASP Basics 1 March 5th, 2004 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.