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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. need help

need help

Scheduled Pinned Locked Moved Visual Basic
helpquestion
7 Posts 2 Posters 0 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.
  • P Offline
    P Offline
    pandapatin
    wrote on last edited by
    #1

    im doin a convertion from hex to ascii.the formula is working fine.but the is one problem whereby if the input is 00.its cant be display in the output..eg input="101010" the output="..." but for 1001 the output only ".".how could is resolve this?

    C 1 Reply Last reply
    0
    • P pandapatin

      im doin a convertion from hex to ascii.the formula is working fine.but the is one problem whereby if the input is 00.its cant be display in the output..eg input="101010" the output="..." but for 1001 the output only ".".how could is resolve this?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      1 - try to use an intelligent header, everyone here needs help 2 - try posting your code if you have a question about code you wrote.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      P 1 Reply Last reply
      0
      • C Christian Graus

        1 - try to use an intelligent header, everyone here needs help 2 - try posting your code if you have a question about code you wrote.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        P Offline
        P Offline
        pandapatin
        wrote on last edited by
        #3

        this is the decoding function,its working Public Function sHexDecode(ByVal sData As String) As String Dim iChar As Integer Dim sOutString As String Dim sTmpChar As String For iChar = 1 To Len(sData) Step 2 If Mid(sData, iChar, 2) = "00" Then 'sTmpChar = vbNullString oCP.Write(Chr("&H" & (1 - 1))) GoTo skipDecode End If sTmpChar = Chr("&H" & Mid(sData, iChar, 2)) skipDecode: sOutString = sOutString & sTmpChar Next iChar sHexDecode = sOutString 'Mod By TC Kua TextBox1.Text = "" TextBox1.Text = sHexDecode End Function this is the part to display the output Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try 'Mod by TC Kua 21st Feb 2008 Call sHexDecode(txtHex.Text) oCP.Write(Encoding.ASCII.GetBytes(Me.TextBox1.Text))))) oCP.Write(Chr("&H" & (1))) Catch ex As Exception ' Warn the user. MessageBox.Show("Unable to write to comm port") Finally End Try End Sub

        C 1 Reply Last reply
        0
        • P pandapatin

          this is the decoding function,its working Public Function sHexDecode(ByVal sData As String) As String Dim iChar As Integer Dim sOutString As String Dim sTmpChar As String For iChar = 1 To Len(sData) Step 2 If Mid(sData, iChar, 2) = "00" Then 'sTmpChar = vbNullString oCP.Write(Chr("&H" & (1 - 1))) GoTo skipDecode End If sTmpChar = Chr("&H" & Mid(sData, iChar, 2)) skipDecode: sOutString = sOutString & sTmpChar Next iChar sHexDecode = sOutString 'Mod By TC Kua TextBox1.Text = "" TextBox1.Text = sHexDecode End Function this is the part to display the output Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try 'Mod by TC Kua 21st Feb 2008 Call sHexDecode(txtHex.Text) oCP.Write(Encoding.ASCII.GetBytes(Me.TextBox1.Text))))) oCP.Write(Chr("&H" & (1))) Catch ex As Exception ' Warn the user. MessageBox.Show("Unable to write to comm port") Finally End Try End Sub

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Is this VB.NET ? Don't use stuff like 'Mid', use the proper .NET stuff.

          pandapatin wrote:

          GoTo skipDecode

          This use of Goto is just plain lazy and it makes your code hard to read. Don't use goto if you don't need to.

          pandapatin wrote:

          If Mid(sData, iChar, 2) = "00" Then

          What if the string has an odd number of characters ? Given that your original complaint is about what happens when the code hits 00, and given that you have a special case for this, can't you make it do whatever you like ?

          pandapatin wrote:

          sTmpChar = Chr("&H" & Mid(sData, iChar, 2))

          I guess you came from VB6. Please try to learn VB.NET. If MS had their way, this code would not work, all this VB6 stuff was originally to be removed. The string class as all the methods you need for this stuff.

          pandapatin wrote:

          TextBox1.Text = "" TextBox1.Text = sHexDecode

          Plain bizarre. Why set it twice in two lines ? And, what's wrong with using sensible variable names ?

          pandapatin wrote:

          Call sHexDecode(txtHex.Text) oCP.Write(Encoding.ASCII.GetBytes(Me.TextBox1.Text)))))

          Why not rewrite the function to return a string ? It looks like you don't really need the textbox ? Do you really need to specify 'call' ? I don't think so. What was the exact problem again ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          P 1 Reply Last reply
          0
          • C Christian Graus

            Is this VB.NET ? Don't use stuff like 'Mid', use the proper .NET stuff.

            pandapatin wrote:

            GoTo skipDecode

            This use of Goto is just plain lazy and it makes your code hard to read. Don't use goto if you don't need to.

            pandapatin wrote:

            If Mid(sData, iChar, 2) = "00" Then

            What if the string has an odd number of characters ? Given that your original complaint is about what happens when the code hits 00, and given that you have a special case for this, can't you make it do whatever you like ?

            pandapatin wrote:

            sTmpChar = Chr("&H" & Mid(sData, iChar, 2))

            I guess you came from VB6. Please try to learn VB.NET. If MS had their way, this code would not work, all this VB6 stuff was originally to be removed. The string class as all the methods you need for this stuff.

            pandapatin wrote:

            TextBox1.Text = "" TextBox1.Text = sHexDecode

            Plain bizarre. Why set it twice in two lines ? And, what's wrong with using sensible variable names ?

            pandapatin wrote:

            Call sHexDecode(txtHex.Text) oCP.Write(Encoding.ASCII.GetBytes(Me.TextBox1.Text)))))

            Why not rewrite the function to return a string ? It looks like you don't really need the textbox ? Do you really need to specify 'call' ? I don't think so. What was the exact problem again ?

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            P Offline
            P Offline
            pandapatin
            wrote on last edited by
            #5

            now the code already working.but the location of the output is not the same as the input.let say the input=101000,the output would look like this"001010=...".its changes place from last place to 1st place.actually i set it to read pair by pair.If Mid(sData, iChar, 2) = "00" Thenit doest read odd num input.

            C 1 Reply Last reply
            0
            • P pandapatin

              now the code already working.but the location of the output is not the same as the input.let say the input=101000,the output would look like this"001010=...".its changes place from last place to 1st place.actually i set it to read pair by pair.If Mid(sData, iChar, 2) = "00" Thenit doest read odd num input.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              pandapatin wrote:

              doest read odd num input.

              I'm suggesting you should fix that, so that the code doesn't break on bad input. I guess you need to step through the debugger and work out what's going on. If the values are being flipped, then perhaps you need to flip the assignment to assign the values in reverse.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              P 1 Reply Last reply
              0
              • C Christian Graus

                pandapatin wrote:

                doest read odd num input.

                I'm suggesting you should fix that, so that the code doesn't break on bad input. I guess you need to step through the debugger and work out what's going on. If the values are being flipped, then perhaps you need to flip the assignment to assign the values in reverse.

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                P Offline
                P Offline
                pandapatin
                wrote on last edited by
                #7

                thx dude..its working now..

                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