Solved

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

Posted on 2004-08-26
3
154 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

23 Experts available now in Live!

Get 1:1 Help Now