Home > Software engineering >  VB use pure database query IP belongs to position is not normal
VB use pure database query IP belongs to position is not normal

Time:12-22

O great god debug modify
 Public Function GetAddress (sip) 
If Len (sip) & lt; 5 Then
GetAddress="IP input error!"
The Exit Function
End the If
On the Error Resume Next
Dim Wry, IPType
The Set Wry=New ShowIp
If Not Wry. IsIp (sip) Then
GetAddress="IP input error!"
The Exit Function
End the If
IPType=Wry. QQWry (sip)
GetAddress=Wry. Country & amp; "" & amp; Wry. LocalStr
End the Function
Private Sub Command1_Click () 'query address
Text1. Text=GetAddress (Text2)
End Sub
'class module, named ShowIp
'============================================
'variable name
'============================================
Public Country, LocalStr, Buf, OffSet
Private StartIP, EndIP, CountryFlag
Public QQWryFile
Public FirstStartIP LastStartIP, RecordCount
Private Stream, EndIPOff
'============================================
'class module initialization
'============================================
Private Sub Class_Initialize ()
On the Error Resume Next
Country=""
LocalStr=""
StartIP=0
EndIP=0
CountryFlag=0
FirstStartIP=0
LastStartIP=0
EndIPOff=0
QQWryFile="QQWry. Dat" 'QQ IP library path
End Sub
'============================================
'IP address is converted to an integer
'============================================
The Function Iptoint (IP) As Single
Dim IPArray, I, Iptoint1 As Single, Iptoint2 As Single, Iptoint3 As Single, Iptoint4 As Single
IPArray=Split (IP, "", 1)
For I=0 To 3
If Not IsNumeric (IPArray (I)) Then IPArray (I)=0
If CInt (IPArray (I)) & lt; 0 Then IPArray (I)=Abs (CInt (IPArray (I)))
If CInt (IPArray (I)) & gt; 255 Then IPArray (I)=255
Next
Iptoint1=CInt (IPArray (3))
Iptoint2=CInt (IPArray (2)) : Iptoint2=Iptoint2 * 256
Iptoint3=CInt (IPArray (1)) : Iptoint3=Iptoint3 * 256: Iptoint3=Iptoint3 * 256
Iptoint4=CInt (IPArray (0)) : Iptoint4=Iptoint4 * 256: Iptoint4=Iptoint4 * 256: Iptoint4=Iptoint4 * 256
Iptoint=Iptoint1 + Iptoint2 + Iptoint3 + Iptoint4
'this algorithm will have overflow in VB? Don't know what reason Iptoint=((CInt (IPArray (0)) * 256 * 256 + CInt (IPArray (1)) * 256 + CInt (IPArray (2))) * Iptoint + CInt (IPArray (3))
End the Function
'============================================
'integer reverse IP address
'============================================
The Function IntToIP (IntValue)
P4=IntValue - Fix (IntValue/256) * 256
IntValue (IntValue - p4)/256=https://bbs.csdn.net/topics/
P3=IntValue - Fix (IntValue/256) * 256
IntValue=https://bbs.csdn.net/topics/(IntValue - p3)/256
The p2=IntValue - Fix (IntValue/256) * 256
IntValue=https://bbs.csdn.net/topics/(IntValue - p2)/256
P1=IntValue
IntToIP=CStr (p1) & amp; ". "& amp; CStr (p2) & amp; ". "& amp; CStr (p3) & amp; ". "& amp; CStr (p4)
End the Function
'============================================

'get started IP position
'============================================
Private Function GetStartIP (RecNo)
OffSet=FirstStartIP * 7 + RecNo
Stream. The Position=OffSet
Buf=Stream. Read (7)

FirstStartIP1=AscB (MidB (Buf, 1, 1))
FirstStartIP2=AscB (MidB (Buf, 2, 1)) : FirstStartIP2=FirstStartIP2 * 256
FirstStartIP3=AscB (MidB (Buf, 3, 1)) : FirstStartIP3=FirstStartIP3 * 256: FirstStartIP3=FirstStartIP3 * 256
FirstStartIP4=AscB (MidB (Buf, 4, 1)) : FirstStartIP4=FirstStartIP4 * 256: FirstStartIP4=FirstStartIP4 * 256: FirstStartIP4=FirstStartIP4 * 256
StartIP=FirstStartIP1 + FirstStartIP2 + FirstStartIP3 + FirstStartIP4

LastStartIP1=AscB (MidB (Buf, 5, 1))
LastStartIP2=AscB (MidB (Buf, 6, 1)) : LastStartIP2=LastStartIP2 * 256
LastStartIP3=AscB (MidB (Buf, 7, 1)) : LastStartIP3=LastStartIP3 * 256: LastStartIP3=LastStartIP3 * 256
'LastStartIP4=AscB (MidB (Buf, 8, 1)) : LastStartIP4=LastStartIP4 * 256: LastStartIP4=LastStartIP4 * 256: LastStartIP4=LastStartIP4 * 256
EndIPOff=LastStartIP1 + LastStartIP2 + + LastStartIP4 LastStartIP3 '

'this algorithm will have overflow in VB? Don't know what reason EndIPOff=AscB (MidB (Buf, 5, 1)) + (AscB (MidB (Buf, 6, 1)) * 256) + (AscB (MidB (Buf, 7, 1)) * 256 * 256)
'this algorithm will have overflow in VB? Don't know what reason StartIP=AscB (MidB (Buf, 1, 1)) + (AscB (MidB (Buf, 2, 1)) * 256) + (AscB (MidB (Buf, 3, 1)) * 256 * 256) + (AscB (MidB (Buf, 4, 1)) * 256 * 256 * 256)
GetStartIP=StartIP
End the Function
'============================================
'get over IP position
'============================================
Private Function GetEndIP ()
Stream. The Position=EndIPOff
Buf=Stream. Read (5)

FirstStartIP1=AscB (MidB (Buf, 1, 1))
FirstStartIP2=AscB (MidB (Buf, 2, 1)) : FirstStartIP2=FirstStartIP2 * 256
FirstStartIP3=AscB (MidB (Buf, 3, 1)) : FirstStartIP3=FirstStartIP3 * 256: FirstStartIP3=FirstStartIP3 * 256
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related