Input String Not in Correct Format

T

tjonsek

I'm building a string to be used as the body of an email.

I'm getting this error message. "Input String Not In Correct Format".

I've checked several newsgroups, however, for the posts I found it was
always in conjunction with a query or conversion. This is neither.
It could be the control break I'm trying to use. I also tried
researching that but came up with a bunch of posts for web/window
controls that are breaking, rather than something to do with display of
text.

Here is the line of code that seems to be causing issues.
body = "The following payout is requested " &
Me.ddlType.SelectedValue.ToString & ": " & g_key & ". " & vbCrLf & _

Polite input is very welcome.
Thanks
 
G

Guest

always in conjunction with a query or conversion. This is neither.

That depends, conversion is possibly occuring. What data type is the
variable "g_key"? What is "body" -- the MailMessage.Body property or your own
variable? If it's your own variable what is it's data type?

Try the following:

body = "The following payout is requested " & Me.ddlType.SelectedValue & ":
" & Convert.ToString(g_key) & ". " & vbCrLf

Changes:
* Removed the .ToString() call on Me.ddlType.SelectedValue since
..SelectedValue is already a string
* Added an explicit convertion to string for g_key since it's data type is
not specified here.
* Remove the trailing ampersand and underscore (& _) after the visual basic
constant vbCrLf.

Paul
 
T

tjonsek

I made the changes you suggested. Here is the full code for that
string. It's still bombing out on that line.
Not quite sure why.
body = "The following payout is requested " & Me.ddlType.SelectedValue
& ": " & Convert.ToString(g_key) & ". " & vbCrLf & _
body = body & "Date Prepared: " & Now() & vbCrLf & _
body = body & "Date of Incident: " & Me.txtDtStart.Text &
vbCrLf & _
body = body & "Union: " & ddlUnion.SelectedValue & vbCrLf & _
body = body & "Reason: " & Me.ddlType.SelectedValue & vbCrLf &
"For the following employee(s):" & vbCrLf & vbCrLf

I split up the commands to build the string to make it easier to read
and debug.
 
T

tjonsek

Ok. I did notice that my line with

body = body & "Date Prepared: " & Now()

was causing a conversion error as well, so I changed that to: body =
body & "Date Prepared: " & Convert.ToString(Now() )

I'm still getting an error, however the stack trace has changed. I
dont' understand the error message "[InvalidCastException: Cast from
string "Date of Incident: 12/12/05" to type 'Boolean' is not valid.] ".
I don't know how this could be happening. This is the line references
'Date of Incident':

body = body & "Date of Incident: " & Me.txtDtStart.Text & vbCrLf & _

Here is the complete stack trace as I see it on the browser when
testing:

FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String
Value, NumberFormatInfo NumberFormat)
Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String
Value)
Microsoft.VisualBasic.CompilerServices.BooleanType.FromString(String
Value)

[InvalidCastException: Cast from string "Date of Incident: 12/12/05
" to type 'Boolean' is not valid.]
Microsoft.VisualBasic.CompilerServices.BooleanType.FromString(String
Value)
GIS.InLieu.btnEmail_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\GIS\InLieu.aspx.vb:967
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Thanks!
 
T

tjonsek

Never mind. I made a dumb error and did not remove the '& _' when I
changed how I built the string.
 
P

Patrick.O.Ige

Maybe try making use of StringBuilder Class.
It would make life much more easier
Patrick
 
G

Guest

Like Patrick said, it's much more readable if you use a string builder. I'll
give it to you both ways:

body = "The following payout is requested " & _
Me.ddlType.SelectedValue & ": " & _
Convert.ToString(g_key) & ". " & vbCrLf & _
"Date Prepared: " & Now().ToShortDateString & vbCrLf & _
"Date of Incident: " & Me.txtDtStart.Text & vbCrLf & _
"Union: " & Me.ddlUnion.SelectedValue & vbCrLf & _
"Reason: " & Me.ddlType.SelectedValue & vbCrLf & _
"For the following employee(s):" & vbCrLf & vbCrLf

With a string builder:

Dim sb As New System.Text.StringBuilder
With sb
.Append("The following payout is requested ")
.Append(Me.ddlType.SelectedValue)
.Append(": ")
.Append(Convert.ToString(g_key))
.Append(". ")
.Append(vbCrLf)
.Append("Date Prepared: ")
.Append(Now().ToShortDateString)
.Append(vbCrLf)
.Append("Date of Incident: ")
.Append(Me.txtDtStart.Text)
.Append(vbCrLf)
.Append("Union: ")
.Append(Me.ddlUnion.SelectedValue)
.Append(vbCrLf)
.Append("Reason: ")
.Append(Me.ddlType.SelectedValue)
.Append(vbCrLf)
.Append("For the following employee(s):")
.Append(vbCrLf)
.Append(vbCrLf)
End With
MailMessage.Body = sb.ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top