Solved

My code not as fancy as DW; should I be worried?

Posted on 2004-08-26
3
155 Views
Last Modified: 2010-04-25
I gave up on try to get DW to write a decent dynamic menu for me, so I rewrote it myself. I want the SELECTED field to be what ever is in the database. But if there isn't anything, then just use the label "Choose Research Category"

So I came up with this:

<% if (rsFacultyProfile.Fields.Item("tblResearchCat.researchCategory")) = ""  then %>
<option selected>Choose Research Category</option>
<%else%>
<option value="<% =(rsFacultyProfile.Fields.Item("tblUsers.researchCategory"))%>"><%=(rsFacultyProfile.Fields.Item("tblResearchCat.researchCategory"))%></option>
<% end if %>

And it works perfectly. However, I look at DW's code and it is full of isNull and CStr and other things I've never used.

So I am running my code by you.

Two questions:

Instead of setting the if statement to  =""   should I ask about its null status? (If so, why would that be preferable?)

And can someone please tell me what exactly is the purpose CStr and why does DW use it so much?

Newbie here. Please don't fly over my head. thanks.

I left the rest of code as DW wrote it:

<%
While (NOT rsResearchCat.EOF)
%>
<option value="<%=(rsResearchCat.Fields.Item("resCatID").Value)%>" <%If (Not isNull((rsFacultyProfile.Fields.Item("tblResearchCat.researchCategory").Value))) Then If (CStr(rsResearchCat.Fields.Item("resCatID").Value) = CStr((rsFacultyProfile.Fields.Item("tblResearchCat.researchCategory").Value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsResearchCat.Fields.Item("researchCategory").Value)%></option>
<%
  rsResearchCat.MoveNext()
Wend
If (rsResearchCat.CursorType > 0) Then
  rsResearchCat.MoveFirst
Else
  rsResearchCat.Requery
End If
%>
</select>
</p>
0
Comment
Question by:polaatx
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
prifre earned 250 total points
ID: 11919612
Hi,

DW writes "fancy" code, since DW have to adjust to anything the user puts into the database. That code of DW works with all kind of fields. "CStr" ("Convert to STRing") would convert even fields with numbers, dates, etc into strings (text) and make it work. But you don't need to program that way, since you created the database and know what is in there.

The same goes for IsNul. When I started learning ASP/VB (I still dont know much...) I looked at DW code and than I also changed to what I liked better. I nowdays use W3WSchools a lot. Their documentation is good. On IsNull they write:
http://www.w3schools.com/vbscript/func_isnull.asp

So IsNull means "No valid data", but "" means empty. Almost the same...

(I personally would probably use more "Response.Write" and less "<%" and "%>"... but that is my own "coding style".)

with a smile
/prifre
0
 

Author Comment

by:polaatx
ID: 11920699
Thanks pritre. Is there a particular reason you prefer response.write more? Just style or does it actually make your code better?
0
 
LVL 9

Expert Comment

by:prifre
ID: 11920996
Well, I like my code readable and if I mix in a lot of % I have much worse overview. Then some parts are "HTML" and others are ASP. Practically - if you feel you have control - the code is good enough.

Regarding your question - "worried?" On the contrary. If you can write your own code, that does what you want, you are far better off than if you just use DW.

So don't worry - be happy!
/prifre
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Issue when emailing and there is a space 7 387
COLDFUSION 9 DEVELOPMENT SERVER STOPPED WORKING 9 443
Webpage Not Working in IE 27 354
Easy way to swap image out on page load 8 174
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now