Solved

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

Posted on 2004-09-03
4
212 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
  • 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now