Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't seem to get function to work!

Status
Not open for further replies.

craigey

Technical User
Joined
Apr 18, 2002
Messages
510
Location
GB
Hi Guys / Gals,

I've been trying to get a function that checks the warranty details from Hp/Compaq, but I keep getting strange errors (such as Invalid procedure call or argument: 'Mid') or getting status:%20%20-?Model=zzzxzxzx&sn=cvcvxvxs in the status bar??

I don't quite know how to incorporate the funuction into a search. Just hoped one of you may be able to helpl me out.

Thanks in advance.

The function is below:
Code:
    function WarrantyCheck(serialnumber, model)
    	'on Error Resume Next
    	pn = ""
    	if Len(trim(serialnumber)) <= 10 Then
    		pn = Whatstheproductnumber(model)
    	End if
    	Dim hugeArr, minfo
    	Dim returnStr, strInfo
    	'minfo= split(sn, ",")
   	sn = serialnumber
    	
    	url="[URL unfurl="true"]http://h20000.www2.hp.com/bizsupport/TechSupport/WarrantyResults.jsp?prodSeriesId=316664&prodTypeId=321957&sn="[/URL] & sn & "&pn=" & pn & "&country=US&nickname=&nickname2=&source=single&x=38&y=13&locale=en_US"
    	Set objHTTP = CreateObject("MSXML2.XMLHTTP")
    	
    	Call objHTTP.Open("GET", url, FALSE)
    	objHTTP.Send
    	
    	returnStr = objHTTP.ResponseText
    	
    	hugeArr = Split(returnStr,"OVERALL START DATE")
    	
    	'---[ info starts at hugeArr(1)
    	StrInfo = Mid(hugeArr(1),1,1100)
    	
    	'---[ warranty start Date
    	startdate = InStr(StrInfo, "<TD width=350>")
    	warranty_start_date = Mid(StrInfo, startdate + 14,11)
    	
    	'---[ warranty status
    	status = InStr(strInfo, "<TD><B><FONT color")
    	wtstatus = Mid(strInfo,status+18,50)
    	tmp1 = InStr(wtstatus,">") + 1
    	tmp2 = InStr(wtstatus,"<")
    	
    	warranty_status = Mid(wtstatus,tmp1,tmp2-tmp1)
    	
    	'---[ warranty End Date
    	endd = InStr(strInfo, "<B>End Date</B>")
    	tmp = Mid(strInfo,endd,100)
    	tmp1 = InStr(tmp,"<TD width=350>") + 14
    	warranty_end_date = trim(Mid(tmp,tmp1,15))
    	
    	w_stat = IIF(warranty_status="Expired", "Ended on: ", "Ends on: ")
    	WarrantyCheck = "Status: " & warranty_status & " - " & w_stat & Replace(warranty_end_date,Chr(10),"")
    End function
    function Whatstheproductnumber(modelin)
    	' Evo N610c 470050-020						= 470050-20
    	' HP Compaq nc6000 (DH913U#ABA)			= DH913U#ABA
    	' Evo N610c 279941-999 					= 279941-999
    	' HP d530 CMT(DG767A)						= DG767A
    	' Compaq Deskpro							= DESKPRO
    	modelin = trim(Replace(modelin,"("," "))
    	modelin = trim(Replace(modelin,")"," "))
   	modelin = Mid(modelin, InStrRev(modelin," "))		
    	Whatstheproductnumber= modelin
    End function
 
Mid needs 3 thinks, the string, the start position and the number of characters to count forward

so if your string is abcdefg
mid(str,2,4)
would give you
bcde (start at the second character ("b") and count forward 4 characters

so modelin = Mid(modelin, InStrRev(modelin," "))
does not have the right number of arguments.
try commenting it out and seeing what happens

}...the bane of my life!
 
Thanks. I've already tried commenting it out, but I then get: Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 1]'
/anprcontacts/warranty.asp, line 50

I commented out StrInfo = Mid(hugeArr(1),1,1100)
& then got:
Invalid procedure call or argument: 'Mid' on line 62, so commented out warranty_status = Mid(wtstatus,tmp1,tmp2-tmp1)

then I got the same error on 66, so commented out tmp = Mid(strInfo,endd,100)

I then got Type mismatch: 'IIF'
/anprcontacts/warranty.asp, line 70 so (can you guess what I did on line 70)..

Finally the page, worked. Well it appeared, but desn't actually do anything.

The code I'm using to try to input the model & Serial & display the result is below:

Code:
<HTML>
<!--<BODY BGCOLOR=White TEXT=Blue LINK=Red Vlink=blue ALink=black> -->
<TITLE>Warranty Search</TITLE>
<link rel="stylesheet" type="text/css" href="test4/browse.css">
<CENTER><FONT SIZE=+3>HP/Compaq Warranty Search</FONT></CENTER>
<CENTER>
<!-- <%'<FORM ACTION='<%=warrantycheck(sn, model)%>'>  %> -->

<br><br>
Model Number: <INPUT TYPE='TEXT' NAME='Model'>
Serial Number: <INPUT TYPE='TEXT' NAME='sn'>
<!--<INPUT TYPE='Submit' VALUE='Search'>-->
<INPUT TYPE='Submit' VALUE='<%=warrantycheck(sn,model)%>'>
</FORM>
</CENTER>
 
yep. It's the only one in the whole script.

but I just get a different error when I comment out the incorrect modelin = Mid line.

It eventually complains about another mid command, that does have the 3 arguments.
 
Model=C9264-67903&sn=MXA050408Z
 
The numbers should be:
Serial Number MXA050408Z
Product Number C9264CB
 
>[tt]w_stat = IIF(warranty_status="Expired", "Ended on: ", "Ends on: ")[/tt]
IIF is not supported by vbs.
 
Thanks for that. It's not my code, but a script freely available on planetsourcecode.

I also found someone else has created a function to use IIF on VBSscript, so I've added to the top of the page:

Code:
function iif(psdStr, trueStr, falseStr)
  if psdStr then
    iif = trueStr
  else 
    iif = falseStr
  end if
end function
 
>...a script freely available on planetsourcecode
Don't know what assumption is made there. I would do this for this situation.
>[tt]if psdStr then[/tt]
[tt]if [blue]eval(psdStr)[/blue] then[/tt]
 
Not quite. I'm going through it all now with response.writes trying to figure out what's going on.

I've managed to get most of the stuff to display, but there's some errors in the instr & other code.

At least it no comes up with:

--> Start Date 01 Apr 2005
Wty: HP HW Replacement Support
Status Active
Start Date 01 Apr 2005
End Date 30 May 2006


Just got to sort out some of te formatting etc....
 
I am wrong in my last post. No need to change in this situation.

It only makes some sense if a string version of a statement is passed.
[tt] IIF("warranty_status=""Expired""", "Ended on: ", "Ends on: ")[/tt]
But that's not the case. So I was wrong there.

 
It's ok, I've sorted it all now.

I was just about to award stars to you guys, but I've uncommented out the dodgy bits of code, such as:


modelin = Mid(modelin, InStrRev(modelin," "))

And

IIF("warranty_status=""Expired""", "Ended on: ", "Ends on: ")

And all of these now work. The InstrRev, doesn't seem to require all 3 arguments as it will use the 1st argument as both the 1st & 2nd arguments, if there are only 2 specified.

The problem was the search strings such as
status = InStr(strInfo, "<TD><B><FONT color")
were partially in Caps, yet all the html was in lowercase. Which obviously resulted in null values.

Sorry guys, I apreciate the help, but I think the stars, should go to me this time round!! :-)
 
It's never a matter of concern. Glad you get it done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top