From Delphi to VB

  • Thread starter Thread starter Henry
  • Start date Start date
H

Henry

Can anybody assist to translate this for me, just moving over from delphi

function IntToIp(Address: LongWord): string;
begin
Result := Format('%d.%d.%d.%d', [
Address shr 24 and $ff,
Address shr 16 and $ff,
Address shr 8 and $ff,
Address shr 0 and $ff]);
end;

cheers
Henry
 
Hello Henry,

You can easily use the IPAddress class (In System.Net namesapce) for this...

Dim tAddressLong as Int64 = (YOUR INT64 ADDERSS HERE)
Dim tAddress as IPAddress=New IPAddress(tAddressLong)

tAddress.ToString() will give you the dotted format.

Note that the IPAddress ctor expects tAddressLong to be in network byte order
(Big Endian). If your tAddressLong is in Little Endian byte order then the
IPAddress class provides funcions for converting it.

If you really wanna write yer own then you want to use the bit shifting operators
( << for shift-left, and >> for shift-right )

-Boo
 
If you really wanna write yer own then you want to use the bit shifting
operators

I absolutlly don't want to do this myself if there's an existing method for
it somewhere,

I need the first IP Address in the subnet of a IP address given a subnet
mask

eg

subnet mask is given 255.255.255.240, that results in 16 subnets with 14 IP
addresses each.

I need to identify from which subnet I receive a client connection from, eg

any IP address from 192.169.1.1 to 192.169.1.14 comes from subnet
192.169.1.0 (first IP address is 192.169.1.1)
I need result 192.169.1.0

any IP address from 192.169.1.17 to 192.169.1.30 comes from subnet
192.169.1.16 (first IP address is 192.169.1.17)
I need result 192.169.1.16

any IP address from 192.169.1.13 to 192.169.1.46 comes from subnet
192.169.1.32 (first IP address is 192.169.1.33)
I need result 192.169.1.32

and so forth

Do you understand?

Is there an easy way to get that address?

cheers
Henry
 
Hello Henry,

Nope, I don't understand. A subnet is just a bitmask that partitions off
the network portion from the host portion of an address.. as such, your example
subnets dont make any sense.

I had originally thought your function was trying to convert the integer
representation of an IP address into the dotted notation. Anyhow, since
you seem to understand what yer doing just use the bit shifting operators
and you can convert your old Deli code.

-Boo
 
Back
Top