This is my function that converts an IP Address to a 32 Bit Decimal Word (I only use this once in the beginning of the Class. I then do not convert back until the very end of the class run.
Private Function fConvert_8BitDecimalTo32BitDecimal(Octet1 as UInt32, Octet2 as UInt32, Octet3 as Uint32, Octet4 as UInt32) As UInt32
// Convert IP Address 8 bit Decimal to 32 bit decimal base10
dim Base10IP,a,b,c,d as UInt32
a = Octet1 * 16777216
b = Octet2 * 65536
c = Octet3 * 256
d = Octet4
Base10IP = a+b+c+d
Return Base10IP
End Function
This Function runs at the end and Converts the 32bit decimal words back into an IP Address. I am still trying to make this one more efficient, but so far so good.
Private Function fConvert_32BitDecimalTo8Bit_IP(Inbound_32BitWordDecimal as UInt32) as string
// Convert 32 bit decimal base10 back to IP Address 8 bit Decimal
Dim Calc1, Calc2, Octet1, Octet2, Octet3, Octet4, Base10IP As UInt32
Dim DecimalAddressParts(), DecimalAddress As String
Dim counter As Integer
Base10IP = Inbound_32BitWordDecimal
For i As Integer = 0 To 3
counter = 3-i
Calc1 = Base10IP / 256^counter
Base10IP = Base10IP - Calc1*(256^counter)
Select Case i
Case 0
Octet1 = Calc1
Case 1
Octet2 = Calc1
Case 2
Octet3 = Calc1
Case 3
Octet4 = Calc1
End Select
Next i
DecimalAddressParts=Array(Str(Octet1),Str(Octet2),Str(Octet3), Str(Octet4))
DecimalAddress =Join(DecimalAddressParts,".")
Return DecimalAddress
End Function
Phew “Lazy Loading” my listbox completely gives me demo app an instant loading feel and loads as you scroll without any hesitation. I am loading over 4million lines
[quote=66502:@Mike Cotrone]This is my function that converts an IP Address to a 32 Bit Decimal Word (I only use this once in the beginning of the Class. I then do not convert back until the very end of the class run.
[code]
Private Function fConvert_8BitDecimalTo32BitDecimal(Octet1 as UInt32, Octet2 as UInt32, Octet3 as Uint32, Octet4 as UInt32) As UInt32
// Convert IP Address 8 bit Decimal to 32 bit decimal base10
dim Base10IP,a,b,c,d as UInt32
a = Octet1 * 16777216
b = Octet2 * 65536
c = Octet3 * 256
d = Octet4
Base10IP = a+b+c+d
Return Base10IP
End Function
[/code][/quote]
In this and the other function, use a memoryblock to eliminate all the math.
Do…Loop is a bit faster than While…Wend from what I measured when I was implementing the QuickSort algorithm. While…Wend took about 10% to 15% more time.
I never compared For…Next to Do…Loop or While…Wend.
I had interesting results from comparing If…ElseIf To Select…Case, where sometimes If…ElseIf was significantly faster than Select…Case (tested with 10 to 20 Cases/ElseIfs). Select…Case was never faster, but sometimes as fast as If…ElseIf. But I can’t say in which circumstances If…ElseIf is faster - I have to test in each time I’m implementing something specific.