Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How do I use Left, Right and Mid Functions?

How do I use Left, Right and Mid Functions?

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorial
6 Posts 4 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrGee
    wrote on last edited by
    #1

    I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!

    N H 2 Replies Last reply
    0
    • M MrGee

      I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      While there are a number of different ways you can do this, here is just a quick example:

      Dim str, buff As String
      str = Me.TextBox1.Text
      Do While Len(str)
      buff = Left(str, 2)
      ListBox1.AddItem (buff)
      str = Right(str, Len(str) - 2)
      Loop

      You can obviously remove the listbox instruction, this is only an example. Hope this helps. :) -Nick Parker

      1 Reply Last reply
      0
      • M MrGee

        I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!

        H Offline
        H Offline
        Hesham Amin
        wrote on last edited by
        #3

        plz post some code so we can help :)

        M 1 Reply Last reply
        0
        • H Hesham Amin

          plz post some code so we can help :)

          M Offline
          M Offline
          MrGee
          wrote on last edited by
          #4

          I finally got it to work using the following code. It's probably not the most efficient code, so if there is a better way, please let me know. Private Sub txtCMD_Change() Dim Length As String Dim Hash As String Dim Code2 As String Dim Code3 As String Dim Code4 As String Dim Code5 As String Dim Code6 As String Dim Code7 As String Dim Code8 As String Dim Code9 As String Dim Code10 As String Dim Code11 As String Dim Code12 As String Dim Code13 As String Dim Code14 As String Dim Code15 As String Dim Code16 As String Dim Code17 As String Dim Code18 As String Dim Code19 As String Dim Code20 As String Dim Code21 As String Dim Code22 As String Dim Code23 As String Dim Code24 As String Dim Code25 As String Dim Code26 As String Dim Code27 As String Dim Code28 As String Dim Code29 As String Dim Code30 As String Dim Code31 As String Dim Code32 As String Dim Code33 As String Dim Code34 As String Dim Code35 As String Dim Code36 As String Dim Code37 As String Dim Code38 As String Dim Code39 As String Dim Code40 As String Dim Code41 As String Dim Code42 As String Dim Code43 As String Dim Code44 As String Dim Code45 As String Dim Code46 As String Dim Code47 As String Dim Code48 As String Dim Code49 As String Length = txtCMDLength.Text Hash = txtHashRange.Text Code2 = Hex2.Text Code3 = Hex3.Text Code4 = Hex4.Text Code5 = Hex5.Text Code6 = Hex6.Text Code7 = Hex7.Text Code8 = Hex8.Text Code9 = Hex9.Text Code10 = Hex10.Text Code11 = Hex11.Text Code12 = Hex12.Text Code13 = Hex13.Text Code14 = Hex14.Text Code15 = Hex15.Text Code16 = Hex16.Text Code17 = Hex17.Text Code18 = Hex18.Text Code19 = Hex19.Text Code20 = Hex20.Text Code21 = Hex21.Text Code22 = Hex22.Text Code23 = Hex23.Text Code24 = Hex24.Text Code25 = Hex25.Text Code26 = Hex26.Text Code27 = Hex27.Text Code28 = Hex28.Text Code29 = Hex29.Text Code30 = Hex30.Text Code31 = Hex31.Text Code32 = Hex32.Text Code33 = Hex33.Text Code34 = Hex34.Text Code35 = Hex35.Text Code36 = Hex36.Text Code37 = Hex37.Text Code38 = Hex38.Text Code39 = Hex39.Text Code40 = Hex40.Text Code41 = Hex41.Text Code42 = Hex42.Text Code43 = Hex43.Text Code44 = Hex44.Text Code45 = Hex45.Text Code46 = Hex46.Text Code47 = Hex47.Text Code48 = Hex48.Text Code49 = Hex49.Text Length = UCase(Mid(txtCMD,

          D 1 Reply Last reply
          0
          • M MrGee

            I finally got it to work using the following code. It's probably not the most efficient code, so if there is a better way, please let me know. Private Sub txtCMD_Change() Dim Length As String Dim Hash As String Dim Code2 As String Dim Code3 As String Dim Code4 As String Dim Code5 As String Dim Code6 As String Dim Code7 As String Dim Code8 As String Dim Code9 As String Dim Code10 As String Dim Code11 As String Dim Code12 As String Dim Code13 As String Dim Code14 As String Dim Code15 As String Dim Code16 As String Dim Code17 As String Dim Code18 As String Dim Code19 As String Dim Code20 As String Dim Code21 As String Dim Code22 As String Dim Code23 As String Dim Code24 As String Dim Code25 As String Dim Code26 As String Dim Code27 As String Dim Code28 As String Dim Code29 As String Dim Code30 As String Dim Code31 As String Dim Code32 As String Dim Code33 As String Dim Code34 As String Dim Code35 As String Dim Code36 As String Dim Code37 As String Dim Code38 As String Dim Code39 As String Dim Code40 As String Dim Code41 As String Dim Code42 As String Dim Code43 As String Dim Code44 As String Dim Code45 As String Dim Code46 As String Dim Code47 As String Dim Code48 As String Dim Code49 As String Length = txtCMDLength.Text Hash = txtHashRange.Text Code2 = Hex2.Text Code3 = Hex3.Text Code4 = Hex4.Text Code5 = Hex5.Text Code6 = Hex6.Text Code7 = Hex7.Text Code8 = Hex8.Text Code9 = Hex9.Text Code10 = Hex10.Text Code11 = Hex11.Text Code12 = Hex12.Text Code13 = Hex13.Text Code14 = Hex14.Text Code15 = Hex15.Text Code16 = Hex16.Text Code17 = Hex17.Text Code18 = Hex18.Text Code19 = Hex19.Text Code20 = Hex20.Text Code21 = Hex21.Text Code22 = Hex22.Text Code23 = Hex23.Text Code24 = Hex24.Text Code25 = Hex25.Text Code26 = Hex26.Text Code27 = Hex27.Text Code28 = Hex28.Text Code29 = Hex29.Text Code30 = Hex30.Text Code31 = Hex31.Text Code32 = Hex32.Text Code33 = Hex33.Text Code34 = Hex34.Text Code35 = Hex35.Text Code36 = Hex36.Text Code37 = Hex37.Text Code38 = Hex38.Text Code39 = Hex39.Text Code40 = Hex40.Text Code41 = Hex41.Text Code42 = Hex42.Text Code43 = Hex43.Text Code44 = Hex44.Text Code45 = Hex45.Text Code46 = Hex46.Text Code47 = Hex47.Text Code48 = Hex48.Text Code49 = Hex49.Text Length = UCase(Mid(txtCMD,

            D Offline
            D Offline
            dynamic
            wrote on last edited by
            #5

            you could cut down with the string , also you could make an array of your textboxes , then you could use something like this : Vb6:


            Private Sub Command1_Click()
            Dim code(2 To 49) As String, x As Long
            Dim txthx(2 To 49) As String
            Dim tb As TextBox

            For x = 2 To 49
            For Each tb In Controls
            If tb.Name = txthx(x) Then
            tb.Text = code(x)
            End If
            Next
            Next

            End Sub


            that would cut out a lot of code :) Vb:


            Public Function TwinsOnWay(ByVal twins As String) As String
            Select Case twins
            Case "Gender"
            Return "Two Girls"
            End Select
            End Function


            M 1 Reply Last reply
            0
            • D dynamic

              you could cut down with the string , also you could make an array of your textboxes , then you could use something like this : Vb6:


              Private Sub Command1_Click()
              Dim code(2 To 49) As String, x As Long
              Dim txthx(2 To 49) As String
              Dim tb As TextBox

              For x = 2 To 49
              For Each tb In Controls
              If tb.Name = txthx(x) Then
              tb.Text = code(x)
              End If
              Next
              Next

              End Sub


              that would cut out a lot of code :) Vb:


              Public Function TwinsOnWay(ByVal twins As String) As String
              Select Case twins
              Case "Gender"
              Return "Two Girls"
              End Select
              End Function


              M Offline
              M Offline
              MrGee
              wrote on last edited by
              #6

              That looks like it would save a lot of code, but I'm not sure how to use it to get the results I need. Am I correct that this is attached to a command button?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups