Solved

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

Posted on 2004-08-26
3
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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 …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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