Results 1 to 5 of 5

Thread: String Declare Error

  1. #1

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446

    String Declare Error

    I have Simple Problem with Declaring Variables. This is my Program.
    Code:
    <%@ Page Language="VB" %>
    <script runat="server">
      Dim stm as String
      stm="prasad"
    
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
       </form>
    </body>
    </html>
    I got the Following Error
    Code:
    Compiler Error Message: BC30188: Declaration expected.
    Source Error:
    Line 2:  <script runat="server">
    Line 3:  Dim stm as String
    Line 4:  stm="prasad"
    prasad

  2. #2
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Have you tried placing the code in a routine?

    Private Sub setString()

    Dim stm as String
    stm="prasad"

    End sub

  3. #3

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446
    It is working fine. But
    why should Declare the Variable inside the Sub procedure?

    any reason..? here the in between of <Server> </server> is Code block only so why not we assign the value over there.?
    prasad

  4. #4
    New Member
    Join Date
    Sep 2002
    Posts
    1

    Thumbs up

    Hi Buddu,

    Its simple. Just try to place your code, i mean variable assignment should be inside subroutine.You can't assign a variable outside subroutine.
    Have a nice day!

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Dim stm as String
    stm="prasad"

    wont work outside a procedure.

    Dim stm as String = "prasad"

    will work
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width