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

x
?
Solved

Syntax error about imports having to precede declarations

Posted on 2004-10-29
3
Medium Priority
?
263 Views
Last Modified: 2008-12-18
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>
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
3 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12449738
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
0
 
LVL 15

Accepted Solution

by:
Timbo87 earned 2000 total points
ID: 12449899
Importing namespaces is possible even when using interspersed ASP.NET code.

Add this under your @Page directive.
<% @Import Namespace="Microsoft.Win32" %>

Arthur,

As far as I know, there is nothing code-behind can do that embedded code cannot do. I use code-behind myself, but embedded code is just as powerful.
0
 
LVL 1

Author Comment

by:jodyglidden
ID: 12450912
That's what I've read as well.  Also, Timbo fixed my bug.  Thanks.
0

Featured Post

Industry Leaders: 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

610 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