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?
LVL 2
JonMarkGoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.