RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

VB6 - Hex issues

VB6 - Hex issues

Hey! I was wondering about code to convert hex into a digit... I've been trying, yet i've found no way to fix any digits like "G" and "M" and "$" and such... They cause the stuff to give an error.

Here's what i'm talking about... Text1 and Text2 are the text boxes.

Scenario 1:
-User imputs a HEX code (like FB34) into Text1
-I use command Text2.Text = Int(Text1.Text)
-Output should go into Text2...
-Say user 'messed up' and typed "GB34" into Text1...
-Program crashes...

Scenario 2:
-User imputs NUMBERS into Text1...
-Messes up, types something like 103Y
-Text2 is supposed to make that HEX... It's too stupid to do so...
-Tries to use command Text2.Text = Hex(Text1.TexT) and crashes...

I don't know how to remove that, i've tried this tutorial on removing certain characters from a string, but that didn't work :\

So, if anyone knows... then please aid! lol

-Aiden
 

joey snitch

Wanderer
easiest way is to simply ignore the offending characters. try this:
Scenario 1:
Text2.Text = Val("&h" + Text1.Text)
Scenario 2:
Text2.Text = Hex(Val(Text1.Text))

In both cases, if it encounters an invalid character, it simply stops parsing the string. so if i put 1G3 and tried to convert it to hex, it would only return 1. and if I typed FX in to convert to int, it would only return 15
If this isn't what you're looking for, or you can't make it work, let me know...
 
joey snitch said:
easiest way is to simply ignore the offending characters. try this:
Scenario 1:
Text2.Text = Val("&h" + Text1.Text)
Scenario 2:
Text2.Text = Hex(Val(Text1.Text))

In both cases, if it encounters an invalid character, it simply stops parsing the string. so if i put 1G3 and tried to convert it to hex, it would only return 1. and if I typed FX in to convert to int, it would only return 15
If this isn't what you're looking for, or you can't make it work, let me know...

Oh, that's exactically what i've been searching for! Thanks a bunch :D:D
 
Top