Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Databases
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 5th, 2003, 12:38 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old June 5th, 2003, 02:44 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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...
Reply With Quote
  #3 (permalink)  
Old June 5th, 2003, 06:12 PM
Imar's Avatar
Wrox Author
Points: 67,575, Level: 100
Points: 67,575, Level: 100 Points: 67,575, Level: 100 Points: 67,575, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,267
Thanks: 66
Thanked 1,428 Times in 1,408 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
Reply With Quote
  #4 (permalink)  
Old June 5th, 2003, 07:51 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #5 (permalink)  
Old June 5th, 2003, 10:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
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.
Reply With Quote
  #6 (permalink)  
Old June 6th, 2003, 02:59 AM
Imar's Avatar
Wrox Author
Points: 67,575, Level: 100
Points: 67,575, Level: 100 Points: 67,575, Level: 100 Points: 67,575, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,267
Thanks: 66
Thanked 1,428 Times in 1,408 Posts
Default

Hi Ken,

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

Thanks for taking care of the explanation.

Cheers,

Imar
Reply With Quote
  #7 (permalink)  
Old June 6th, 2003, 11:26 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

you guys rock, thanks!

Nick
Reply With Quote
Reply


Thread Tools
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with simple JOIN statement zoltac007 SQL Server ASP 1 May 31st, 2007 11: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



All times are GMT -4. The time now is 02:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.