Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Can't enter HEX numbers in value textbox?


Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2001, 04:47 PM
vbfourme
Guest
 
Posts: n/a
Default Can't enter HEX numbers in value textbox?


Hi,

First of all I’d like to say how much this site and the VB link web pages (especially Planet Source Code) has helped me, I’ve learned more in the last week then in months of reading books.

Now,

I’m stuck on how to enter a HEX number into a text box. I’m creating an Assembly Language Calculator / Conversion program; here is a partial of my code:

Private Sub Command1_Click()
Dim MyHex
Dim MyDec
Dim lngNum As Long
Dim lngBin As Long
Dim strResult As String
firstVal = (fstval.Text) ' first Hex value
secondVal = (sndval.Text) ' second Hex value
MyDec = firstVal Xor secondVal ' Returns Xor in Dec number
MyHex = Hex(MyDec) ' Returns Xor in Hex number
HexRes.Text = MyHex ' Display Hex result
DecRes.Text = MyDec ' Display Dec result
BinRes.Text = strResult$ ' Display Bin result

EVERYTHING works fine but ONLY if I enter DECIMAL numbers in the respective value textboxes, I WANT to use ONLY Hex numbers.

What I want to do is enter HEX numbers directly into the “first value textbox” and “second value textbox”. I CAN enter the values as, for example &h3E and &h2F and everything works fine. But I’d rather NOT have the users do this, what I would like is this: 3E and 2F and return the proper values in the appropriate textbox. I’ve tried all kinds of treatments for this but cannot seem to get anything to work. I tried Private Functions, Declarations, plus an array of other codes; I also have DOZENS of codes and apps from Planet Source Code and copied, pasted, and edited just about everyone of them but STILL cannot get this to work the way I want it.

As you can tell I’m a “toddler” as far as VB is concerned, I’m just starting; but with the aid of this site and the VB links page I’m sure I’ll begin to move a bit faster.

Thanks,

vbfourme
Reply With Quote
  #2  
Old 12-09-2001, 05:06 PM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default Re: Can't enter HEX numbers in value textbox?

Well, you could do a Val(hexvalue) to convert it to a decimal, and then do stuff, then convert back with Hex(decvalue).
Reply With Quote
  #3  
Old 12-09-2001, 05:23 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default Re: Can't enter HEX numbers in value textbox?

Val(hexval) will only work if you put an &H in front of it.

These functions may be of use to you.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #4  
Old 12-09-2001, 05:28 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default Re: Can't enter HEX numbers in value textbox?

You could also check out this post for a function that works.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #5  
Old 12-09-2001, 06:05 PM
vbfourme
Guest
 
Posts: n/a
Default Re: Can't enter HEX numbers in value textbox?

Okay, I'm making headway.

I can get the &h to display AFTER I click in either value textbox with this code:

Private Sub fstval_Click()
fstval.Text = "&h"
sndval.Text = "&h"
End Sub

BUT, my question is:

Isn't this code suppose to open a textbox with whatever is between the quotes ALREADY displayed in the text box:

fstval.text = "&h"
sndval.text = "&h"

Why isn't the textbox displaying what I have between the quotes? If I can get this already displayed then the users will ONLY have to enter the value; plus, it will also relieve me of placing a label telling the user to enter a Hex value since the &h which is already displayed speaks for itself.

Whoops, I just inserted this in the main code and got a "type mismatch". Hummm.
Reply With Quote
  #6  
Old 12-09-2001, 06:11 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default Re: Can't enter HEX numbers in value textbox?

Set the Text property at design time or in the form load event. You should also have an error handler around the val statement just in case the user deletes the &h from the textbox.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #7  
Old 12-09-2001, 06:17 PM
vbfourme
Guest
 
Posts: n/a
Default Re: Can't enter HEX numbers in value textbox?

This reminds me of the Abbott and Costello routine when Bud askes Lou "How stupid can you be" and Lou replies, "How stupid do yo want me to be."

YEAH, set it at design time; what a NOVEL idea.

Thanks Banjo.

EDITED:

IT WORKS!!!!!!!
Reply With Quote
  #8  
Old 12-10-2001, 06:38 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default Re: Can't enter HEX numbers in value textbox?

<pre>If UCase(Left$(Text1.Text, 2)) = "&amp;H" Then
lngVariable = Val(Text1.Text)
ElseIf UCase(Left$(Text1.Text, 1)) = "&amp;" Then
lngVariable = Val("&amp;H" &amp; Mid$(Text1.Text, 2))
ElseIf UCase(Left$(Text1.Text, 2)) = "H" Then
lngVariable = Val("&amp;" &amp; Text1.Text)
Else
lngVariable = Val("&amp;H" &amp; Text1.Text)
End If</pre>

Makes the entering of data almost completely foolproof, but not quite.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #9  
Old 12-10-2001, 10:49 AM
vbfourme
Guest
 
Posts: n/a
Default Re: Can't enter HEX numbers in value textbox?

Thanks Squirm,

I'll file that with the other codes. Now, that I got this thing working , so to speak; I'll play around with these so I can get it working the way it SHOULD.

vbfourme
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->