Link to home
Start Free TrialLog in
Avatar of jodyglidden
jodyglidden

asked on

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>
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

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.
Avatar of ryerras
ryerras

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
Hi jodyglidden,

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

Regards!
B..M
Avatar of jodyglidden

ASKER

Even if I add the strAccount and strAccounts Dim statements I am still getting a Declaration error for the statement mentioned above.
ASKER CERTIFIED SOLUTION
Avatar of ryerras
ryerras

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, that worked.  I just changed the sub name to Page_Load