?
Solved

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

Posted on 2004-09-03
4
Medium Priority
?
219 Views
Last Modified: 2010-04-23
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)
0
Comment
Question by:kwh3856
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11974376
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
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 2000 total points
ID: 11974382
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
 

Author Comment

by:kwh3856
ID: 11974421
Once again.....THANK YOU..


Thanks
Kenny
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11974425
anytime, let me know if you need anything further.

Cheers,

Greg
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question