Click to See Complete Forum and Search --> : less bulky / more efficient code


catchup
02-04-2005, 03:04 PM
i really need to have things run more effecient. currently
i have a function that numbers cells on a page retreived by aspTear, and the cell numbers never change, this part of the code is fine, since i found it on the net:

Function GetCell(cellnumber, extracturl)

Const Request_POST = 1
Const Request_GET = 2

Set xObj = Server.CreateObject("SOFTWING.AspTear")
strRetVal = xObj.Retrieve(extracturl,Request_GET,"","","")
set xobj = nothing

i = 1 ' HTML Text Location Start
q = 1 ' Cell Number Start

' Loop until we have processed the cell we're looking for
Do until q > cellnumber
' Look for <TD the start of a cell
i = InStr(i, UCase(strRetVal), "<TD")

' Find the location of the end of the <TD tag
r = InStr(i, strRetVal, ">")

' Let the next loop start looking after this <TD tag we found
i = r + 1

' increase the count of which cell we're at
q = q + 1
Loop

' The start of our cell text is right after the last found tag
StartCellText = i

If (InStr(r, UCase(strRetVal), "<TABLE") > 0) AND _
(InStr(r, UCase(strRetVal), "<TABLE") < _
InStr(r, UCase(strRetVal), "</TD>")) then
ThisCellText = mid(strRetVal, StartCellText, _
InStr(r, UCase(strRetVal),"<TABLE")- StartCellText )
Else
ThisCellText = mid(strRetVal, StartCellText, _
InStr(r, UCase(strRetVal), "</TD>")- StartCellText )
End If

GetCell = ThisCellText
End Function



Then since i need the info from may cells and i not a smart programmer i'm doing things an ugly way:

variable44 = GetCell(44, "http://www.company.com/page.asp")
variable45 = GetCell(45, "http://www.company.com/page.asp")
variable47 = GetCell(47, "http://www.company.com/page.asp")
variable49 = GetCell(49, "http://www.company.com/page.asp")
variable57 = GetCell(57, "http://www.company.com/page.asp")
variable58 = GetCell(58, "http://www.company.com/page.asp")
variable60 = GetCell(60, "http://www.company.com/page.asp")
variable62 = GetCell(62, "http://www.company.com/page.asp")

.....all the way up to cell 1071......

variable1071 = GetCell(1071, "http://www.company.com/page.asp")

so how can things be so that variables are created with the cells info without making a request to the aspTear each time?

thanks!

lmf232s
02-04-2005, 03:26 PM
This might work.

Dim Variable(1071)

For i = 1 to UBound(Variable)
Variable(i) = GetCell(i, "http://www.company.com/page.asp")
Next

catchup
02-04-2005, 04:15 PM
hmm... if i understand your code correctly, it still is making a request to the aspTear for each cell number, i was kinda looking for a way to "cache" the cell numbers after only 1 request to the aspTear.

any thought on this...

lmf232s
02-04-2005, 04:19 PM
ok, i see, i thought you wanted to keep from typing out all that code.
and yes my approach still make a call to ASPterr ? for each cell.

im not sure but to do what you want to do you might want to look into xml

catchup
02-04-2005, 05:13 PM
i guess i'm looking to get multiple cells in one pass and puts them into dictionary object

any idea on how this is done?

lmf232s
02-04-2005, 05:21 PM
well it looks like you are calling it as a function and
passing it 2 variables (some number and a address).

I dont think you are going to be able to call it once and retreive
all the values that you want. But what you might be able to do is
create a xml sheet, where the code would be ran for 1-1700 records
and store a cached copy of them, now instead of call the function
like you do you would, you would use the xml page that already has the data.

Again i am not for sure on this, but i think xml would do what you
are asking for. Other then that i dont now, you are calling a function it looks like and that function can only return 1 value.
If you have the source code to the function (ASPterr) then you might be able to modify the function to return what you want.

catchup
02-04-2005, 06:21 PM
well if got it going with the xml idea, and its so far 4 times faster than the tear dll
But i'm still calling the scrapping for each call of the function, and idea how to fix this - to have just 1 call...


Response.Buffer = True

Function GetCell(cellnumber)

Dim objXMLHTTP, xml
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
xml.Open "GET", "http://www.company.com/page.asp", False
xml.Send
strRetVal = xml.responseText

Const Request_POST = 1
Const Request_GET = 2

i = 1
q = 1

Do until q > cellnumber
i = InStr(i, UCase(strRetVal), "<TD")
r = InStr(i, strRetVal, ">")
i = r + 1
q = q + 1
Loop

StartCellText = i

If (InStr(r, UCase(strRetVal), "<TABLE") > 0) AND _
(InStr(r, UCase(strRetVal), "<TABLE") < _
InStr(r, UCase(strRetVal), "</TD>")) then
ThisCellText = mid(strRetVal, StartCellText, _
InStr(r, UCase(strRetVal),"<TABLE")- StartCellText )
Else
ThisCellText = mid(strRetVal, StartCellText, _
InStr(r, UCase(strRetVal), "</TD>")- StartCellText )
End If

GetCell = ThisCellText
Set xml = Nothing
End Function