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
Solved

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

Posted on 2004-09-03
4
216 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports vb.net 2 54
i have to take the screenshot of command prompt? how to do this? 1 45
Passing data between Forms 3 20
Convert Ctime to date time in textfile? 7 31
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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