Newb If Syntax: End of statement expected.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Newb If Syntax: End of statement expected.

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    5

    Newb If Syntax: End of statement expected.

    All,

    Just trying to figure out some ASP on the fly and I am stumped. I am not entirely sure if this is .Net ASP or not, but figured this is a good place to start.

    I am simply trying to fix a form input problem where a certain TextBox that usually contains integers can sometimes be empty. If empty, I would like to have my variable set to NULL if possible (assuming my DB will like that).

    This is what I am attempting and the error follows:

    <code>
    Dim intDispOrder as Integer
    If Trim(CType(e.Item.FindControl("txtDGDispOrder"),TextBox).Text) != "" Then
    intDispOrder = (CType(e.Item.FindControl("txtDGDispOrder"),TextBox).Text)
    End If
    </code>

    Compiler Error Message: BC30205: End of statement expected.

    Can someone point me to the syntax problem? Any extra pointers about the actual code and if it will work are appreciated too!

    TIA!

  2. #2
    Join Date
    Apr 2005
    Posts
    5
    Oh, sorry, the error is on the If statement line.

  3. #3
    Join Date
    Apr 2005
    Posts
    5
    Background: the original problem I am attempting to solve is the following exception that I was getting when the user didn't enter an integer in the TextBox as the code expects (without the If statement):

    Exception Details: System.FormatException: Input string was not in a correct format.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    "!=" is C#/JavaScript syntax. Try this instead:

    If Trim(CType(e.Item.FindControl("txtDGDispOrder"), TextBox).Text) <> "" Then
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Apr 2005
    Posts
    5
    Most excellent! I thank you kindly!

    If someone doesn't mind, I also am wondering if I can initialize my integer variable as NULL (instead it seems to default to zero)? I tried two ways but got errors each time:

    Dim intDispOrder as Integer = System.DBNull
    BC30691: 'DBNull' is a type in 'System' and cannot be used as an expression.

    Dim intDispOrder as Integer = NULL
    BC30822: 'NULL' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead.

    Is it even possible to set a var to null?

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    It is not possible to set an Integer variable to null. Either choose an integer value (e.g., -1) to represent a null value, or use an Object variable instead of an Integer:

    Dim objDispOrder As Object ' Defaults to Nothing
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Apr 2005
    Posts
    5
    Thanks, Phil. I think I was headed down the path of poor programming with that question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center