views:

291

answers:

2

this is the code i used to display image in the header. the problem i have is i want to use a variable for the image, when i put the variable name instead of the image name i get an error:

Microsoft JScript runtime error '800a138f'

'undefined' is null or not an object

/EKtestdb/fpdf/fpdf/includes/Basics.asp, line 121

    this.Header=function Header() 
  { 
  this.SetY (10) 
  this.SetFont ("Times","",10) 
  //this.Cell (45,5, "HEADER", 0, 0, "L") 
  this.SetFont ("Times","b",14) 
  //this.Cell (190,5, this.title, 0, 0, "C") 
  this.Cell (190,20, this.title, 0, 0) 
  this.SetFont ("Times","",10) 
  this.Image('logoSM1.jpg',165,3,33) 
  this.Image( techpic ,165,3,33)

this is the code for basics.asp line 121:

this.strrpos=function strrpos(s,ch){ 
 res = s.lastIndexOf(ch) 
 if (res>0-1){return res}else{return false} 
} 
this.strpos=function strpos(s,ch,start){ 
 if (arguments.length<3){start=0} 
 res = s.indexOf(ch,start); 
 if (res>-1){return res}else{return false} 
}

if you just want to display an image this line should work:

this.Image('logoSM1.jpg',165,3,33)

but for using a variable instead of image name can someone help with this?

A: 

I am updating my answer, because I didn't realize you are using both JScript and VBscript. You don't need to add the <%=%> because all your code is already in <%%> on the Jscript side.

I am not sure why you are getting the problem, but looking at the code you added I don't see a LoadModels(), which the documentation for fpdf says you need if you are using a vbscript page.

http://www.aspxnet.it/public/Default.asp?page=174&amp;idp=62

Also I am not sure if it matters, but maybe you can add an opening and closing single quotation marks:

this.Image( "'" + techpic + "'" ,165,3,33);

I also noticed that none of the code under this.Header=function Header() contains semicolons after them, which is required for JSCript.

Waleed Al-Balooshi
I could not get it to workyes the variable is an ASP variable, I tried the code above and it would not work it gave me the message:FPDF error: Image file has no extension and no type was specified: here is a sample of the asp code please let me know if you need to see more:Set pdf=CreateJsObject("FPDF")pdf.CreatePDF()pdf.SetPath("fpdf/")'------pdf.SetFont "Arial","",16pdf.Open()pdf.AddPage()Dim techpictechpic = "logoSM1.jpg"if (objRS.EOF) thenelse Do Until objRS.EOF = True EmployeeNo = objRS("EmployeeNo")
bluffo
@bluffo I updated my answer, because I thought you were mixing javascript and vbscript, but it is actually JScript, so you don't need the <%=%>.
Waleed Al-Balooshi
I noticed there are no semicolons as well I added them and without the image it does load faster, but I still could not get the image to work this time error msg was different:FPDF error: Image file has no extension and no type was specified: 'undefined'I can post more samples of the code if you need thanks for helping I tried to post this question in another forum and they said Im using the wrong forum.Microsoft JScript runtime error '800a138f''undefined' is null or not an object/EKtestdb/fpdf/fpdf/includes/Basics.asp, line 121
bluffo
@bluffo this is kind of a shot in the dark, but try this.Image( eval(techpic) ,165,3,33) OR this.Image( eval('techpic') ,165,3,33)
Waleed Al-Balooshi
Ok I finally got it working the problem was with my Dim techpic declaration for some reason I had to move it up to the first asp section before the select and the variable = objRS im not sure why but at least it works now. Thank you Waleed for your responses you help me to figure it out, and to anyone else having problems I hope this helps you.
bluffo
@bluffo you should add an answer with what you did and accept it. That way if someone has the same problem they can see the answer directly rather than have to look at the comments.
Waleed Al-Balooshi
Ok I posted the answer I cant mark my own question as answer but at least its there so people can read it. Thanks again Waleed for your response it gave me a new ideal to think about the problem. I would mark yours as answer but I dont have enough reputation yet.
bluffo
A: 

The problem I had was with the variable declaration I am not sure why but I had to declare the variable in the first section of the pdf.asp file to output a variable in the header. For ouputting in the footer this was not the case and I am still unsure why here is a sample of the fpdf.asp code:

this.Header=function Header()
        {
        this.SetY (10);
        this.SetFont ("Times","b",14);
        this.Cell (190,20, this.title, 0, 0);
        this.SetFont ("Times","",10);
        //this.Image('logoSM1.jpg',165,3,33);
        this.Image( techpic2 ,165,3,33);
        }
    this.Footer=function Footer()
        {
        this.SetY (-15)
        this.SetFont ("Times","i",10)
        this.Cell (190, 5, "", 0, 1)
        this.Cell (190, 0, "", 1, 1)
        this.Cell (45, 5, EmployeeName + " - " + EmployeeNo, 0, 0, "L")
        this.Cell (100, 5, this.PageNo() + "/{nb}", 0, 0, "C")
        this.Cell (45, 5, "", 0, 0, "R")            
        }

In the code above the footer will retrieve the value of EmployeeName and output correctly but in the header the value of techpic2 would not be retrieved. In the line above techpic2 the image was successfully displayed here is a sample of the pdf.asp code:

strSQL = "SELECT * FROM employee_course_vendortraining_view "  

objRS.Open strSQL, objConn

%>

<!--#include file="fpdf.asp"-->

<%

Set pdf=CreateJsObject("FPDF")

pdf.CreatePDF()

pdf.SetPath("fpdf/")

'------pdf.SetFont "Arial","",16

pdf.Open()

pdf.AddPage()


if (objRS.EOF) then

else

    Do Until objRS.EOF = True

    EmployeeNo = objRS("EmployeeNo")
    EmployeeName = objRS("EmployeeName")
     techpic2 = objRS("techpic2") 

Here the variables are all assigned the value from the recordset this was working for ouputting from the footer but would not work for the header. But once I declared and set the variables in the example below the header would output correctly:

strSQL = "SELECT * FROM employee_course_vendortraining_view "  

    objRS.Open strSQL, objConn
Dim EmployeeName
    EmployeeName = objRS("EmployeeName")
Dim techpic2
    techpic2 = objRS("techpic2")
    %>

    <!--#include file="fpdf.asp"-->

    <%

    Set pdf=CreateJsObject("FPDF")

    pdf.CreatePDF()

    pdf.SetPath("fpdf/")

Why the footer could read the variable but not the header I am still not sure why but if anyone else is having problems maybe this will help.

bluffo