Results 1 to 3 of 3

Thread: How to tell if field in file is boolean

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    26

    How to tell if field in file is boolean

    I'm processing a file for input and need to verify that all fields are of the correct type. One of the types is boolean.
    I've taken the input line and broke it down into a string array. From here I am checking whether the inputted value from the file is numeric and so on.
    My problem is how can I check to see if the field that is suppose to be boolean really is boolean?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    In the web controls there is a BaseCompareValidator that tests strings to see if they can convert to different types. You could either use that or I believe the you can get a TypeConverter object to check also.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can also use error checking if you want but it will be slow the first time.
    VB Code:
    1. 'syntax
    2.         Dim obj As String = "2"
    3.         MsgBox(CanConvertToBoolean(obj))
    4.  
    5.     Private Function CanConvertToBoolean(ByVal text As String) As Boolean
    6.         Dim bln As Boolean
    7.         Try
    8.             bln = Boolean.Parse(text)
    9.         Catch ex As Exception
    10.             Return False
    11.         End Try
    12.         Return True
    13.     End Function

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