Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (1 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 ,....

VB
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

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

VB
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]
VB
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
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900