Syntax error Declaration Expected

Anyone see why I'm getting the declaration expected error?

<%@ Page Language="VB" %>
<%@ import Namespace="Microsoft.Win32" %>
<script runat="server">

    dim Accountskey as RegistryKey

right here-->    Accountskey = Registry.CurrentUser.OpenSubKey("Software", False)

        for each strAccount in Accountskey.getvaluenames()
            strAccounts = strAccounts & strAccount
        next
        Label1.text = strAccounts

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        Done
        <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        <asp:Label id="Label1" runat="server">Label</asp:Label>
        <!-- Insert content here -->
    </form>
</body>
</html>
LVL 1
jodygliddenAsked:
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.

nauman_ahmedCommented:
It looks fine to me, as this is the way described in MSDN:

Private Sub DoesKeyExist
    Dim regVersion As Microsoft.Win32.RegistryKey
    regVersion = _
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\TestApp\\1.0", True)
    If regVersion Is Nothing Then
        regVersion = _
Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\TestApp\\1.0")
    End If
End Sub

Also, here you are trying to acces the registry on the server. Does user has permission to access the registry? Here are some links that might be helpful:

http://msdn.microsoft.com/library/en-us/dnnetsec/html/SecNetHT11.asp
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2874&lngWId=10

Best, Nauman.
0
ryerrasCommented:
I am not sure why u r getting the error over there, your error should be in the following for loop

for each strAccount in Accountskey.getvaluenames()
            strAccounts = strAccounts & strAccount
        next
        Label1.text = strAccounts

If you you have not declared neither strAccount or strAccounts

you did not seem to declare them as strings prior to using them. thats all the syntax errors i can see
0
mmarinovCommented:
Hi jodyglidden,

ryerras is correct - the problem is with strAccount and strAccounts, not with the OpenSubKey method

Regards!
B..M
0
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.

jodygliddenAuthor Commented:
Even if I add the strAccount and strAccounts Dim statements I am still getting a Declaration error for the statement mentioned above.
0
ryerrasCommented:
hmm ok. its because, you put the inline code between the script tags.

When you use the <script runat="server"></script> tags to define a block of code, essentially ASP.NET inlines everything between the blocks directly into the body of the class that is generated for the page.  In other words, you can define variables for the class, and routines or functions for a class, but you cannot directly include source code inside a <script> tag.

However, if you use the <% %> tags to isolate your code blocks, ASP.NET essentially creates a new function that is executed at that point in the document cycle.  All of the inner text of this block is dumped into the internals of the function, which means that you can use source code or definitions or whatever else you want inside of this tag, and you won't get an error.  I say that it essentially creates a function because it doesn't really, variables that are defined inside a <% %> block are scoped for the entire page, so that any code running in the page can access them.  This is different than if you were creating real functions

So your code should be



<%@ Page Language="VB" %>
<%@ import Namespace="Microsoft.Win32" %>
<script runat="server">
Public Sub ReadFromRegistry
    dim Accountskey as RegistryKey
  //---------- new declarations
    dim strAccount as string
    dim strAccounts as string
   Accountskey = Registry.CurrentUser.OpenSubKey("Software", False)

        for each strAccount in Accountskey.getvaluenames()
            strAccounts = strAccounts & strAccount
        next
        Label1.text = strAccounts
End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        Done
        <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        <asp:Label id="Label1" runat="server">Label</asp:Label>
        <!-- Insert content here -->
    </form>
</body>
</html>

This should compile and work for you
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
jodygliddenAuthor Commented:
Yes, that worked.  I just changed the sub name to Page_Load
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.