(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-22-24 01:53 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - Noob in VB 6 New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Nicky
Newcomer


 





Since: 04-25-06

Last post: 6601 days
Last view: 6601 days
Posted on 04-25-06 02:02 PM Link | Quote
Hi you all,

want to learn vb 6

my probs are:
I dont know how to load more than one byte
I dont know how to load the byte from a offset(for example i want load offset 444444, but i dont know how to do this)
I dont know how to save after editing the bytes into the rom.

THX in advance

bye you all
Guy Perfect









Since: 11-18-05

Last post: 6304 days
Last view: 6302 days
Posted on 04-25-06 02:37 PM Link | Quote
In any programming language, the most fundamental way to read data from and write data to files is to open the file for Binary access and use a buffer.

The Open statement is what is used in VB to open a file. You can open a file for Read, Write, or Read Write, depending on what you need to do. The Close statement will end interactions with the file. In the example below, I used Read Write, but change it if you only need to do one of those two:

Open "File.dat" For Binary Access Read Write As #1
'Your file I/O code goes here
Close #1

The #1 that I used is VB's way of automagically keeping track of open files. It can be, for the sake of learning, any whole number 1 or greater. You can also use a variable name here. The FreeFile function will return the lowest file number that is not currently in use, so you can Variable = FreeFile: Open "File.dat" For Binary Access Read Write As Variable if you need to.



The buffer is an array of any type you choose, but ROM hacking almost exclusively uses an array of Bytes. It's typically best to use a dynamic array and resize it depending on what you need to do. You'll have to do some research on what I'm about to show you, but this is just a basic example... so to speak. This will create an array of bytes, open a file, resize the array to the size of the file, and load the entire file into the array:

Dim Buffer() As Byte, FileLen As Double

Open "File.dat" For Binary Access Read As #1 'Open for Read only
FileLen = LoF(#1) 'Get the size of the file in number of bytes. LoF = Length of File

'We can't assign 0 elements to an array, so this check is required
If FileLen > 0 Then
ReDim Buffer(1 To FileLen) As Byte 'Resize the array
Get #1, 1, Buffer 'Get the data from file #1, starting at byte 1, into Buffer
End If
Close #1

The statement of choice in that example is the Get statement, which reads a number of records from a file. When you open the file for Binary, the record size is always the number of bytes. If you open the file for Write or Read Write, you can use the Put statement, which works in the same way, except it writes the contents of the array to the given location in the given file.

Important:
In most programming languages, the first byte in a file is indexed as 0, but in variants of BASIC, such as Visual Basic, it's indexed as 1.



Do some research on the Open, LoF, ReDim, Get, Put and Close procedures for a greater understanding of techniques used with file I/O.

If you have any questions after that, go ahead and ask.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - Noob in VB 6 |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.020 seconds; used 357.02 kB (max 435.88 kB)