Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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