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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting IPX Network (HEX) to IP (Octet) in a Form

Status
Not open for further replies.

jchim32

MIS
Oct 25, 2002
16
0
0
US
I am looking for a way to convert an IPX Network Number (HEX) to IP (Octet) in my Access form. Anyone have any ideas on how this can be done?

Thanks,

Jeff
 
Hi there, could you please give an example of an IPX network number. Is it in the format "12AB3C4D" or "12-AB-3C-4D"

-I don't anything about IPX network numbers :)

Cheers,
DanJR
 
hi there...

here is a way to do it, if the the format of the IPX address is "A5E6C090"

There are two functions. the first function I created and the second is from MSDN.

You may want to add some error checking...

-----
Public Function ConvertIPXtoIP(IPX As String) As String
'accepts IPX Networt number e.g. "A5E6C090"
'Return equivalant IP number e.g. "165.230.192.144"

Dim lng As Long
Dim strIP As String

strIP = ""

For lng = 1 To 8 Step 2
If lng = 1 Then
strIP = HexToLong(Mid(IPX, lng, 2))
Else
strIP = strIP & "." & HexToLong(Mid(IPX, lng, 2))
End If

Next lng

ConvertIPXtoIP = strIP


End Function


Function HexToLong(ByVal sHex As String) As Long
'see website: HexToLong = Val("&H" & sHex & "&")
End Function

------

I hope this helps...

Cheers,
Dan
 
Dan,

Thanks for the reply. The IPX networks are in the format of 12AB3C4D. In your 2nd response you posted what looks to be the exact code I am looking for, only thing is I am not too saavy on VB. Can you explain how I can build this into my form, creating a field in design view and when and where to place the code. By looking at the code above, you are on it, that is exactly the result I'm looking for.

Thanks a bunch,

Jeff
 
Hi Jeff,

1. Copy and paste the two functions into a module.

2. Create a new form. In design view add two textboxes. Call the first textbox "txtIPX" and the second "txtIP". Also add a command button and call it cmdConvert.

3. Now, on the On_Click event of the 'cmdConvert' button, put in the following code (within the forms class module).

---------

Private Sub cmdConvert_Click()
On Error GoTo errConvert

'check txtIPX field contains a 32 bit network address
If Len(txtIPX) <> 8 Then '<--this only check that the IPX has 8 characters (ie simple check)
MsgBox &quot;IPX field does not contain 8 characters&quot;
Me.txtIP = &quot;Unable to convert&quot;
GoTo CleanUp

End If

'do the conversion
Me.txtIP = ConvertIPXtoIP(Trim$(Me.txtIPX.Value))


CleanUp:
Exit Sub

errConvert:
MsgBox &quot;Error in cmdConvert_Click (&quot; & Err.Number & &quot;) &quot; & Err.Description
Resume CleanUp

End Sub

-----------


This example illustrates how to implement the function. Of course, there are many other ways to use it, e.g., put the code on the after_update event of the txtIP field, thus you won't need a command button.


let me know if you want me to clearify anything further.

Cheers,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top