Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Talk to Webmaster Tony John
Online Members
naveensanagasetti
lily
Padma
prabhakar
Nitin Soni
abhinav
Prabu
Celine liyon
Ranipriya
More...
Forums
»
.NET
»
.NET
»
Input string was not in a correct format
Posted Date:
22 Jul 2012
Posted By::
ptina
Member Level:
Bronze
Member Rank:
1584
Points
: 5
Responses:
3
private void btn_Clear_Click(object sender, EventArgs e)
{
txt_ID.Text = "";
txt_Manufacturer.Text = "";
txt_CatNo.Text = "";
txt_DischargeRate1.Text = "";
txt_BatteryCapacity.Text = "";
txt_Voltage.Text = "";
txt_Weight.Text = "";
txt_Length.Text = "";
txt_Width.Text = "";
txt_Height.Text = "";
txt_Series.Text = "";
txt_Parallel.Text = "";
//txt_TotalBatteries.Text = "";
}
private void btn_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void txt_SystemVoltage_TextChanged(object sender, EventArgs e)
{
int intBatterySeries;
double dblBatterySeries;
if (txt_SystemVoltage.Text != "" && txt_Voltage.Text != "")
{
dblBatterySeries = Convert.ToDouble(txt_SystemVoltage.Text) / Convert.ToDouble(txt_Voltage.Text);
intBatterySeries = Convert.ToInt32(dblBatterySeries);
txt_Series.Text = intBatterySeries.ToString();
}
}
private void txt_Voltage_TextChanged(object sender, EventArgs e)
{
int intBatterySeries;
double dblBatterySeries;
if (txt_SystemVoltage.Text != "" && txt_Voltage.Text != "")
{
dblBatterySeries = Convert.ToDouble(txt_SystemVoltage.Text) / Convert.ToDouble(txt_Voltage.Text);
intBatterySeries = Convert.ToInt32(dblBatterySeries);
txt_Series.Text = intBatterySeries.ToString();
}
}
private void txt_Amp_TextChanged(object sender, EventArgs e)
{
int intBatteryParallel;
double dblBatteryParallel;
if (txt_SystemVoltage.Text != "" && txt_Voltage.Text != "")
{
dblBatteryParallel = Convert.ToDouble(txt_Amp.Text) / Convert.ToDouble(txt_BatteryCapacity.Text);
intBatteryParallel = Convert.ToInt32(dblBatteryParallel);
txt_Parallel.Text = intBatteryParallel.ToString();
}
}
private void txt_BatteryCapacity_TextChanged(object sender, EventArgs e)
{
int intBatteryParallel;
double dblBatteryParallel;//<<<error msg
if (txt_SystemVoltage.Text != "" && txt_Voltage.Text != "")
{
dblBatteryParallel = Convert.ToDouble(txt_Amp.Text) / Convert.ToDouble(txt_BatteryCapacity.Text);//<<<<<<<<<<<<<<<<<<<<<<< error
intBatteryParallel = Convert.ToInt32(dblBatteryParallel);
txt_Parallel.Text = intBatteryParallel.ToString();
}
}
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
}
private void txt_TotalBatteries_TextChanged(object sender, EventArgs e)
{
int intBatteryParallel;
double dblTotalBattery;
if (txt_Series.Text != "0" && txt_Parallel.Text != "0")
{
dblTotalBattery = Convert.ToDouble(txt_Series.Text) * Convert.ToDouble(txt_Parallel.Text);
intBatteryParallel = Convert.ToInt32(dblTotalBattery);
txt_TotalBatteries.Text = intBatteryParallel.ToString();
}
}
}
}
when i click the clear button. error msg as formatexception was unhandled. input string was not ina correct format.
at this part of the code as shown above.
private void txt_BatteryCapacity_TextChanged(object sender, EventArgs e)
{
int intBatteryParallel;
double dblBatteryParallel;//<<<error msg
if (txt_SystemVoltage.Text != "" && txt_Voltage.Text != "")
{
dblBatteryParallel = Convert.ToDouble(txt_Amp.Text) / Convert.ToDouble(txt_BatteryCapacity.Text);//<<<<<<<<<<<<<<<<<<<<<<< error
intBatteryParallel = Convert.ToInt32(dblBatteryParallel);
txt_Parallel.Text = intBatteryParallel.ToString();
}
}
1)how to correct the error as i am unable to clear the textboxes? 2)any mistake at txt_TotalBatteries as i am unable to get ans by multiplying txt_series and txt_parallel?
Tweet
Responses
#681345 Author:
ptina
Member Level:
Bronze
Member Rank:
1584
Date: 22/Jul/2012 Rating:
Points
: 1
sometimes i get values for txt_parallel as 0.2,0.5 but the ans is displayed as 0. how to display as 1 even the value is 0.2 or 0.5?
#681346 Author:
Ravindran
Member Level:
Diamond
Member Rank:
3
Date: 22/Jul/2012 Rating:
Points
: 2
Hi,
Before converting to Double make sure txt_BatteryCapacity text is integer value if you pass string value then the Input string error occur
Regards
N.Ravindran
Your Hard work never fails
#681353 Author:
Dharmaraj Nagarajan
Member Level:
Gold
Member Rank:
13
Date: 22/Jul/2012 Rating:
Points
: 3
Hi,
These error is because of either the value is not matching the format to the data type you wish to convert as Ravi suggested. One more thing before proceeding with the conversion, you need to check for the null value.
string Num;
num="";
if(num != "")
{
//put your conversion process here.
}
All is well.
Thanks,
Dharma
Editor,Mentor,MVM
Try and fail but don't fail and try
Me and DNS
Post Reply
You must
Sign In
to post a response.
Tweet
Next :
Getter setter vs get set?
Previous :
Scroll bar scrolling up automatically when user selects text from dropdownlist in Fck edit
Return to Discussion Forum
Post New Message
Category:
Related Messages
Is there any expert to solve this?
what is difference between String and string(data type) in c#?
what is a resource file...
Horizontal Scroll Bar for a listview control
sql querry
Active Members
Today
baskar
(71)
Asheej T K
(49)
naveensanagase...
(29)
Last 7 Days
baskar
(366)
Ultimaterengan
(292)
Asheej T K
(195)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds