Results 1 to 21 of 21

Thread: my program only reads four hex bytes x.X

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    my program only reads four hex bytes x.X

    hi all, my program is acting very weird... im using vbe 2005 and when my program loads from the file and gets what its supposed to get, it only reads the first 4 bytes, adds a FF byte to the start and the end... when i clearly wrote it to load the 6 digits... and i would also like it so that i dont have to write the offset for every letter but make it so it reads From one offset to another, which displays about 385 words, but they all have FF's in between them... so i want it so that it loads the file, then it loads a word, adds it as an item in a dropdownbox, when it gets to the FF's skip the FF's and add the word after to the next item in the dropdownbox... here is the code so far... and i would like someone to edit it please... it would be much appreciated.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim one, two, three, four, five, six As Byte
    3.         Dim A, B, C, D, F, G As String
    4.         Dim bname As String
    5.  
    6.         FileOpen(1, Mainform.OpenFileDialog1.FileName, OpenMode.Binary)
    7.         FileGet(1, one, &H245EEB) ' loads first letter, a P
    8.         FileGet(1, two, &H245EEC) ' loads second letter, an A
    9.         FileGet(1, three, &H245EED) ' loads third letter, a J
    10.         FileGet(1, four, &H245EEE) ' loads fourth letter, an A
    11.         FileGet(1, five, &H245EEF) ' loads fifth letter, a R
    12.         FileGet(1, six, &H246EF0) ' loads sixth letter, an O
    13.         FileClose(1)
    14.         A = ConvertByte(one)
    15.         B = ConvertByte(two)
    16.         C = ConvertByte(three)
    17.         D = ConvertByte(four)
    18.         F = ConvertByte(five)
    19.         G = ConvertByte(six)
    20.         bname = A + B + C + D + F + G ' adds them together to make the word, PAJARO
    21.         ComboBox1.Items.Add(bname) ' adds it as an item
    22.  
    23.     End Sub

    but it only reads PAJA encased by // (which i set as the translation for FF)help would be EXTREMELY appreciated

    -Shaneypoo17
    Last edited by Shaneypoo17; Mar 10th, 2006 at 12:54 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    well... ive figured out the four bytes problem... now i need something so i can load from one offset to another instead of loading every byte seperately... could someone give me an example of this code but instead of usingfileget over and over again make it so it like loads from one offset to another offset. here it is:
    VB Code:
    1. FileGet(1, one, &H245EEB) ' loads first letter, a P
    2.         FileGet(1, two, &H245EEC) ' loads second letter, an A
    3.         FileGet(1, three, &H245EED) ' loads third letter, a J
    4.         FileGet(1, four, &H245EEE) ' loads fourth letter, an A
    5.         FileGet(1, five, &H245EEF) ' loads fifth letter, a R
    6.         FileGet(1, six, &H246EF0) ' loads sixth letter, an O
    could someone change that so it loads all the letters in one go? and is there also a way to load from one offset to another one, and it reads a seperator that seperates one word from another and then it inserts each word into a different item in dropdownbox1? if there is could someone provide a code to do both things please?

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: my program only reads four hex bytes x.X

    Just use a For loop. Or have I misunderstood the question?
    I don't live here any more.

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    i really dont know... could you give an example?

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: my program only reads four hex bytes x.X

    To be honest, you are biting off WAY more than you can chew. You need to learn the fundamentals of programming before you try to start anything this advanced.

    Reading raw byte data is not trivial, even for an experienced programmer, if you are not familiar with looping constructs then you will not get anywhere with this particular task.

    In all seriousness I suggest you grab a book about programming, you'll be coding like a pro in no time.
    I don't live here any more.

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    well... i know looping... but i dont know how you would set up looping an offset... O.o but i am quite experienced and i managed to write a whole code that loads straight from raw bytes but i just need to know how i would go about looping offsets...

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    for loops dont work with bytes...do you know a way to get for loops to work with raw bytes?

  8. #8
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: my program only reads four hex bytes x.X

    How bout this?
    VB Code:
    1. Dim bname As String
    2.         Dim strHold As String
    3.         For int As Int32 = &H245EEB To &H246EF0
    4.             FileGet(1, strHold, int)
    5.             bname &= strHold
    6.         Next int
    Or if you need to....

    bname &= ConvertByte(strHold)

    Edit: ahhh, VBE 2005
    I use 2003, but the syntax should be really similiar (but atleast that exaplins the convertbyte).
    Last edited by sevenhalo; Mar 10th, 2006 at 04:02 PM.

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    doesnt work... just appears as a blank when i use my tablefile to translate it. and isnt hex 8-bit?

  10. #10
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: my program only reads four hex bytes x.X

    A single hex pair is, but the values you have (&H00245EEB) is 32bit (00 is left off in the IDE; no such thing as 24bit). Unless I'm sorely mistaken...

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    no... i doubt its 8-bit lol... im so stupid lol. does anyone know how to solve this prediciment?

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    the loading all letters in one go to cut down on coding one...

  13. #13
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: my program only reads four hex bytes x.X

    Step me through this one second... I just need to clarify a couple things.

    When you call "FileGet(1, one, &H245EEB)" what is the value of "one" as it appeards in the command window?

    Also, when you call "A = ConvertByte(one)", what is the value of "A" in the command window?

    I just want to make sure it's doing what I'm thinking it's doing.

    Thanks.

  14. #14

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    one is what the byte is stored in... and A is what the Converted byte is stored in. the ConvertByte is a function that basically has all the bytes and their conversions... if you wanna see it just say...

  15. #15
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: my program only reads four hex bytes x.X

    Yes please. Add break points to those two lines and copy/paste the output of them here.

    Also, if you're going to post long snippets like that, use an attachment.

  16. #16

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    well, this is quite very annoying O.o i found a working loop, but i get an error saying: 'For' loop control variable cannot be of type 'String'. and it underlines the first I in the loop heres the loop.
    VB Code:
    1. For I = 0 To pknameno
    2. Seek(1, nameoff + I + 12)
    3. FileGet(1, nameoff + I + 12)
    4. Next I

  17. #17

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    wait... nvm i fixed it up abit and instead of displaying a whole word per line, it displays one letter on each line... can someone fix this so that it loads 12 characters on each line?
    VB Code:
    1. Dim pknameno As Integer = 386
    2.         Dim nameoff As Long = &H245EEC
    3.         Dim avec As Byte                
    4.         Dim doubled As Long
    5.                 Dim lol As Integer = 12
    6.                 For doubled = 0 To pknameno
    7.                     Seek(1, nameoff + doubled + lol)
    8.                     FileGet(1, avec + lol, nameoff + doubled + lol)
    9.                     BZ = ConvertByte(avec)
    10.                     ComboBox1.Items.Add(BZ)
    11.                 Next doubled

    thx in advance,

    -Shaneypoo17

  18. #18

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    correction:

    VB Code:
    1. Dim pknameno As Integer = 386
    2.         Dim nameoff As Long = &H245EEC
    3.         Dim avec As Byte                
    4.         Dim doubled As Long
    5.                 Dim lol As Integer = 12
    6.                 For doubled = 0 To pknameno
    7.                     Seek(1, nameoff + doubled + lol)
    8.                     FileGet(1, avec, nameoff + doubled + lol)
    9.                     BZ = ConvertByte(avec)
    10.                     ComboBox1.Items.Add(BZ)
    11.                 Next doubled

    i still havnt found it... i really need help ;_;

  19. #19
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: my program only reads four hex bytes x.X

    I don't understand all the variables you have introduced.
    Going back to just reading from a file, and using methods from System.IO...

    Thinking of the file as a linear sequence of bytes. We want to jump to position H245EEB, then read 6 bytes, and put them into a string.

    .Net uses Streams, normally you use a StreamReader or BinaryReader, but they don't have an available Seek method. The base class IO.Stream does, but it is an abstact class that you are supposed to inherit from, not create instances of. We can get to the methods of the Stream class though, as you can use StreamReader.BaseStream.Seek. So we do that...
    VB Code:
    1. 'create a streamreader
    2.         Dim streamReader1 As New StreamReader("c:\1.txt")
    3.         'StreamReader inherits from the Stream class which has the methods we want.
    4.         '
    5.         'We use BaseStream.Seek to move to a position in the stream
    6.         ' The first parameter is an offset, the second is the place we are offset from
    7.         ' So we move to &H245EEB from the start of the file:
    8.         streamreader1.BaseStream.Seek(&H245EEB, SeekOrigin.Begin)
    9.         'reading 6 chars into this:
    10.         Dim charBuffer(5) As Char
    11.         'each time you read a char, the position in the stream moves on 1 place
    12.         'so the for loop reads 6 sequential bytes from the current position in the stream
    13.         For i As Integer = 0 To 5
    14.             charBuffer(i) = Convert.ToChar(streamreader1.BaseStream.ReadByte)
    15.         Next
    16.         ' write out the contents of the array
    17.         Dim outString As New String(charBuffer)
    18.         Console.WriteLine(outstring)
    19.         'tidy up
    20.         streamReader1.Close()
    21.         streamReader1.Dispose()

  20. #20

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    ... soz but could you edit it so:
    1.it converts the bytes using a function i made called ConvertByte
    2.it reads everything from &H245EEC to &H247091
    3.make it so it reads 386 words from those offsets... and each word is 12 characters long. then after could you make it so it puts each name on a different line in a dropdownbox?
    4. and make it load from mainform.openfiledialog1.filename plz
    if someone could do that i would be forever grateful ^^ thanks in advance

    -Shaneypoo17

  21. #21

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    38

    Re: my program only reads four hex bytes x.X

    anyone at all?

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