| <%
' 文字列で変数名を指定して定義して、初期値をセット
Def "ObjServer", Server
DefineGlobal()
' **********************************************************
' 関数内でグローバル変数を定義
' **********************************************************
Sub DefineGlobal()
' 空文字
Def "ErrorMessage", ""
' 変数を初期状態
Def "Cn,Rs", Empty
' 定数セットは、C: を先頭に付加します
Def "InfoString", "C:入力して下さい"
' 日付
Def "Today,SaveDay", Now()
' 配列
Def "Param1,Param2", Array(1,10,25,30)
' オブジェクト
Def "Obj", Nothing ' VB の定数
Def "Obj2", "ObjServer" ' 定義済みのオブジェクト変数
Def "MyStr,str", "InfoString" ' 定義済みの通常変数
End Sub
Response.Write ErrorMessage & "<br>"
Response.Write Cn & "<br>"
Response.Write Rs & "<br>"
Response.Write InfoString & "<br>"
Response.Write Today & "<br>"
Response.Write SaveDay & "<br>"
Response.Write TypeName(Obj) & "<br>"
Response.Write TypeName(Obj2) & "<br>"
Response.Write MyStr & "<br>"
Response.Write str & "<br>"
' **********************************************************
' グローバル変数定義
' **********************************************************
sub Def( sVar, sInit )
Dim aData,I
if instr( sVar, "," ) = 0 then
DefBase sVar, sInit
else
aData = Split( sVar, "," )
For I = 0 To Ubound(aData)
DefBase aData(I), sInit
Next
end if
end sub
sub DefBase( sVar, sInit )
if IsEmpty( sInit ) then
ExecuteGlobal "Dim " & sVar & ":" & sVar & " = Empty"
Exit Sub
end if
if IsNull( sInit ) then
ExecuteGlobal "Dim " & sVar & ":" & sVar & " = Null"
Exit Sub
end if
if IsDate( sInit ) then
ExecuteGlobal "Dim " & sVar & ":" & sVar & " = #" & sInit & "#"
Exit Sub
end if
if IsArray( sInit ) then
ExecuteGlobal "Dim gblDummy"
gblDummy = sInit
ExecuteGlobal "Dim " & sVar & ": " & sVar & " = gblDummy"
Exit Sub
end if
if TypeName(sInit) = "String" then
if Ucase(Left( sInit, 2 )) = "C:" or sInit = "" then
if Ucase(Left( sInit, 2 )) = "C:" then
sInit = Right( sInit, Len(sInit)-2 )
end if
ExecuteGlobal "Dim " & sVar & ":" & _
sVar & " = """ & sInit & """"
Exit Sub
end if
end if
if IsObject( sInit ) then
ExecuteGlobal "Dim gblDummy"
Set gblDummy = sInit
ExecuteGlobal "Dim " & sVar & ": Set " & sVar & " = gblDummy"
Exit Sub
end if
on error resume next
ExecuteGlobal "Dim " & sVar & ":" & sVar & "=" & sInit
ExecuteGlobal "Dim " & sVar & ": Set " & sVar & "=" & sInit
on error goto 0
end sub
%>
| |