Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: I am pulling my hair out on this line of code....


Message #1 by "Richard Waterman" <Richard@R...> on Wed, 27 Mar 2002 17:23:38
I have confirmed that the variables have the proper values but for some 
reason, the If statement I want to use will not equate to true
Please scroll down to this line:
"if (rsMenu("MenuMainID") = 1) then"  this line works but I really want 
the 1 to be variable MenuMainID so that its: 
"if (rsMenu("MenuMainID") = MenuMainID) then"

I've tried adding .value to rsMenu("MenuMainID") but that doesn't help.  

<% Dim SQL, MyConn, rsMenu,rsMenuSub,i
   dim MenuMainID
   MenuMainID=1
set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "connSiteAccess"

SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
SQL=SQL+"and MenuUrl = UrlLink "
SQL=SQL+"and MenuMainSub <> 'sub'"
Set rsMenu = MyConn.Execute(SQL)

SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
SQL=SQL+"and MenuUrl = UrlLink "
SQL=SQL+"and MenuMainSub = 'sub' "
if (Request.QueryString("MenuMainID") <> "") then MenuMainID = 
Request.QueryString("MenuMainID")
SQL=SQL+"and MenuMainID = "+ Replace(MenuMainID, "'", "''")
Set rsMenuSub = MyConn.Execute(SQL)

%>
<html>
<head>
<title>List Menu</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="16%" border="0">
 
 
<% if not rsMenu.eof then
  while NOT rsMenu.EOF %>
         <tr>
    <td><%=rsMenu("MenuText")%></td>
  </tr> 
      <%' not rsMenuSub.eof and
	   'Whats wrong with this line??????
           'I know MenuMainID gets set to 1 but and
	   'rsMenu("MenuMainID") will be 1
	   'If I try using this line
           ' "if rsMenu("MenuMainID") = MenuMainID then"
	   'the statement wont equate to true.
	   'Unless I manually type in 1 like in if statement below.
	    if (rsMenu("MenuMainID") = 1) then
		  
         while NOT rsMenuSub.EOF %>
        <tr>
        <td><%=rsMenuSub("MenuText")%></td>
         </tr>
		 <% rsMenuSub.MoveNext
		    wend 
			End if '%> 
  <% rsMenu.MoveNext
 WEND
 else
   response.write "<Center>NO RECORDS FOUND</center>"
 end if %>
</table>
</body>
</html>
Message #2 by "Richard Waterman" <Richard@R...> on Wed, 27 Mar 2002 19:02:04
Well I kind of answered my own question.  I got it to work anyway but 
dont fully understand why code wouldnt work the way I planed...
What got it to work was to change the Type on both variables.  I used 
this line and it worked:
"if cint((rsMenu("MenuMainID")) = cint(MenuMainID)) then"

