Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close space between lines

Status
Not open for further replies.

meltingpot

Technical User
May 11, 2004
118
GB
The code below writes a name and address but I have a problem with the spaces. As an example If the field "Add3" is missing it leaves a space on the page. How do I make the lines close up if a field is empty ???


Code =======================
<td width="366"><%=(Course_accepted.Fields.Item("Unit").Value)%><br>
<%=(Course_accepted.Fields.Item("Add1").Value)%><br>
<%=(Course_accepted.Fields.Item("Add2").Value)%><br>
<%=(Course_accepted.Fields.Item("Add3").Value)%><br>
<%=(Course_accepted.Fields.Item("add4").Value)%><br>
<%=(Course_accepted.Fields.Item("County").Value)%><br>
<%=(Course_accepted.Fields.Item("postcode").Value)%><br>
<br></td>

Help !
 
something like this:

Code:
if (Course_accepted.Fields.Item("Unit").Value)&""<>"" then
then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if
and so on...continue the same pattern

-DNG
 
Hi DotNetGnat, so would it look like this for example... im new to this and my syntax is bad

<td width="366">
<%
if (Course_accepted.Fields.Item("Unit").Value)&""<>"" then
then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if
%>
<%
if (Course_accepted.Fields.Item("Add1").Value)&""<>"" then
then
Response.write Course_accepted.Fields.Item("Add1").Value & "<br>"
end if
%>

</td>
:)
 
Code:
<% If Len(Course_accepted.Fields.Item("Add3").Value) Then
      Response.Write( Course_accepted.Fields.Item("Add3").Value & "<br>" )
   End If
%>
 
yep that would work...

Code:
<td width="366">
<% 
if (Course_accepted.Fields.Item("Unit").Value)&""<>"" then
then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if 
if (Course_accepted.Fields.Item("Add1").Value)&""<>"" then
then
Response.write Course_accepted.Fields.Item("Add1").Value & "<br>"
end if 
%>
</td>

-DNG
 
What does the 'Len' do at the start of the line ?
 
oops..."then" is repeated twice...i had it wrong in my post...

please understand the code before using it...

-DNG
 
Using the following and not having much luck get a browser error

Code -------------
<%
if (Course_accepted.Fields.Item("Unit").Value)&""<>""
then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if
if (Course_accepted.Fields.Item("Add1").Value)&""<>""
then
Response.write Course_accepted.Fields.Item("Add1").Value & "<br>"
end if
%>

Error ========
.."courses/c_app/letters/letter_ALL_accepted.asp, line 401, column 53
if (Course_accepted.Fields.Item("Unit").Value)&""<>""
 
meltingpot, use the syntax that rac2 provided above.

DotNetGnat, did you mean to write this (otherwise, your code does not appear to make any sense):
Code:
<% 
if (Course_accepted.Fields.Item("Unit").Value)<> "" 
then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if 
if (Course_accepted.Fields.Item("Add1").Value)<> "" 
then
Response.write Course_accepted.Fields.Item("Add1").Value & "<br>"
end if 
%>

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
chopstik, i meant what i wrote:

Code:
<td width="366">
<% 
if (Course_accepted.Fields.Item("Unit").Value)&""<>"" then
Response.write Course_accepted.Fields.Item("Unit").Value & "<br>"
end if 
if (Course_accepted.Fields.Item("Add1").Value)&""<>"" then
Response.write Course_accepted.Fields.Item("Add1").Value & "<br>"
end if 
%>
</td>

-DNG
 
Thanks every one, I used the final thread from DotNetGnat. Workd great .. ive learnt something today ...
Thanks from the South of England
 
Well, my apologies if it worked. Sorry for any confusion.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
By concatenating the field value from the recordset with an empty string you are essentially forcing the value to be a string if it was null. Then you check to make sure it isn't an empty string. What this gets you is a cheap two-fer, you can check if the value is null or an empty string in one conditional statement.

-T

 
Thanks for that explanation, Tarwn.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Ahh, I see. I think it's the syntax that confused me. I would have expected to see the appended string written inside the brackets. e.g.
Code:
if (Course_accepted.Fields.Item("Unit").Value & "") <> "" then


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Oops...didnt get time to check back this thread...any ways..

No problem Chopstik. I have learned this trick on this forums. I guess its a deprecated way to check if a recordset value is null or empty string...

Thanks for explaining it Trawn.

-DNG

 
I can't stay quiet and would like to stick MHO out there. This to me is a hack and a bad one. I recall seeing someone do this years ago (in here) and I argued it was bad form then also. It does do the comparison but it does it in a cryptic manner in which will undoubtedly be hard to maintain and make your code just not formed well.

There is a reason you cannot force this type of inequality/equality in languages such as C#, Java etc... At least I can't

This rates up there with a line like this
Code:
if str = "" then : response.write("empty") : else : response.write("not emtpy") : end if

Which only makes it hard to read and maintain

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Man, this is a huge thread for a simple task, I just said this to add to the size of the thread.

[monkey][snake] <.
 
[lol]

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top