Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > Visual Basic

Visual Basic Visual Basic Discussion

Reply
 
Thread Tools Display Modes
Old 12-22-2005, 07:52 PM   #1 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,522
Send a message via MSN to IHaveRegistered
Default 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
__________________
IHaveRegistered is offline   Reply With Quote
Old 12-24-2005, 02:54 AM   #2 (permalink)
 
Join Date: Nov 2003
Posts: 164
Default

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 is offline   Reply With Quote
Old 12-24-2005, 04:55 PM   #3 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,522
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by joey snitch
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
__________________
IHaveRegistered is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5