Click here to Skip to main content
14,332,266 members
Rate this:
Please Sign up or sign in to vote.
See more:
hiii...I am new in the coding world.....I am running a program ..where i have to convert a character in its Ascii value....I am getting anerror.....
"conversion of char in double is not possible"
plz help me ,....

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb_from.TextChanged
    Try

        tb_to.Text = tb_from.Text.Substring(0, tb_from.Text.Length - 3) + CStr(CInt(tb_from.Text.Substring(tb_from.Text.Length - 3)) + CInt(ddl_serial.Text))

        If ddl_stat.Text = "NBCC GR" Then
            If tb_from.Text.Substring(0, 1) <> "0" Then
                msgbox.WebMsgBox.Show(" serial should start from '0'")
            Else
                tb_to.Text = tb_from.Text.Substring(0, tb_from.Text.Length - 3) + CStr(CInt(tb_from.Text.Substring(tb_from.Text.Length - 3)) + CInt(ddl_serial.Text))
            End If
        End If

        If ddl_stat.Text = "NBCC Challan" Then
            If tb_from.Text.Substring(0, 1) <> "0" Then
                msgbox.WebMsgBox.Show(" serial should start from '0'")
            Else
                tb_to.Text = tb_from.Text.Substring(0, tb_from.Text.Length - 3) + CStr(CInt(tb_from.Text.Substring(tb_from.Text.Length - 3)) + CInt(ddl_serial.Text))
            End If
        End If

        If ddl_stat.Text = "GR" Or ddl_stat.Text = "GatePass" Or ddl_stat.Text = "Challan" Or ddl_stat.Text = "EB's" Or ddl_stat.Text = "D2D GatePass" Then

            Dim xyz As String

            xyz = tb_from.Text.Substring(0, 1)

            'If tb_from.Text.Substring(0, 1) <> Convert.ToInt32("A") Then

            If xyz <> System.Convert.ToInt32(xyz) Then

                'If xyz <> System.Convert.ToSByte(xyz) Then

                msgbox.WebMsgBox.Show("error")

            End If
            'System.Convert.ToSByte(xyz)
        End If
    Catch ex As Exception
        msgbox.WebMsgBox.Show(ex.ToString())
    End Try
End Sub
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

Don't know what all that code is for, but you just use:

Dim i As Integer = Asc("S")


The Convert.ToInt32 etc. are using to take a string that contains a number (ie, "25") and returns the numeric representation (25).

[EDIT]Added by LOSMAC ;)[/EDIT]
Dim i As Integer = 0
Dim sString As String = "Hello Word!"

For i = 0 To sString.Length - 1
    MsgBox(sString.Substring(i, 1) & " = " & Asc(sString.Substring(i, 1)), MsgBoxStyle.Information, sString)
Next
   
v2
Comments
Maciej Los 8-May-12 9:32am
   
Good answer, my 5!

More at MSDN: Asc, Chr

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100