Using a string array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evolution445
    New Member
    • Jul 2007
    • 63

    Using a string array

    Hi,

    I have a read process memory function, which is in a Do ... Loop.

    Code:
            Do
                On Error Resume Next
                ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
                Text = Text + Chr(Data)
                current_byte = current_byte + 1
            Loop Until current_byte = 17
            CloseHandle(pHandle)
    
            TextBox1.Text = Text
    It is currently reading a string saying: test-test-test-test-test
    What I want is to keep the current character it reads, and add the new one after it. "Text = Text + Chr(Data)".

    When I take this out and say "Text = Chr(Data)", then have Text display as MsgBox(Text), it works fine, I see character after character appear, but when I use the above code, then TextBox1.Text is left empty.

    What I thought of using was a string/character array, but I have no idea how to use that with my code. I did do an attempt:

    Code:
    Dim Text() as String = Nothing
    ReDim Text(0 to 17)
    
            Do
                On Error Resume Next
                ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
                Text(1) = Text(1) + Chr(Data)
                current_byte = current_byte + 1
                Text(1) = Text(+1)
            Loop Until current_byte = 17
            CloseHandle(pHandle)
    
            TextBox1.Text = Text
    But this didnt work either. I also tried using a global variable instead of a local one, but no result either.

    Another small problem Im having is that the readprocessmemo ry skips the very first character, always.


    Anyone know how to solve these issues?
    Any help appreciated.

    Evolution445
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    I think you should use & (ampersand) instead of + to concatenate strings. So Text = Text & Chr(Data).

    Steven
    Last edited by MrMancunian; Aug 6 '09, 11:27 AM. Reason: Typo

    Comment

    • Evolution445
      New Member
      • Jul 2007
      • 63

      #3
      Hi MrMancunian,


      Thanks for your reply, but this did not seem to work.
      This time 'Text' was left empty the whole time.

      What I did notice was that if I used:

      Text = Chr(Data) + Text

      The whole string came out fine, except that it was flipped the wrong way around.
      Last edited by Evolution445; Aug 6 '09, 12:23 PM. Reason: Added info instead of multi-post

      Comment

      • Evolution445
        New Member
        • Jul 2007
        • 63

        #4
        Think I found a way around this now, using:

        Code:
                    Text = TextBox1.Text + Chr(Data)
                    TextBox1.Text = Text
        Now it displays the string correctly in the textbox, but still the very first character is left out.

        It should read: "This is a test", but instead it comes up in the textbox as "his is a test"

        Is there a way to solve that?

        Evolution445

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Another small problem Im having is that the readprocessmemo ry skips the very first character, always.
          Current_byte must have been initialized someplace before the code you posted. I'm guessing you set it to 1 instead of zero. Most everything in our world is zero indexed meaning the first element of an array is item 0, second element is item 1 and so on.

          Comment

          • Evolution445
            New Member
            • Jul 2007
            • 63

            #6
            I have looked into that several times, even tried changing the offset address from 8723E9 to H8723E8 or H8723E7, but it had no effect, neither did changing current_byte from 0 to -2 or any other value, except upwards. Whatever I do, the first character after Data returns 0, is left out.

            Code:
            Dim current_byte As Integer = 0

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Have you tried using the Update method to refresh the TextBox.

              Say you had your TextBox within a panel called "ResultSection" ...you would have something like

              Code:
              Do
                          On Error Resume Next
                          ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
                           TextBox1.Text += Chr(Data)
                           ResultSection.Update()     
                          current_byte = current_byte + 1
              Loop Until current_byte = 17
              
              CloseHandle(pHandle)

              Comment

              • Evolution445
                New Member
                • Jul 2007
                • 63

                #8
                Hi Frinavale,

                I have just tried this using TextBox1.Update (), but the result is still the same, also when I put the textbox inside a panel.

                What I did was put a breakpoint on the readprocessmemo ry, and Chr(Data), when I pause it just after readprocessmemo ry, the first time, Data returns 0. While this seems kinda odd as it does run through the ReadProcessMemo ry. Whatever I try, it just skips the first character that comes after Data = 0.

                Instead of making it stop when current_byte is 30, I made that 250 so that it picked up other things aswell. Somewhere down the line there was "nter Message:". Suppose it was missing the "E" there aswell.

                I cant really explain the problem but I hope someone understands.

                Thanks in advance,

                Evolution445

                Comment

                • Evolution445
                  New Member
                  • Jul 2007
                  • 63

                  #9
                  Could it have something to do with the way I read memory? As in, one byte at a time. Could it solve the problem if I read e.g 20/30 bytes at once? How would I do this with an array, and properly converting whatever comes in Data to normal characters?

                  Comment

                  Working...