Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Syntax error Declaration Expected

Posted on 2004-10-30
6
Medium Priority
?
578 Views
Last Modified: 2010-05-18
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>
0
Comment
Question by:jodyglidden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12450984
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
 
LVL 6

Expert Comment

by:ryerras
ID: 12451755
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12453595
Hi jodyglidden,

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

Regards!
B..M
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jodyglidden
ID: 12453833
Even if I add the strAccount and strAccounts Dim statements I am still getting a Declaration error for the statement mentioned above.
0
 
LVL 6

Accepted Solution

by:
ryerras earned 2000 total points
ID: 12453903
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
 
LVL 1

Author Comment

by:jodyglidden
ID: 12464834
Yes, that worked.  I just changed the sub name to Page_Load
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question