0

这是我用来在标题中显示图像的代码。我遇到的问题是我想为图像使用一个变量,当我输入变量名称而不是图像名称时,我得到一个错误:

Microsoft JScript 运行时错误“800a138f”

'undefined' 为 null 或不是对象

/EKtestdb/fpdf/fpdf/includes/Basics.asp,第 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)

这是 basics.asp 第 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} 
}

如果您只想显示图像,则此行应该有效:

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

但是对于使用变量而不是图像名称,有人可以帮忙吗?

4

2 回答 2

0

我正在更新我的答案,因为我没有意识到您同时使用 JScript 和 VBscript。您不需要添加 <%=%> 因为您的所有代码都已经在 J​​script 端的 <%%> 中。

我不确定你为什么会遇到这个问题,但是查看你添加的代码我没有看到 LoadModels(),fpdf 的文档说如果你使用的是 vbscript 页面,你需要它。

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

我也不确定它是否重要,但也许你可以添加一个开始和结束单引号:

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

我还注意到,下面的代码都没有 this.Header=function Header()在它们之后包含分号,这是 JSCript 所必需的。

于 2010-06-10T18:39:11.760 回答
0

我遇到的问题是变量声明我不知道为什么,但我必须在 pdf.asp 文件的第一部分中声明变量以在标题中输出一个变量。对于在页脚中输出,情况并非如此,我仍然不确定为什么这里是 fpdf.asp 代码的示例:

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")            
        }

在上面的代码中,页脚将检索 EmployeeName 的值并正确输出,但在页眉中将不会检索 techpic2 的值。在 techpic2 上面的行中,图像成功显示在这里是 pdf.asp 代码的示例:

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") 

在这里,变量都被分配了来自记录集的值,这用于从页脚输出,但不适用于页眉。但是,一旦我在下面的示例中声明并设置变量,标题就会正确输出:

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/")

为什么页脚可以读取变量但不能读取页眉我仍然不确定为什么但如果其他人遇到问题也许这会有所帮助。

于 2010-06-11T16:33:20.170 回答