Register - Login
Views: 99830428
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 09:11:47 PM
Jul - Computers and Technology - Visual Basic 2008, reading from ROMs? New poll - New thread - New reply
Next newer thread | Next older thread
Deleted User
Collection of nobodies
Posted on 12-08-07 03:19:22 PM (last edited by Jelly Beanie at 12-08-07 12:20 PM) Link | Quote
Hello, I'm new here, and I need help in Visual Basic. I got my code to open the ROM and read some offsets, but when I do read them, the values are returned as weird characters instead of the expected 01, 0A, FF, etc...

I tried this code:

FileOpen(1, File, OpenMode.Binary)
FileGet(1, gxed1.Text, &H3976BC)

And the text field gets a " ` "

In the ROM there is a "01" when reading through a hex editor. I tried converting to ASCII value and to hex, but I didn't get what I was expecting. The question is, how do I need to convert it to make it display the value like Hex editors do?

Thanks.

____________________


===================
[Posted by Jelly Beanie]
Deleted User
Collection of nobodies
Posted on 12-08-07 03:32:26 PM Link | Quote
What you describe is exactly what I'd expect to happen.

Hex editors show the byte values, not the actual ascii characters. The ones you listed aren't even part of the "printable" set.

____________________


===================
[Posted by Kawa]
Deleted User
Collection of nobodies
Posted on 12-08-07 03:38:06 PM Link | Quote
Well, it doesn't, that's why I'm asking for help. The text box instead of displaying a "01" it displays the scrambles I usually see in notepad.

____________________


===================
[Posted by Jelly Beanie]
Post 24/1311 (41 days), online 2 days ago
Posted on 12-08-07 05:12:00 PM Link | Quote
Asc() gives the ASCII value for any character ... but can't VisualBasic read values into integers directly? Or at least it could before .NET Like this:

Dim val As Integer '(or Byte, Long, whatever length you need)
Open "filename" For Binary As #1
Get #1, &H3976BC, val


____________________



#122
Deleted User
Collection of nobodies
Posted on 12-08-07 05:31:18 PM Link | Quote
Yeah, I remember I could get the value directly in VB6, and I tried the Asc() function already and it got me a 96, instead of a 01. And the hex address is correct.

____________________


===================
[Posted by Jelly Beanie]
Post 25/1311 (41 days), online 2 days ago
Posted on 12-08-07 05:34:29 PM Link | Quote
96 is ASCII for the "`" you were getting, so that part works ... just remember the first byte in the file ($000000) is offset 1 in VisualBasic, so you have to add 1

____________________



#122
Deleted User
Collection of nobodies
Posted on 12-08-07 05:42:41 PM Link | Quote
Thanks, now it works.

____________________


===================
[Posted by Jelly Beanie]
Rena
I had one (1) message in Discord deleted and proceeded to make a huge, huge mess about how it was a violation of free speech and how moderators are supposed to be spam janitors and nobody should have the right to tell me not to talk about school shootings
Level: 135


Posts: 1763/5390
EXP: 29077141
For next: 257864

Since: 07-22-07

Pronouns: he/him/whatever
From: RSP Segment 6

Since last post: 342 days
Last activity: 342 days

Posted on 12-08-07 08:49:49 PM Link | Quote
Jul - Post #1763 - 12-08-07 03:49:49pm
Watch out with using hex in VB. I don't know if "VB 2008" has the same problems as VB6, but there were a few gotchas that you had to watch out for. VB liked to assume you were using Integer (16-bit) unless you told it otherwise, so e.g. assigning &hFFFF to a variable got you -1 even if it were a Long. I don't remember how you tell it you want 65535 instead. Also, Byte is always unsigned, but IIRC Integer and Long are always signed (durr), so you might get tripped up with things being negative when you don't expect it.

____________________
Deleted User
Collection of nobodies
Posted on 12-08-07 09:36:40 PM Link | Quote
Well, I haven't gotten any problems besides the one I mentioned above, thanks anyways. I got to say I'm a bit curious on how I could read and write to a ROM without even converting to decimal and back to hex...

To convert it back I just used Chr(gxed1.Text)

But meh, as long as it works

____________________


===================
[Posted by Jelly Beanie]
neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 87/603
EXP: 1084754
For next: 72365

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 42 days

Posted on 12-09-07 04:52:06 AM Link | Quote
Originally posted by HyperHacker
VB liked to assume you were using Integer (16-bit) unless you told it otherwise, so e.g. assigning &hFFFF to a variable got you -1 even if it were a Long.
VB sign extends to fill in the missing bits it doesn't see in the expression. In short, the safe thing to do is to always give enough bits as the type contains.
Post 27/1311 (41 days), online 2 days ago
Posted on 12-09-07 05:05:50 AM Link | Quote
I'm pretty sure adding "L" at the end (like &HFFFFL) forced it to be Long, just like in C ...

And there has to be a way to do this without Asc/Chr in newer versions ... what if you had to read a 16/32bit integer?

____________________



#119
Sukasa

Level: 123


Posts: 159/4326
EXP: 20936845
For next: 294421

Since: 07-07-07


Since last post: 1.1 years
Last activity: 1.1 years

Posted on 12-09-07 05:18:53 AM Link | Quote
Send PM | Obligatory blank page | Megaman ZX FTW
Real Life Comics
Perfection NEO Forums
p2pnet.net

Actualy, &hFFFF& = 65535, not L

____________________
Rena
I had one (1) message in Discord deleted and proceeded to make a huge, huge mess about how it was a violation of free speech and how moderators are supposed to be spam janitors and nobody should have the right to tell me not to talk about school shootings
Level: 135


Posts: 1766/5390
EXP: 29077141
For next: 257864

Since: 07-22-07

Pronouns: he/him/whatever
From: RSP Segment 6

Since last post: 342 days
Last activity: 342 days

Posted on 12-09-07 05:32:36 AM Link | Quote
Jul - Post #1766 - 12-09-07 12:32:36am
Originally posted by Sukasa
Actualy, &hFFFF& = 65535, not L
Yeah, that was it. (For pointlessness' sake, you can do &o for Octal too! \o/)

____________________
GuyPerfect
Catgirl
Level: 68


Posts: 191/1096
EXP: 2665817
For next: 62983

Since: 07-23-07


Since last post: 1.7 years
Last activity: 220 days

Posted on 12-10-07 05:45:28 AM Link | Quote
Joke's on you, Sukasa. &HFFFFL works in .NET, but I'm not certain &HFFFF& does.
Next newer thread | Next older thread
Jul - Computers and Technology - Visual Basic 2008, reading from ROMs? New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

31 database queries, 2 query cache hits.
Query execution time: 0.085984 seconds
Script execution time: 0.027534 seconds
Total render time: 0.113518 seconds