Well I might do some checking to see what Type vbscript had orginally of 
my (rsMenu("MenuMainID"), and MenuMainID variables, but I need a break. 

If someone still has pointers on this I would appreciate hearing them.

> I have confirmed that the variables have the proper values but for some 
r> eason, the If statement I want to use will not equate to true
P> lease scroll down to this line:
"> if (rsMenu("MenuMainID") = 1) then"  this line works but I really want 
t> he 1 to be variable MenuMainID so that its: 
"> if (rsMenu("MenuMainID") = MenuMainID) then"

> I've tried adding .value to rsMenu("MenuMainID") but that doesn't 
help.  

> <% Dim SQL, MyConn, rsMenu,rsMenuSub,i
 >   dim MenuMainID
 >   MenuMainID=1
s> et MyConn=Server.CreateObject("ADODB.Connection")
M> yConn.Open "connSiteAccess"

> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
S> QL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
S> QL=SQL+"and MenuUrl = UrlLink "
S> QL=SQL+"and MenuMainSub <> 'sub'"
S> et rsMenu = MyConn.Execute(SQL)

> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
S> QL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
S> QL=SQL+"and MenuUrl = UrlLink "
S> QL=SQL+"and MenuMainSub = 'sub' "
i> f (Request.QueryString("MenuMainID") <> "") then MenuMainID = 
R> equest.QueryString("MenuMainID")
S> QL=SQL+"and MenuMainID = "+ Replace(MenuMainID, "'", "''")
S> et rsMenuSub = MyConn.Execute(SQL)

> %>
<> html>
<> head>
<> title>List Menu</title>
<> meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<> /head>

> <body bgcolor="#FFFFFF" text="#000000">
<> table width="16%" border="0">
 > 
 > 
<> % if not rsMenu.eof then
 >  while NOT rsMenu.EOF %>
 >         <tr>
 >    <td><%=rsMenu("MenuText")%></td>
 >  </tr> 
 >      <%' not rsMenuSub.eof and
	>    'Whats wrong with this line??????
 >           'I know MenuMainID gets set to 1 but and
	>    'rsMenu("MenuMainID") will be 1
	>    'If I try using this line
 >           ' "if rsMenu("MenuMainID") = MenuMainID then"
	>    'the statement wont equate to true.
	>    'Unless I manually type in 1 like in if statement below.
	>     if (rsMenu("MenuMainID") = 1) then
	> 	  
 >         while NOT rsMenuSub.EOF %>
 >        <tr>
 >        <td><%=rsMenuSub("MenuText")%></td>
 >         </tr>
	> 	 <% rsMenuSub.MoveNext
	> 	    wend 
	> 		End if '%> 
 >  <% rsMenu.MoveNext
 > WEND
 > else
 >   response.write "<Center>NO RECORDS FOUND</center>"
 > end if %>
<> /table>
<> /body>
<> /html>
Message #3 by "Jose Bueno" <jbueno@i...> on Wed, 27 Mar 2002 22:05:37
ROTFLMAO!!!  Are we living parallel lives, or what?  I had the same 
problem yesterday, basically 1 * 1 != 1 (intx * sngy != intx) 

:D

-Jose
Message #4 by Abdul Sami <abdul_sami_20@y...> on Wed, 27 Mar 2002 14:32:18 -0800 (PST)
Check out with the help of response.write statement what output
are you getting (for which you have applied condition), is it 1
or something else.
Also check the datatype of menuid and check it with interger
value

--- Richard Waterman <Richard@R...> wrote:
> I have confirmed that the variables have the proper values but
> for some 
> reason, the If statement I want to use will not equate to true
> Please scroll down to this line:
> "if (rsMenu("MenuMainID") = 1) then"  this line works but I
> really want 
> the 1 to be variable MenuMainID so that its: 
> "if (rsMenu("MenuMainID") = MenuMainID) then"
> 
> I've tried adding .value to rsMenu("MenuMainID") but that
> doesn't help.  
> 
> <% Dim SQL, MyConn, rsMenu,rsMenuSub,i
>    dim MenuMainID
>    MenuMainID=1
> set MyConn=Server.CreateObject("ADODB.Connection")
> MyConn.Open "connSiteAccess"
> 
> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
> SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
> SQL=SQL+"and MenuUrl = UrlLink "
> SQL=SQL+"and MenuMainSub <> 'sub'"
> Set rsMenu = MyConn.Execute(SQL)
> 
> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
> SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
> SQL=SQL+"and MenuUrl = UrlLink "
> SQL=SQL+"and MenuMainSub = 'sub' "
> if (Request.QueryString("MenuMainID") <> "") then MenuMainID = 
> Request.QueryString("MenuMainID")
> SQL=SQL+"and MenuMainID = "+ Replace(MenuMainID, "'", "''")
> Set rsMenuSub = MyConn.Execute(SQL)
> 
> %>
> <html>
> <head>
> <title>List Menu</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> </head>
> 
> <body bgcolor="#FFFFFF" text="#000000">
> <table width="16%" border="0">
>  
>  
> <% if not rsMenu.eof then
>   while NOT rsMenu.EOF %>
>          <tr>
>     <td><%=rsMenu("MenuText")%></td>
>   </tr> 
>       <%' not rsMenuSub.eof and
> 	   'Whats wrong with this line??????
>            'I know MenuMainID gets set to 1 but and
> 	   'rsMenu("MenuMainID") will be 1
> 	   'If I try using this line
>            ' "if rsMenu("MenuMainID") = MenuMainID then"
> 	   'the statement wont equate to true.
> 	   'Unless I manually type in 1 like in if statement below.
> 	    if (rsMenu("MenuMainID") = 1) then
> 		  
>          while NOT rsMenuSub.EOF %>
>         <tr>
>         <td><%=rsMenuSub("MenuText")%></td>
>          </tr>
> 		 <% rsMenuSub.MoveNext
> 		    wend 
> 			End if '%> 
>   <% rsMenu.MoveNext
>  WEND
>  else
>    response.write "<Center>NO RECORDS FOUND</center>"
>  end if %>
> </table>
> </body>
> </html>


=====
Abdul Sami

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/
Message #5 by "Richard Waterman" <Richard@R...> on Thu, 28 Mar 2002 00:46:21
Yes I had done the response.writes already thats why I new what was 1 and 
not.  Thats why I was pulling out hair.
Response.write rsMenu("MenuMainID") displayed 1
Response.write MenuMainID Displayed 1. 
I could not figure out why the 1 would not equal the other 1. But after 
looking at the Forum, I tried data type conversion. rsMenu("MenuMainID") 
is a Number is the Access table so I figured it would be ok but obviously 
vbscript was picky about it.  I do plan to see what type vbscript had 
them as maybe it help me in future programs.

> Check out with the help of response.write statement what output
are you getting (for which you have applied condition), is it 1
or something else.
Also check the datatype of menuid and check it with interger
value

--- Richard Waterman <Richard@R...> wrote:
> I have confirmed that the variables have the proper values but
> for some 
> reason, the If statement I want to use will not equate to true
> Please scroll down to this line:
> "if (rsMenu("MenuMainID") = 1) then"  this line works but I
> really want 
> the 1 to be variable MenuMainID so that its: 
> "if (rsMenu("MenuMainID") = MenuMainID) then"
> 
> I've tried adding .value to rsMenu("MenuMainID") but that
> doesn't help.  
> 
> <% Dim SQL, MyConn, rsMenu,rsMenuSub,i
>    dim MenuMainID
>    MenuMainID=1
> set MyConn=Server.CreateObject("ADODB.Connection")
> MyConn.Open "connSiteAccess"
> 
> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
> SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
> SQL=SQL+"and MenuUrl = UrlLink "
> SQL=SQL+"and MenuMainSub <> 'sub'"
> Set rsMenu = MyConn.Execute(SQL)
> 
> SQL="SELECT * FROM Menu, MenuItems, UrlInfo "
> SQL=SQL+"Where Menu.MenuID = MenuItems.MenuID "
> SQL=SQL+"and MenuUrl = UrlLink "
> SQL=SQL+"and MenuMainSub = 'sub' "
> if (Request.QueryString("MenuMainID") <> "") then MenuMainID = 
> Request.QueryString("MenuMainID")
> SQL=SQL+"and MenuMainID = "+ Replace(MenuMainID, "'", "''")
> Set rsMenuSub = MyConn.Execute(SQL)
> 
> %>
> <html>
> <head>
> <title>List Menu</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> </head>
> 
> <body bgcolor="#FFFFFF" text="#000000">
> <table width="16%" border="0">
>  
>  
> <% if not rsMenu.eof then
>   while NOT rsMenu.EOF %>
>          <tr>
>     <td><%=rsMenu("MenuText")%></td>
>   </tr> 
>       <%' not rsMenuSub.eof and
> 	   'Whats wrong with this line??????
>            'I know MenuMainID gets set to 1 but and
> 	   'rsMenu("MenuMainID") will be 1
> 	   'If I try using this line
>            ' "if rsMenu("MenuMainID") = MenuMainID then"
> 	   'the statement wont equate to true.
> 	   'Unless I manually type in 1 like in if statement below.
> 	    if (rsMenu("MenuMainID") = 1) then
> 		  
>          while NOT rsMenuSub.EOF %>
>         <tr>
>         <td><%=rsMenuSub("MenuText")%></td>
>          </tr>
> 		 <% rsMenuSub.MoveNext
> 		    wend 
> 			End if '%> 
>   <% rsMenu.MoveNext
>  WEND
>  else
>    response.write "<Center>NO RECORDS FOUND</center>"
>  end if %>
> </table>
> </body>
> </html>


=====
Abdul Sami

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/

  Return to Index