Results 1 to 4 of 4

Thread: "not valid integer value"

  1. #1

    "not valid integer value"

    Hi there.. I have a quite basic problem here which I can't find the answare to since I don't know exactly what I'm looking for.. I want to check if a string is a valid integer value before doing an StrToInt(); to avoid the "not valid int value" error message. I tried adding try, except, finally, but that diddn't remove the message..
    BK - we.create (tm)

  2. #2

    "not valid integer value"

    StrToIntDef tries to convert the string, and gives you back a default value if it can't convert. For example, to convert, and get back -1 if a problem occurs:

    [pascal]MyInt := StrToIntDef(YourString, -1);[/pascal]

    Alternatively, use exception handling:

    [pascal]try
    MyInt := StrToInt(YourString);
    except
    // a problem occurred - deal with it
    MyInt := -1;
    end;[/pascal]
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    "not valid integer value"

    Thanks
    BK - we.create (tm)

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    "not valid integer value"

    The Val function turns a string into an integer but allows an error code as a third parameter that indicates the first character in the string that isn;t numeric.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

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