Link to home
Start Free TrialLog in
Avatar of jodyglidden
jodyglidden

asked on

Syntax error about imports having to precede declarations

I have the following code that is giving me an error:

Imports statements must precede declarations.  My imports is before my declarations.  Any idea what I'm doing wrong?

<%@ Page Language="VB" %>
<script runat="server">

    Imports Microsoft.Win32
    dim Accountskey as registrykey
    Accountskey = Registry.CurrentUser.OpenSubKey("Software\VB and VBA Program Settings\Mailgov (Redirector)\AccountSettings", 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 Arthur_Wood
Arthur_Wood
Flag of United States of America image

why are you writing the VB.NET code in your aspx page,and not using the CodeBehind.  The problem is that the code as you have it here, is actually being seen, by the JIT compiler, as if it were following the implied declarations of the controls on your page, and that is sees as creasting the 'error' that you are seeing.

ASP.NET does NOT support coding as you have it here, which is the older ASP style, using embedded VBScript.  In fact, you cannot embed VBScript in the ASPX page, in any fashion.  

ASP.NET is a completely DIFFERENT style of web development, and you would be VERY wise to TOTALLY FORGET (yes FORGET) everything your ever knew (or thought you knew) about ASP development, becuase it has ABSOLUTELY no relevance to ASP.NET development.  The two are as different as Night and Day - actually they are more different - say like Cats and Airplanes.

AW
ASKER CERTIFIED SOLUTION
Avatar of Timbo87
Timbo87

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
Avatar of jodyglidden
jodyglidden

ASKER

That's what I've read as well.  Also, Timbo fixed my bug.  Thanks.