Results 1 to 7 of 7

Thread: how use character string and converting

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    4

    how use character string and converting

    hii all members, im new here, and im new with VB. still learn...

    i need a suggest or solution about my case.

    i create a simple project for converting character..
    example :
    Textbox1 i write like : bkbcr01 ir ckbcr01

    and than, i create new 2 textbox for result..
    first box is from 2 of first character, it mean "bk" or "ck"
    for bk i want to get the result for number like 10 and ck = 11
    i test like this

    Code:
            Dim ItemCode As Char
            ItemCode = TextBox1.Text.Substring(0, 4)
            If TextBox1.Text = "bk" Then
                TextBox3.Text = "10"
            End If
            If TextBox1.Text = "ck" Then
                TextBox3.Text = "11"
            End If
    but my friend say, use Switch..but i dont know bout switch function.

    this is a first case


    2. Second case is..

    i want to use third fourth and fifth.. bcr
    this result, will show at the second textbox or textbox2 with true hidden.

    for this character i want to convert like this
    Code:
    a = 0
    b = 1
    c = 2
    ....
    ....
    ....
    z = 25
    and the result for bcr will be like this
    010217

    im very confuse for converthing this case...

    anybody know about this one..

    thx before...

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: how use character string and converting

    A switch function is used in C code. For VB it is referred to as a Select Case, and yea, it would be a better solution....

    Code:
    Select case textbox1.text
        Case "bk"
            TextBox3.Text = "10"
        Case "ck"
            TextBox3.Text = "11"
    I don't know what you are asking in your second question.
    kevin
    Last edited by kebo; Oct 27th, 2014 at 09:57 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    4

    Re: how use character string and converting

    thx for your respone my friend..

    first question is clear i think...

    for second question is..
    when i put bkbcr01, in textbox2 resulit will like this

    01021701

    bk = 10, from first Question, result in Textbox1

    01 = b
    02 = c
    17 = r
    01 = 01

  4. #4
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: how use character string and converting

    Hi,

    For you second question it sounds like you need some sort of conversion routine whereby “a” = 0 and “z” = 25 and all the letters in between increment by 1 each time and then the numbers are formatted to 2 characters each time?

    If so then you can use the ASCII value of each of the characters in the string, subtract them by 97 to make the characters zero indexed from “a”, for want of a better explanation, then format that number to be 2 characters then finally join them all together. Ie:-

    vb.net Code:
    1. Dim converterdText As String = String.Concat(someString.Skip(2).Take(3).Select(Function(x) (Asc(x) - 97).ToString("00")))
    2. MsgBox(converterdText)

    I will then leave this to you to put your final solution together.

    Hope that helps.

    Cheers,

    Ian

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    4

    Re: how use character string and converting

    ok friend..ill test it. and i will report this

    thx for the best solution

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    4

    Re: how use character string and converting

    i got a little confuse...

    here's my code

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ItemCode As Char
            Dim firststring As String = TextBox1.Text.Substring(0, 2)
            Dim blankmsg = "Insert The Right Code"
            Dim mssgtittle = "Blank Code"
    
    
    
    
            If TextBox1.Text.Length < 7 Then
                MsgBox(blankmsg, , mssgtittle)
    
    
            Else
                Select Case firststring
                    Case "if"
                        TextBox2.Text = "0"
                    Case "iu"
                        TextBox2.Text = "1"
                    Case "il"
                        TextBox2.Text = "2"
                    Case "ig"
                        TextBox2.Text = "3"
                    Case "is"
                        TextBox2.Text = "4"
                    Case "ih"
                        TextBox2.Text = "5"
                    Case "iw"
                        TextBox2.Text = "6"
                    Case "id"
                        TextBox2.Text = "7"
                    Case "ik"
                        TextBox2.Text = "8"
                    Case "ii"
                        TextBox2.Text = "9"
                    Case "ia"
                        TextBox2.Text = "10"
                    Case "ib"
                        TextBox2.Text = "11"
                    Case "im"
                        TextBox2.Text = "12"
                    Case "ip"
                        TextBox2.Text = "13"
                    Case "ie"
                        TextBox2.Text = "14"
                    Case "it"
                        TextBox2.Text = "15"
                    Case "io"
                        TextBox2.Text = "16"
                    Case "ir"
                        TextBox2.Text = "17"
                    Case "ic"
                        TextBox2.Text = "18"
                    Case "in"
                        TextBox2.Text = "19"
                    Case "iy"
                        TextBox2.Text = "20"
                    Case "iy"
                        TextBox3.Text = "20"
                    Case "iz"
                        TextBox2.Text = "21"
                    Case "iq"
                        TextBox2.Text = "22"
                    Case "ix"
                        TextBox2.Text = "23"
                    Case "ij"
                        TextBox2.Text = "24"
                    Case "gt"
                        TextBox2.Text = "25"
                    Case "tr"
                        TextBox2.Text = "26"
                    Case "sk"
                        TextBox2.Text = "27"
                    Case "ti"
                        TextBox2.Text = "28"
                    Case "ev"
                        TextBox2.Text = "29"
                    Case "re"
                        TextBox2.Text = "30"
                    Case "bx"
                        TextBox2.Text = "31"
                    Case "fi"
                        TextBox2.Text = "32"
                    Case "un"
                        TextBox2.Text = "33"
                    Case "rd"
                        TextBox2.Text = "34"
                    Case "lk"
                        TextBox2.Text = "35"
                    Case "cu"
                        TextBox2.Text = "36"
                End Select
                Dim convertText As String = String.Concat(TextBox1.Text.Skip(2).Take(3).Select(Function(x) (Asc(x) - 97).ToString("00")))
                TextBox3.Text = convertText
            End If
        End Sub
    End Class
    try to use this build release


    when you write like iyyyy23

    for Item TypeCode is good, it mean iy is 20
    and yyy23 should be like 24242423

    and once again,.. i want to insert $ symbol in front like this $24242423

    anyone can help me...

    sorry im new for this one, and sorry for bad english..

    thx before

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: how use character string and converting

    I have removed your attachment to protect our members, because we have no way of knowing what an executable file actually does - which could include something malicious, such as if there is a virus on your computer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width