Avatar of mcrmg
mcrmg
 asked on

Class in vbscript

Hi,

I would like to use this code, how can I pass an IP to the function?  thx
<%


class browserLocaleObject

public ip
public countryCode
public countryName
public regionCode
public regionName
public city
public zipPostalCode
public latitude
public longitude
public timeZone
public GMTOffset
public DSTOffset


private sub Class_Initialize
Dim objXMLHTTP
Dim coordinates
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
 ip = Request.ServerVariables("REMOTE_ADDR")


Response.Write ip
' objXMLHTTP.Open "GET", "http://api.hostip.info/?ip="&ip, False
objXMLHTTP.Open "GET", "http://ipinfodb.com/ip_query.php?ip="&ip, False
objXMLHTTP.Send
Set xmldoc = objXMLHTTP.responseXML
on error resume next
' countryCode = xmldoc.selectSingleNode("HostipLookupResultSet/gml:featureMember/Hostip/gml:name").text
countryCode = xmlDoc.documentElement.selectSingleNode("CountryCode").text
countryName = xmlDoc.documentElement.selectSingleNode("CountryName").text
regionCode = xmlDoc.documentElement.selectSingleNode("RegionCode").text
regionName = xmlDoc.documentElement.selectSingleNode("RegionName").text
city = xmlDoc.documentElement.selectSingleNode("City").text
zipPostalCode = xmlDoc.documentElement.selectSingleNode("ZipPostalCode").text
latitude = xmlDoc.documentElement.selectSingleNode("Latitude").text
longitude = xmlDoc.documentElement.selectSingleNode("Longitude").text
timeZone = xmlDoc.documentElement.selectSingleNode("Timezone").text
GMTOffset = xmlDoc.documentElement.selectSingleNode("Gmtoffset").text
DSTOffset = xmlDoc.documentElement.selectSingleNode("Dstoffset").text
set objXMLHTTP=Nothing
End Sub


Public Sub Spill
Dim out
out = "<table id=""tSpill"">"
out = out & "<colgroup><col id=""cLeft""><col id=""cRight""></colgroup>"
out = out & "<tr><td>IP</td><td>" & ip & "</td></tr>"
out = out & "<tr><td>Country Code</td><td>" & countryCode & "</td></tr>"
out = out & "<tr><td>Country Name</td><td>" & countryName & "</td></tr>"
out = out & "<tr><td>Region Code</td><td>" & regionCode & "</td></tr>"
out = out & "<tr><td>Region Name</td><td>" & regionName & "</td></tr>"
out = out & "<tr><td>City</td><td>" & city & "</td></tr>"
out = out & "<tr><td>ZipPostalCode</td><td>" & zipPostalCode & "</td></tr>"
out = out & "<tr><td>Latitude</td><td>" & latitude & "</td></tr>"
out = out & "<tr><td>Longitude</td><td>" & longitude & "</td></tr>"
out = out & "<tr><td>Timezone</td><td>" & timeZone & "</td></tr>"
out = out & "<tr><td>GMT Offset</td><td>" & GMTOffset & "</td></tr>"
out = out & "<tr><td>DST Offset</td><td>" & DSTOffset & "</td></tr>"
out = out & "</table>"
Response.Write out 
End Sub
End class

Dim browserLocale
Set browserLocale = new browserLocaleObject
%>

Open in new window

ASPVB Script

Avatar of undefined
Last Comment
strickdd

8/22/2022 - Mon
strickdd

Function MyFucntion(param1, param2)

End Function
mcrmg

ASKER
this is what I have

I can pass the IP, but how can I get the ip within the class?  thx
Public Sub setMyIP(vCriteria) 
	getIP = vCriteria
End Sub

Public Property Let getIP(sIP) 
    ipinit = sIP
    Response.Write "LET:" & ipinit & "<BR>"
End Property 

Public Property Get getIP() 
    getIP = getIP
End Property 





browserLocale.setMyIP("12.34.56.78")

Open in new window

strickdd

If you are wanting to specify a Property, it is like this:

        Public Property Let IPAddress(inValue)
            ip = inValue
      End Property
      Public Property Get IPAddress()
            IPAddress= ip
      End Property

To reference it in the class, you can just use the variable "ip"
Your help has saved me hundreds of hours of internet surfing.
fblack61
mcrmg

ASKER
okay, it can print out ip in LET, but it is empty in GET,

private sub Class_Initialize
Dim objXMLHTTP
Dim coordinates
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
 'ip = Request.ServerVariables("REMOTE_ADDR")


Response.Write IPAddress

thx
Public Property Let IPAddress(inValue)
      ip = inValue
      Response.Write "LET:" & ip & "<BR>"
End Property

Public Property Get IPAddress()
      IPAddress= ip
      Response.Write "GET:" & IPAddress & "<BR>"
End Property

Open in new window

mcrmg

ASKER
I am sorry, I just realized that it is still not working.  I can get ip in class except in private sub Class_Initialize, any ideas?  thx
strickdd

The Class_Initialize function is called before setting the IPAddress property and is used to set the default values of the variables in the class. I believe you can create a constructor for the class that takes in the IPAddress value and sets the property.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mcrmg

ASKER
is there a way that u can show me how to do this?  

btw, I have requested to reopen this q..thx
ASKER CERTIFIED SOLUTION
strickdd

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.