|
-
Mar 9th, 2006, 04:01 PM
#1
Thread Starter
Member
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim one, two, three, four, five, six As Byte
Dim A, B, C, D, F, G As String
Dim bname As String
FileOpen(1, Mainform.OpenFileDialog1.FileName, OpenMode.Binary)
FileGet(1, one, &H245EEB) ' loads first letter, a P
FileGet(1, two, &H245EEC) ' loads second letter, an A
FileGet(1, three, &H245EED) ' loads third letter, a J
FileGet(1, four, &H245EEE) ' loads fourth letter, an A
FileGet(1, five, &H245EEF) ' loads fifth letter, a R
FileGet(1, six, &H246EF0) ' loads sixth letter, an O
FileClose(1)
A = ConvertByte(one)
B = ConvertByte(two)
C = ConvertByte(three)
D = ConvertByte(four)
F = ConvertByte(five)
G = ConvertByte(six)
bname = A + B + C + D + F + G ' adds them together to make the word, PAJARO
ComboBox1.Items.Add(bname) ' adds it as an item
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.
-
Mar 10th, 2006, 03:06 PM
#2
Thread Starter
Member
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:
FileGet(1, one, &H245EEB) ' loads first letter, a P
FileGet(1, two, &H245EEC) ' loads second letter, an A
FileGet(1, three, &H245EED) ' loads third letter, a J
FileGet(1, four, &H245EEE) ' loads fourth letter, an A
FileGet(1, five, &H245EEF) ' loads fifth letter, a R
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?
-
Mar 10th, 2006, 03:13 PM
#3
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.
-
Mar 10th, 2006, 03:15 PM
#4
Thread Starter
Member
Re: my program only reads four hex bytes x.X
i really dont know... could you give an example?
-
Mar 10th, 2006, 03:26 PM
#5
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.
-
Mar 10th, 2006, 03:34 PM
#6
Thread Starter
Member
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...
-
Mar 10th, 2006, 03:52 PM
#7
Thread Starter
Member
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?
-
Mar 10th, 2006, 03:56 PM
#8
Re: my program only reads four hex bytes x.X
How bout this?
VB Code:
Dim bname As String
Dim strHold As String
For int As Int32 = &H245EEB To &H246EF0
FileGet(1, strHold, int)
bname &= strHold
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.
-
Mar 10th, 2006, 04:11 PM
#9
Thread Starter
Member
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?
-
Mar 10th, 2006, 04:21 PM
#10
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...
-
Mar 10th, 2006, 04:21 PM
#11
Thread Starter
Member
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?
-
Mar 10th, 2006, 04:23 PM
#12
Thread Starter
Member
Re: my program only reads four hex bytes x.X
the loading all letters in one go to cut down on coding one...
-
Mar 10th, 2006, 04:29 PM
#13
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.
-
Mar 10th, 2006, 04:34 PM
#14
Thread Starter
Member
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...
-
Mar 10th, 2006, 05:05 PM
#15
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.
-
Mar 11th, 2006, 06:17 AM
#16
Thread Starter
Member
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:
For I = 0 To pknameno
Seek(1, nameoff + I + 12)
FileGet(1, nameoff + I + 12)
Next I
-
Mar 11th, 2006, 07:09 AM
#17
Thread Starter
Member
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:
Dim pknameno As Integer = 386
Dim nameoff As Long = &H245EEC
Dim avec As Byte
Dim doubled As Long
Dim lol As Integer = 12
For doubled = 0 To pknameno
Seek(1, nameoff + doubled + lol)
FileGet(1, avec + lol, nameoff + doubled + lol)
BZ = ConvertByte(avec)
ComboBox1.Items.Add(BZ)
Next doubled
thx in advance,
-Shaneypoo17
-
Mar 11th, 2006, 07:52 AM
#18
Thread Starter
Member
Re: my program only reads four hex bytes x.X
correction:
VB Code:
Dim pknameno As Integer = 386
Dim nameoff As Long = &H245EEC
Dim avec As Byte
Dim doubled As Long
Dim lol As Integer = 12
For doubled = 0 To pknameno
Seek(1, nameoff + doubled + lol)
FileGet(1, avec, nameoff + doubled + lol)
BZ = ConvertByte(avec)
ComboBox1.Items.Add(BZ)
Next doubled
i still havnt found it... i really need help ;_;
-
Mar 11th, 2006, 08:45 AM
#19
Hyperactive Member
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:
'create a streamreader
Dim streamReader1 As New StreamReader("c:\1.txt")
'StreamReader inherits from the Stream class which has the methods we want.
'
'We use BaseStream.Seek to move to a position in the stream
' The first parameter is an offset, the second is the place we are offset from
' So we move to &H245EEB from the start of the file:
streamreader1.BaseStream.Seek(&H245EEB, SeekOrigin.Begin)
'reading 6 chars into this:
Dim charBuffer(5) As Char
'each time you read a char, the position in the stream moves on 1 place
'so the for loop reads 6 sequential bytes from the current position in the stream
For i As Integer = 0 To 5
charBuffer(i) = Convert.ToChar(streamreader1.BaseStream.ReadByte)
Next
' write out the contents of the array
Dim outString As New String(charBuffer)
Console.WriteLine(outstring)
'tidy up
streamReader1.Close()
streamReader1.Dispose()
-
Mar 11th, 2006, 09:40 AM
#20
Thread Starter
Member
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
-
Mar 12th, 2006, 09:17 AM
#21
Thread Starter
Member
Re: my program only reads four hex bytes x.X
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|