'System.FormatException...........Convert from String to Boolean

I am reading data from a flat file.  The data in the field is a 0.  I am reading it in as a String value because if the data does not exist, the fill the location with a blank.  I then try to covert it to a boolean value but get a system.format problem.  What could be causing this problem.

Thanks
Kenny


Here is the code


Dim migrant As String
 migrant = Val(Mid(strLine, 102, 1))
  migrant = Convert.ToBoolean(migrant)
kwh3856Asked:
Who is Participating?
 
gregoryyoungConnect With a Mentor Commented:
or you can just put in an ifstatement if thats clearer to you ...

dim  val as boolean = false
if migrant = "1" then
    val = true
end if
0
 
gregoryyoungCommented:
you cant convert a 1/0 to a boolean ...

instead use

dim foo as integer = Convert.ToInt(migrant)
dim val as boolean = (foo = 1)
0
 
kwh3856Author Commented:
Once again.....THANK YOU..


Thanks
Kenny
0
 
gregoryyoungCommented:
anytime, let me know if you need anything further.

Cheers,

Greg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.