ASP如果设置Param的声明

时间:2015-02-17 23:34:09

标签: pdf vbscript asp-classic

使用ASPPDF,我正在从用户输入创建一个pdf表单。

当用户选择一个无线电选项时,我可以像这样设置数据在PDF中的写入位置。

If Request("type") = 1 Then x=57
If Request("type") = 1 Then y=506 else
If Request("type") = 2 Then x=57
If Request("type") = 2 Then y=400 else

Page1.Canvas.SetParams "color=black, linewidth=2"
Page1.Canvas.DrawLine x, y, x + 7, y - 7
Page1.Canvas.DrawLine x, y - 7, x + 7, y

这会在我的PDF中的相应框中生成X标记。

我的问题是这些字段的值必须是字符串,而不是数字。当我尝试这个时,我没有收到任何错误,但它也没有写任何东西。

If Request("type") = AP Then x=57
If Request("type") = AP Then y=506 else
If Request("type") = AR Then x=57
If Request("type") = AR Then y=400 else

Page1.Canvas.SetParams "color=black, linewidth=2"
Page1.Canvas.DrawLine x, y, x + 7, y - 7
Page1.Canvas.DrawLine x, y - 7, x + 7, y

我无法简单地将表单中的值更改为数字,因为在整个脚本中的多个位置使用了相同的值,我需要它作为该值,而不是数字。

我也试过添加" " (引用)围绕价值,但这也不起作用。

... 
If Request("type") = "AP" Then x=57
...

有任何帮助吗?

1 个答案:

答案 0 :(得分:2)

错误的结构化if .. then .. else声明。正确的语法如下:

' Single-Line syntax:
If condition Then statements [Else elsestatements ] 

' Or, you can use the block form syntax: 
If condition Then
   [statements]
[ElseIf condition-n Then
   [elseifstatements]] . . .
[Else
   [elsestatements]]
End If

因此,您的代码剪切可能如下:

If UCase(Request("type")) = "AP" Then 
  x=57
  y=506
ElseIf UCase(Request("type")) = "AR" Then
  x=57
  y=400
Else
  '
End If

Select Case UCase(Request("type"))
    Case "AP" 
        x=57
        y=506
    Case "AR"
        x=57
        y=400
    Case Else
        '
End Select

注意:UCase函数返回一个已转换为大写的字符串,因为我们可以不知道 Request("type")是哪个字母大小写(例如apaPApAP?)。

资源:VBScript Language Reference

相关问题