Solved

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

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

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

Title # Comments Views Activity
website template 12 344
Create recordset using Dreamweaver PHP and MS SQL 2008 4 560
Dreamweaver CS6 with WordPress 9 119
CC Dreamweaver Regular Expression Problem 14 19
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

820 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