Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2004, 01:01 PM
Registered User
 
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jackel23 Send a message via MSN to jackel23 Send a message via Yahoo to jackel23
Default Stupid Question

[font=Arial ]
I am creating a checkbox list to display some information. When I test the page it gives me this error.
Sub or Function not defined
I'm not sure why so I'm hoping you can tell me. here is the code.
<%sdpmdh = ""%><%sdpmdh2 = ""%><%sdpmdh3 = ""%>
<% If orecord("DPMD_hardware") Like "%~cpu1~%" Then sdpmdh = "checked" End If %>
<% If orecord("DPMD_hardware") Like "%~cpu2~%" Then sdpmdh2 = "checked" End If%>
<% If orecord("DPMD_hardware") Like "%~cpu3~%" Then sdpmdh3 = "checked" End If%>
        <td align=right width="53%">
[size=2]<strong>DPMD Hardware</strong> [size=2]CPU

<input type="checkbox" name="DPMDh1" value="~CPU1" <%=sdpmdh%>>
<input type="checkbox" name="DPMDh12" value="~CPU2" <%=sdpmdh2%>>
<input name="DPMDh13" type="checkbox" value="~CPU3" <%=sdpmdh3%>>
[/font=Arial]

¤¤¤¤¤¤¤¤¤¤¤¤
Jackel23
¤¤¤¤¤¤¤¤¤¤¤¤
 
Old February 19th, 2004, 01:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

"Like" is not a VBScript keyword or function. You should be able to use InStr to look for the "cpuX" string.

If InStr(orecord("DPMD_hardware"), "~cpu1~") > 0 Then...

You don't need to have all those pairs of <% %>. Every one slows down the page a bit. If you have many lines of script, just wrap them all in one pair.

<%
sdpmdh = ""
sdpmdh2 = ""
sdpmdh3 = ""
If InStr(orecord("DPMD_hardware"), "~cpu1~") > 0 Then sdpmdh = "checked" End If
If InStr(orecord("DPMD_hardware"), "~cpu2~") > 0 Then sdpmdh2 = "checked" End If
If InStr(orecord("DPMD_hardware"), "~cpu3~") > 0 Then sdpmdh3 = "checked" End If
%>

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 19th, 2004, 01:42 PM
Registered User
 
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jackel23 Send a message via MSN to jackel23 Send a message via Yahoo to jackel23
Default

That's what I thought but I couldn't find any rule that showed proof of what VBscript could use. Thanks for the % advice too.

¤¤¤¤¤¤¤¤¤¤¤¤
Jackel23
¤¤¤¤¤¤¤¤¤¤¤¤
 
Old February 20th, 2004, 11:17 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is "%~cpu1~%" a string literal or is it a variable? Is the tilde (~) really part of the string? Maybe you could just post your code cause now I'm curious. :-)

 
Old February 20th, 2004, 11:32 AM
Registered User
 
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jackel23 Send a message via MSN to jackel23 Send a message via Yahoo to jackel23
Default

Your right I couldn't post my code. It was the variable to look for in the string. the odd thing is the access DB accepted it directly so viewing the info worked ok but saving it did not. I took out the ~ and used no seperation character. It didn't want to save then either. I insured the fields in question are text based and they are but it will only accept numbers. I'm working around this problem by making the input numerical. The save page as far as I could see doesn't have anything requiring a number for that input. I'm starting to babble here so long story short I'm working around it but I would like to know what it mean when this pops up.
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.


¤¤¤¤¤¤¤¤¤¤¤¤
Jackel23
¤¤¤¤¤¤¤¤¤¤¤¤
 
Old February 20th, 2004, 01:17 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this

<%
sdpmdh = ""
sdpmdh2 = ""
sdpmdh3 = ""
If orecord("DPMD_hardware") Like '%" & cpu1 & "%' Then sdpmdh = "checked" End If
If orecord("DPMD_hardware") Like '%" & cpu2 & "%' Then sdpmdh2 = "checked" End If
If orecord("DPMD_hardware") Like '%" & cpu3 & "%' Then sdpmdh3 = "checked" End If
%>

Alternatively, this should work or be pretty close...

<%
sdpmdh = ""
sdpmdh2 = ""
sdpmdh3 = ""
If InStr(orecord("DPMD_hardware"),cpu1) > 0 Then sdpmdh = "checked" End If
If InStr(orecord("DPMD_hardware"),cpu2) > 0 Then sdpmdh2 = "checked" End If
If InStr(orecord("DPMD_hardware"),cpu3) > 0 Then sdpmdh3 = "checked" End If
%>

 
Old February 20th, 2004, 01:29 PM
Registered User
 
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jackel23 Send a message via MSN to jackel23 Send a message via Yahoo to jackel23
Default

I am continuing with the InStr code just so I can expand my coding vocabulary. One thing I wanted to know is why is the >0 there?
If InStr(orecord("DPMD_hardware"),cpu1) > 0 Then sdpmdh = "checked" End If

¤¤¤¤¤¤¤¤¤¤¤¤
Jackel23
¤¤¤¤¤¤¤¤¤¤¤¤
 
Old February 20th, 2004, 01:40 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

InStr returns an integer indicating where the string starts, 0 means it was not found. It is used incorrectly as returning a Boolean but this is because VB(Script) will interpret 0 to be false and all positive integers to be true.

--

Joe
 
Old February 23rd, 2004, 10:41 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Personally I'd go with the LIKE statement. Something tells me that 'inStr' is not always supported in MsSql, but it is in VbScript or ASP. Not totally sure about that, but I've had problems with it and had to use 'CharIndex' for performing an inStr search. Could have been for a specific data type or something. However, the LIKE statement should be supported in both and that kinda comes in handy when troubleshooting.

 
Old February 24th, 2004, 12:31 PM
Registered User
 
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jackel23 Send a message via MSN to jackel23 Send a message via Yahoo to jackel23
Default

I'd have to agree. I'm learning ASP under fire though so I haven't been able to realy learn the language. I'm actually taking someone elses site and reworking it to be more purposeful. If you don't mind a second dumb question I'm not able to get my javascript that I picked up from javascript.com to work in an ASP page. I'm just wondering if there is anything needed to show what script is being used other then <Script> tag.

¤¤¤¤¤¤¤¤¤¤¤¤
Jackel23
¤¤¤¤¤¤¤¤¤¤¤¤





Similar Threads
Thread Thread Starter Forum Replies Last Post
stupid question... seymour_glass C# 3 May 2nd, 2007 06:40 AM
Probably stupid question skiloff BOOK: ASP.NET Website Programming Problem-Design-Solution 0 July 6th, 2005 02:44 PM
stupid question j_pres44 Beginning PHP 4 December 13th, 2004 05:06 AM
stupid question Warbird General .NET 6 December 7th, 2004 09:33 AM
A really stupid question Phaedrus VB.NET 2002/2003 Basics 3 October 29th, 2003 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.