Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help converting dec to hex

Status
Not open for further replies.

RnRExpress

Technical User
Oct 24, 2004
53
US
I apologize for posting this message twice, but I wasnt sure which forum to do this in.

I am taking an 11 digit number , in a text box, and trying to convert it and palce that number into the enxt unbounded text box. A typical number would be something like 06701542003. And the =Hex option in Access cannot handle such a large number.

Any help would be extremely appreciated.

Richard
 
Try using DEC2HEX like

DEC2HEX(number,places)

where number is your number and places is numbe of characters to use. Also suitable for numbers with (0) zero leading.

If you get messag NAME? in result, you'll need to install (copy to win\sys folder) msowcf.dll library and to reference it. you'll find it somewhere on the net.

hope his helped.
 
Im sorry but I am not a programmer. Where do I put something like this? Does it go into the unbound's properies as an expression? And if so, can I substitute number in (number,place) with the actual field I want to convert?
 
OK.

When You downloaded this msowcf.dll, follow these steps:

1. copy it to every PC's C:\Windows\system32\ folder that will use DEC2HEX function;
2. on every PC' Access Copy that will use DEC2HEX function, you'll have to register reference to this dll this way: (1) open blank (or existing db), choose Modules and Click New module, (2) from menu select Tools -> References, (3) in References dialog choose Browse and point to C:\windows\system32\msowcf.dll and press Open. After that, on References dialog press OK.
3. Now that you made reference to it, you can use it's methods and functions including upper one (DEC2HEX).

Yes, You can substitute number easily and write it like:
a$ = DEC2HEX(Me.FieldName,11)
or

dim numToConv as long, result as string
numToConv = Me.FieldName
result = DEC2HEX(numToConv,13)

asuming that FieldName is name of Text Input Box on Your form that contains number to be converted.

that's it.
 
How are ya RnRExpress . . . . .

Problem is, [blue]almost all methods[/blue] one can use to resolve a Hex Value [blue]are limited to Long Integers[/blue] (as you've found out). Other restrictions along the same lines make it just as hard, for instance; [blue]you can not BitMask a value greater than Long Integer[/blue] . . . .

Be aware: [purple]Resolution not Accuracy starts to fall off above 17 significant digits.[/purple] This is a problem with [blue]many Hex Converters[/blue] when handling large values. So restrict your input accordingly.

The following method is purely mathamatical and should give you what you want.

In the AfterUpdate event of your input TextBox copy/paste the following code (you substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Me![purple][b]enxt[/b][/purple] = GetHex(Me![purple][b]InputTextBoxName[/b][/purple])[/blue]
Next in a module in the modules window copy/paste the following:
Code:
[blue]Public Function GetHex(ByVal strVal) As String
   
   If Len(Trim(strVal) & "") > 0 And IsNumeric(strVal) Then
      Dim srcVal As Double, divVal As Double, Build As String
      Dim intHold As Double, Remainder As Integer
      
      Const Mask As Integer = 16
      srcVal = Val(Me!strVal)
      
      Do
         divVal = srcVal / Mask
         intHold = Int(divVal)
         Remainder = srcVal - intHold * Mask
         srcVal = intHold
         Build = Hex(Remainder) & Build
      Loop Until srcVal = 0
      
      GetHex = Build
   End If

End Function[/blue]
Thats it . . . . give it a whirl and let me know . . . .

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan,

Couple of other questions.

Most of the code in my form now has "me." instead of "me!" is this ok?

Second, that should I be typing instead of ENXT in your code? The field I am taking the number from is called "Customer_ESN" and the field I want to populate is "Customer_ESN_Hex"


I changed your first code to:
Me!enxt = GetHex(Me!Custoemr_ESN)

but I dont understant what to replace ENXT with.

Also, I did save the module code.

Thanks for the assistance.
 
Have you tried this ?
Me!Customer_ESN_Hex = GetHex(Me!Custoemr_ESN)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

I was playing around with that, I no mater what I do, now I get a runtime error after putting that line in the event for AfterUpdate of the Customer_ESN textbox.

The error is:

Runtime Error 2465

Database can't find the field 'Customer_ESN' referred to in your expression.

Now I am totally confused since this field does exist :)

.
 
Me!Custoemr_ESN is a control, not a field.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

You have to forgive me since I am not a well versed user/programmer of Access.

Ok, its a control and not a field. Either way, why am I getting the message that field Customer_ESN does not exist. Granted that its actually Custoemr ESN (space, not an _ between the words).
 
Some guesses:
Me!Customer_ESN_Hex = GetHex(Me!Custo[highlight]me[/highlight]r_ESN)
Me!Customer_ESN_Hex = GetHex(Me![Customer ESN])
Me![Customer ESN Hex] = GetHex(Me![Customer ESN])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
[blue]PHV . . . . .

Thanks for the assist!
[/blue] ;-)

Calvin.gif
See Ya! . . . . . .
 
Hey guys,

I apreciate the help.

I used the following now:
Me![Customer ESN Hex] = GetHex(Me![Customer ESN])

But now instead of the previous error about not finding that field, I now get a diff error.

Compile error: Invalid use of Me keyword.

This is the code I cut & pasted from an earilier reply.

Public Function GetHex(ByVal strVal) As String

If Len(Trim(strVal) & "") > 0 And IsNumeric(strVal) Then
Dim srcVal As Double, divVal As Double, Build As String
Dim intHold As Double, Remainder As Integer

Const Mask As Integer = 16
srcVal = Val(Me!strVal) <<<< This is the Me! thats
highlighted in the
debugger

Do
divVal = srcVal / Mask
intHold = Int(divVal)
Remainder = srcVal - intHold * Mask
srcVal = intHold
Build = Hex(Remainder) & Build
Loop Until srcVal = 0

GetHex = Build
End If

End Function
 
RnRExpress . . . . .

I'm at work and its hard getting back here.

Yes your right (I copied code & posted before correcting exactly what you've pointed out. [blue]strVal[/blue] receives the passed variable, so yes . . . there's no Me.
Code:
[blue]Change: srcVal = Val([purple][b]Me!strVal[/b][/purple])
    To: srcVal = Val([purple][b]strVal[/b][/purple])[/blue]
So there's no more confusion on what names to use, in the properties for each control, goto the [blue]Other Tab[/blue]. Right at the top is the [purple]Name Property[/purple]. This is the name you should be using. When you field/control names in code, if they contain any spaces you must surround the names with brackets [purple][][/PURPLE]. So a control name of say [blue]First Name[/blue] could take three forms:
Code:
[blue]  FirstName
 [purple][b][[/b][/purple]First Name[purple][b]][/b][/purple]
  First_Name[/blue]
Let me know how ya make out . . . .

Calvin.gif
See Ya! . . . . . .
 
Hey AceMan,

That did it. Thank you guys so much!!!

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top