• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1079
  • Last Modified:

Can't define variable as public

I am using ASP.net. At the top of my page I have
<%
    Dim x As Integer
x = 0
%>

and later down I have:
                            <asp:Repeater ID="rptrInventory" runat="server">
                                                            <ItemTemplate>
<%
if x = 6 or x = 0 Then
Response.Write("<tr>")
x = 1
End if
x = x + 1
%>

When I run it I get this error: Compiler Error Message: BC30451: Name 'x' is not declared.

If I change Dim x to Public x, I get the error: Compiler Error Message: BC30247: 'Public' is not valid on a local variable declaration.

Any ideas?
0
JonMarkGo
Asked:
JonMarkGo
  • 3
  • 3
1 Solution
 
thirdCommented:
declare it public on your codebehind.
0
 
JonMarkGoAuthor Commented:
I don't have access to my codebehind... Is there any way to make it public only to this script?
0
 
thirdCommented:
try this instead

<script  runat="server">
    Dim x As Integer = 0
</script>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
JonMarkGoAuthor Commented:
No luck... Where would  the codebehind file be in a normal script?
0
 
thirdCommented:
I just tried below and it works. what error message came out?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<script  runat="server">
    Dim x As Integer = 0
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%
if x = 6 or x = 0 Then
Response.Write("<tr>")
x = 1
End if
x = x + 1
%>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
JonMarkGoAuthor Commented:
Nevermind, the reason it didn't work was a different bug. Thanks!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now