Link to home
Start Free TrialLog in
Avatar of kwh3856
kwh3856Flag for United States of America

asked on

'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)
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

you cant convert a 1/0 to a boolean ...

instead use

dim foo as integer = Convert.ToInt(migrant)
dim val as boolean = (foo = 1)
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kwh3856

ASKER

Once again.....THANK YOU..


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

Cheers,

Greg