Related
I'm trying add a point in currently opened Autocad drawning. As reference I'm using VBA example from AddPoint manual:
VBA:
RetVal = object.AddPoint(Point)
object
Type: Block, ModelSpace, PaperSpace
The objects this method applies to.
Point
Access: Input-only
Type: Variant (three-element array of doubles)
The coordinates of the point to be created.
Sub Example_AddPoint()
' This example creates a point in model space.
Dim pointObj As AcadPoint
Dim location(0 To 2) As Double
' Define the location of the point
location(0) = 5#: location(1) = 5#: location(2) = 0#
' Create the point
Set pointObj = ThisDrawing.ModelSpace.AddPoint(location)
ZoomAll
End Sub
So far I'm successfully connected to ActiveX object and can get/set many things with it (as long as it requires a string input), except I can't figure out how create a
Variant (three-element array of doubles)
required for AddPoint function
Here is autoit code I'm playing with:
Local $location[3] = [5.0,5.0,0.0]
Local $oAcad = ObjGet("","AutoCAD.Application")
$oAcad.ActiveDocument.Modelspace.AddPoint($location)
It returns error:
"1.au3" (3) : ==> The requested action with this object has failed.:
$oAcad.ActiveDocument.Modelspace.AddPoint($location)
$oAcad.ActiveDocument.Modelspace^ ERROR
There is no details about error even with error handler, so I assume datatype of $location variable is wrong.
I have a need to crawl a set of data of indeterminate size and build a table key/value index of it. Since I don't know the dimensions in advance, seems I have to use a recursive function. My Lua skills are very new and superficial. I'm having difficulty understanding how to deal with returning a table from the function call.
Note this is for a Lua 5.1 script processor
API = function(tbl)
local table_api = {}
-- do stuff here with target data and add to table_api
table_api["key"] = value
-- then later there is a need to recurse deeper into target data
table_api["lower"] = API(var)
return table_api
end
result = API(source_data)
In most every other language I know there would be some way to make the recurse line table_api["lower"] = API(var) work but since Lua does table variables by reference, my return sub-table just keeps getting overwritten and my result is a tiny last bit of what it should be.
Just for background on my purpose: there's a commercial application I'm working with that has a weakly documented Lua scripting interface. It's running Lua 5.1 and the API is not well documented and frequently updated. As I understand it, everything is stored in _G, so I wanted to write something to reverse engineer the API. I have a working recursive function (not shown here) that enumerates all of _G. For that return value, it just builds up an annotated string and progressively builds on the string. That all works fine and is really useful, but it shows much more that the API interface; all the actual data elements are included, so I have to sift through like 30,000 records to determine an API set of about 500 terms. In order to determine the API, I am trying to use this sub-table return value recursive function being discussed in this question. The code I'm showing here is just a small distilled subset of the larger function.
I'll go ahead and include the full code here. I was hoping to incrementally build a large'ish table of each API level, any sublevels, and finally whatever keys used at the lowest level.
In the end, I was expecting to have a table that I could address like this:
result["api"]["label"]["api"]["sublabel"]["value"]["valuename"]
Full code:
tableAPIShow = function(tbl, table_track)
table_track = table_track or {}
local table_api = {}
if type(tbl) == 'table' then
-- Check if values are tables.
local parent_table_flag = true
for ind,val in pairs(tbl) do
if type(val) ~= 'table' then
parent_table_flag = false
break
end
end
-- If all children are table type, check each of them for subordinate commonality
local api_flag = false
if parent_table_flag == true then
local child_table = {}
local child_table_flag = false
api_flag = true
for ind,val in pairs(tbl) do
-- For each child table, store the names of the indexes.
for sub_ind,sub_val in pairs(val) do
if child_table_flag == false then -- First time though, create starting template view of typical child table.
child_table[sub_ind] = true -- Store the indexes as a template table.
elseif child_table[sub_ind] == nil then -- Otherwise, test this child table compared to the reference template.
api_flag = false
break
end
end
if api_flag == false then -- need to break out of nested loop
break
end
child_table_flag = true
end
end
if api_flag == true then
-- If everything gets to here, then this level is an API with matching child tables below.
for ind,val in pairs(tbl) do
if table_api["api"] == nil then
table_api["api"] = {}
end
table_api["api"][ind] = tableAPIShow(val, table_track)
end
else
-- This level is not an API level, determine how to process otherwise.
for ind,val in pairs(tbl) do
if type(val) == 'table' then
if table_track[val] ~= nil then -- Have we already recursed this table?
else
table_track[val] = true
if table_api["table"] == nil then
table_api["table"] = {}
end
table_api["table"][ind] = tableAPIShow(val, table_track)
end
else -- The children are not tables, they are values
if table_api["value"] == nil then
table_api["value"] = {}
end
table_api["value"][ind] = val
end
end
end
else
-- It's not a table, just return it.
-- Probably never use this portion because it's caught on upper level recurse and not called
return tbl
end
return table_api
end
And I was calling this function in the main script like this:
local str = tableAPIShow(_G)
I've got another function that recursively shows a table so I can look inside my results and see I only get a return value that contains only the values of the top-level of _G (I have it excluded built-in Lua functions/values because I'm only interested in the Application API):
{
[value] = table: 00000000F22CB700 {
[value][_VERSION] = Application/5.8.1 (x86_64; Windows NT 10.0.16299),
[value][tableAPIShow] = "function: 00000000F22C6DE0, defined in (121-231) C:\\Users\\user\\AppData\\Local\\Temp\\APP\\/~mis00002690 ",
[value][_FINAL_VERSION] = true,
[value][Path] = ./Scripts/Database/elements/,
[value][class] = "function: 00000000F1953C40, defined in (68-81) Scripts/Common/Class.lua ",
[value][db_path] = ./Scripts/Database/,
[value][merge_all_units] = "function: 00000000F20D20C8, defined in (2242-2250) Scripts/Database/db_merge.lua ",
}
You just need to localize the variable you store your table in and it will work as you expect:
local table_api = {}
(note that you are passing table variable that conflicts with the global table variable and is not currently used in the function.)
I am inclined to believe that your tableAPIShow function code is working correctly and the
another function that recursively shows a table
fails to serialize your table fully. Hence you don't see the deeper levels of the table returned by tableAPIShow().
I got your initial and current code (tableAPIShow) to work with my simple table serialize function: the whole _Global table is exported completely and formatted as you implemented it in your tableAPIShow().
Code for testing:
apiMassiveTable = {
api = {
get = {
profile = {"profileID", "format"},
name = {"profileID", "encoding"},
number = {"profileID", "binary"}
},
set = {
name = {"apikey", "profileID", "encoding", "newname"},
number = {"apikey", "profileID", "binary", "newnumber"}
},
retrieve = {}
},
metadata = {version="1.4.2", build="nightly"}
}
-- tableAPIShow implemenation here
table.serialize = dofile("serialize.lua")
print(table.serialize("myNameForAHugeTable", tableAPIShow(_G)))
PS: Whatever serialize function you're using, it should enquote strings like Application/5.8.1 (x86_64; Windows NT 10.0.16299) which it does not.
Like #Paul Kulchenko said, you need to learn to use locals (https://www.lua.org/pil/4.2.html). Global variable post-exist until a new lua_State is loaded (a new environment, could be a new process depending on what interpreter you are using). So a tip is to always use local variables for anything you don't want to leave the function or leave the compilation unit.
Think of tables like dictionaries: a word is attached to a definition. Thusly the definition is the data.
What I think you are trying to do is serialization of a table of data. However, that isn't really necessary. You can either shadow copy or deep copy the given table. A shadow copy is when you don't delve into the depths of tables found in the keys, etc. A deep copy is when you copy tables in keys of tables in keys of tables... etc.
local shallow_copy = function(tab)
local rep_tab = {}
for index, value in pairs(tab)do
rep_tab[index] = value
end
return rep_tab
end
-- because local variable is not defined or declared immediately on a 1-liner,
-- a declaration has to exist so that deep_copy can be used
-- lets metatable execute functions
local deep_copy
deep_copy = function(tab)
local rep_tab = {}
for index, value in pairs(tab)do
if(type(value) == "table")then
rep_tab[index] = deep_copy(value)
else
rep_tab[index] = value
end
end
return rep_tab
end
Deco's deepcopy.lua
https://gist.github.com/Deco/3985043
You can also index tables using periods:
local tab = {}
tab.abc = 123
tab["def"] = 456
print(tab.abc, tab["def"])
To serialize the entire _G, you would just filter out the junk you don't need and recurse each table encountered. Watch out for _G, package, and _ENV because if defined it will recurse back to the start.
-- use cap as a whitelist
enumerate_dir = function(dir, cap)
local base = {}
for i, v in pairs(dir) do
-- skip trouble
if(i ~= "_G" and i ~= "_ENV" and i ~= "package")then
if(type(v) == "table")then -- if we have a table
base[i] = enumerate_dir(v, cap)
else
for k, n in pairs(cap) do
if(type(v) == n)then -- if whitelisted
base[i] = tostring(v)
end
end
end
end
end
return base
end
-- only functions and tables from _G please
local enumeration = enumerate_dir(_G, {"function", "table"})
-- do some cool quips to get a basic tree system
prefix = ""
recursive_print = function(dir)
for i, v in pairs(dir)do
if(type(v) == "table")then
print(prefix, i, v)
prefix = prefix .. ">"
recursive_print(v)
else
print(prefix, i, v)
end
end
if(#prefix > 0)then
prefix = prefix:sub(1, #prefix-1)
end
end
recursive_print(test)
I have written a function to detect objects in arrays. In this case I use it to clear white objects, which touch the border of an image. But the problem is, that there is always a StackOverFlowError in vcat and it occurs at different lines (depends on image). Here is a minimum working example. It works fine with the second image, but not with the first:
using Images
function getImChars(I::Array)
charAr=copy(I);
indexMax=find(x->(x==1),charAr);
(h,w)=size(charAr);
# check border values
(r,c)=ind2sub(size(charAr),indexMax);
indexBorderR1=find(x->(x==1),r);
indexBorderR2=find(x->(x==h),r);
indexBorderR=[indexBorderR1;indexBorderR2];
indexBorderC1=find(x->(x==1),c);
indexBorderC2=find(x->(x==w),c);
indexBorderC=[indexBorderC1;indexBorderC2];
borderPixels=[999;999]; # initialize def value FIX
for bRc=1:length(indexBorderR)
borderPixels=[borderPixels [r[indexBorderR[bRc]];c[indexBorderR[bRc]]]];
end
for bCc=1:length(indexBorderC)
borderPixels=[borderPixels [r[indexBorderC[bCc]];c[indexBorderC[bCc]]]];
end
borderPixels=borderPixels[:,2:end];
(rbP,cbP)=size(borderPixels);
fcharAr=[];
for k=1:cbP
bP=[borderPixels[:,k];false;false;false;false];
locObj1=[];
locObj2=[];
locObj3=[];
locObj4=[];
locObj5=[];
locObj6=[];
if(charAr[bP[1],bP[2]]==0)
continue;
else
charAr[bP[1],bP[2]]=0;
end
recGetCharClearBorders(true,false,h,w,bP,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,charAr);
end
return charAr;
end
function recGetCharClearBorders(firstFlag::Bool,doNotAdd::Bool,h::Int,w::Int,hP::Array,locObj1::Array,locObj2::Array,locObj3::Array,locObj4::Array,locObj5::Array,locObj6::Array,imAr::Array)
leftPoint=[hP[1];hP[2]-1;0;0;0;0];
rightPoint=[hP[1];hP[2]+1;0;0;0;0];
topPoint=[hP[1]-1;hP[2];0;0;0;0];
bottomPoint=[hP[1]+1;hP[2];0;0;0;0];
# check if it is not out of bounds and relative directions
if(topPoint[1]!=0)
if(imAr[topPoint[1],topPoint[2]]==1)
hP[4]=1;
end
end
if(bottomPoint[1]!=(h+1))
if(imAr[bottomPoint[1],bottomPoint[2]]==1)
hP[6]=1;
end
end
if(leftPoint[2]!=0)
if(imAr[leftPoint[1],leftPoint[2]]==1)
hP[3]=1;
end
end
if(rightPoint[2]!=(w+1))
if(imAr[rightPoint[1],rightPoint[2]]==1)
hP[5]=1;
end
end
# add first elements
if(firstFlag)
locObj1=collect(hP[1]);
locObj2=collect(hP[2]);
locObj3=collect(hP[3]);
locObj4=collect(hP[4]);
locObj5=collect(hP[5]);
locObj6=collect(hP[6]);
firstFlag=false;
else
# if first element of locObj was deleted actual point should not get pushed to array
if(!doNotAdd)
push!(locObj1,hP[1]);
push!(locObj2,hP[2]);
push!(locObj3,hP[3]);
push!(locObj4,hP[4]);
push!(locObj5,hP[5]);
push!(locObj6,hP[6]);
imAr[hP[1],hP[2]]=0;
end
end
goL=false;
goT=false;
goR=false;
goB=false;
doNotAdd=false;
if(length(locObj1)!=0)
# always take and check first elements of locObj
hPfInLoc=[locObj1[1],locObj2[1],locObj3[1],locObj4[1],locObj5[1],locObj6[1]];
hPl=[hPfInLoc[1];hPfInLoc[2]-1;0;0;0;0];
hPt=[hPfInLoc[1]-1;hPfInLoc[2];0;0;0;0];
hPr=[hPfInLoc[1];hPfInLoc[2]+1;0;0;0;0];
hPb=[hPfInLoc[1]+1;hPfInLoc[2];0;0;0;0];
compL=false;
compT=false;
compR=false;
compB=false;
# check bounds and if array values have changed
if(hPt[1]!=0)
if(imAr[hPt[1],hPt[2]]!=0)
compT=true;
end
end
if(hPb[1]!=(h+1))
if(imAr[hPb[1],hPb[2]]!=0)
compB=true;
end
end
if(hPl[2]!=0)
if(imAr[hPl[1],hPl[2]]!=0)
compL=true;
end
end
if(hPr[2]!=(w+1))
if(imAr[hPr[1],hPr[2]]!=0)
compR=true;
end
end
# define directions and set defined direction false in locObj
if((locObj3[1]==1)& compL)
locObj3[1]=0;
goL=true;
elseif((locObj4[1]==1)& compT)
locObj4[1]=0;
goT=true;
elseif((locObj5[1]==1)& compR)
locObj5[1]=0;
goR=true;
elseif((locObj6[1]==1)& compB)
locObj6[1]=0;
goB=true;
else
if (length(locObj1)==1)
locObj=[];
else # if everything is zero delete first rows of arrays
deleteat!(locObj1,1);
deleteat!(locObj2,1);
deleteat!(locObj3,1);
deleteat!(locObj4,1);
deleteat!(locObj5,1);
deleteat!(locObj6,1);
doNotAdd=true;
return recGetCharClearBorders(firstFlag,doNotAdd,h,w,hP,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,imAr);
end
end
end
#execute choosen direction
if(goL)
return recGetCharClearBorders(firstFlag,doNotAdd,h,w,hPl,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,imAr);
end
if(goT)
return recGetCharClearBorders(firstFlag,doNotAdd,h,w,hPt,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,imAr);
end
if(goR)
return recGetCharClearBorders(firstFlag,doNotAdd,h,w,hPr,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,imAr);
end
if(goB)
return recGetCharClearBorders(firstFlag,doNotAdd,h,w,hPb,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,imAr);
end
end
# execute test procedure
Im=Images.load("Test.png");
Im=data(Im);
imAr=map(Float64,Im);
resIm=getImChars(imAr);
save("Imout.png",resIm);
You only have to change the name of the image in my code. Just tell me, if you need some more information. Thanks a lot.
Cheers, clax
Unlike many functional programming language, Julia doesn't optimize for tail recursion (reusing the stack frame when a function ends by a call). So in your case it is very likely that your recursive function hits the max stack depths depending on your OS's thread stack size.
Unfortunately, the Julia core team decide not to prioritise Tail call optimization as they don't deem such feature a must. Indeed people can often refactor their code into loops.
Afaik, tail call optimization is pretty difficult and many other programming languages featuring functional programming paradigm also lack it.
Took a few minutes needed to run and fixup the tail recursion. Is the following replacement for recGetCharClearBorders performing correctly:
function recGetCharClearBorders(firstFlag::Bool,doNotAdd::Bool,h::Int,w::Int,hP::Array,locObj1::Array,locObj2::Array,locObj3::Array,locObj4::Array,locObj5::Array,locObj6::Array,imAr::Array,recdepth,recloc)
while true
leftPoint=[hP[1];hP[2]-1;0;0;0;0];
rightPoint=[hP[1];hP[2]+1;0;0;0;0];
topPoint=[hP[1]-1;hP[2];0;0;0;0];
bottomPoint=[hP[1]+1;hP[2];0;0;0;0];
# check if it is not out of bounds and relative directions
if(topPoint[1]!=0)
if(imAr[topPoint[1],topPoint[2]]==1)
hP[4]=1;
end
end
if(bottomPoint[1]!=(h+1))
if(imAr[bottomPoint[1],bottomPoint[2]]==1)
hP[6]=1;
end
end
if(leftPoint[2]!=0)
if(imAr[leftPoint[1],leftPoint[2]]==1)
hP[3]=1;
end
end
if(rightPoint[2]!=(w+1))
if(imAr[rightPoint[1],rightPoint[2]]==1)
hP[5]=1;
end
end
# add first elements
if(firstFlag)
locObj1=collect(hP[1]);
locObj2=collect(hP[2]);
locObj3=collect(hP[3]);
locObj4=collect(hP[4]);
locObj5=collect(hP[5]);
locObj6=collect(hP[6]);
firstFlag=false;
else
# if first element of locObj was deleted actual point should not get pushed to array
if(!doNotAdd)
push!(locObj1,hP[1]);
push!(locObj2,hP[2]);
push!(locObj3,hP[3]);
push!(locObj4,hP[4]);
push!(locObj5,hP[5]);
push!(locObj6,hP[6]);
imAr[hP[1],hP[2]]=0;
end
end
goL=false;
goT=false;
goR=false;
goB=false;
doNotAdd=false;
if(length(locObj1)!=0)
# always take and check first elements of locObj
hPfInLoc=[locObj1[1],locObj2[1],locObj3[1],locObj4[1],locObj5[1],locObj6[1]];
hPl=[hPfInLoc[1];hPfInLoc[2]-1;0;0;0;0];
hPt=[hPfInLoc[1]-1;hPfInLoc[2];0;0;0;0];
hPr=[hPfInLoc[1];hPfInLoc[2]+1;0;0;0;0];
hPb=[hPfInLoc[1]+1;hPfInLoc[2];0;0;0;0];
compL=false;
compT=false;
compR=false;
compB=false;
# check bounds and if array values have changed
if(hPt[1]!=0)
if(imAr[hPt[1],hPt[2]]!=0)
compT=true;
end
end
if(hPb[1]!=(h+1))
if(imAr[hPb[1],hPb[2]]!=0)
compB=true;
end
end
if(hPl[2]!=0)
if(imAr[hPl[1],hPl[2]]!=0)
compL=true;
end
end
if(hPr[2]!=(w+1))
if(imAr[hPr[1],hPr[2]]!=0)
compR=true;
end
end
# define directions and set defined direction false in locObj
if((locObj3[1]==1)& compL)
locObj3[1]=0;
goL=true;
elseif((locObj4[1]==1)& compT)
locObj4[1]=0;
goT=true;
elseif((locObj5[1]==1)& compR)
locObj5[1]=0;
goR=true;
elseif((locObj6[1]==1)& compB)
locObj6[1]=0;
goB=true;
else
if (length(locObj1)==1)
locObj=[];
else # if everything is zero delete first rows of arrays
deleteat!(locObj1,1);
deleteat!(locObj2,1);
deleteat!(locObj3,1);
deleteat!(locObj4,1);
deleteat!(locObj5,1);
deleteat!(locObj6,1);
doNotAdd=true;
continue
end
end
end
#execute choosen direction
if(goL)
hP = hPl
continue
end
if(goT)
hP = hPt
continue
end
if(goR)
hP = hPr
continue
end
if(goB)
hP = hPb
continue
end
break
end
end
Somehow the output image turned on its side in my run.
I have a strange problem. Let's look at that code:
TreeNode tn = TreeView1.FindNode("2009/08/12 (1)"); //OK, the Node is found
Now, I need to delete that node:
(IT DOESN'T WORK !)
(e.g. (I know that I don't need to use TreeView1.FindNode() method, but i = -1))
TreeNode tn1 = TreeView1.FindNode(tn.ValuePath);
int i = TreeView1.Nodes.IndexOf(tn1);
or
TreeView1.Nodes.Remove(tn);
The problem is, the codes above doesn't work, I mean, the node isn't removed, why ?
The TreeView looks like that:
alt text http://img130.imageshack.us/img130/230/71970321.png
It seems that the TreeView control in .net only allows to remove First Level Nodes, so if the node you are trying to delete is not this kind of node, you need to delete it trough its parent, using something like this:
Dim Padre As TreeNode = TreeView1.SelectedNode.Parent
If (Padre Is Nothing) Then
TreeView1.Nodes.Remove(TreeView1.SelectedNode)
Else
Padre.ChildNodes.Remove(TreeView1.SelectedNode)
End If
Hope it helps!
Are you sure that you've selected the node properly? If TreeView1.Nodes.IndexOf(tn1) is returning -1, this indicates the node can't be found.
For example, how can I run me.test below?
myvar = 'test'
me.myvar
ASP looks for the method "myvar" and doesn't find it. In PHP I could simply say $me->$myvar but ASP's syntax doesn't distinguish between variables and methods. Suggestions?
Closely related to this, is there a method_exists function in ASP Classic?
Thanks in advance!
EDIT: I'm writing a validation class and would like to call a list of methods via a pipe delimited string.
So for example, to validate a name field, I'd call:
validate("required|min_length(3)|max_length(100)|alphanumeric")
I like the idea of having a single line that shows all the ways a given field is being validated. And each pipe delimited section of the string is the name of a method.
If you have suggestions for a better setup, I'm all ears!
You can achieve this in VBScript by using the GetRef function:-
Function Test(val)
Test = val & " has been tested"
End Function
Dim myvar : myvar = "Test"
Dim x : Set x = GetRef(myvar)
Response.Write x("Thing")
Will send "Thing has been tested" to the client.
So here is your validate requirement using GetRef:-
validate("Hello World", "min_length(3)|max_length(10)|alphanumeric")
Function required(val)
required = val <> Empty
End Function
Function min_length(val, params)
min_length = Len(val) >= CInt(params(0))
End Function
Function max_length(val, params)
max_length = Len(val) <= CInt(params(0))
End Function
Function alphanumeric(val)
Dim rgx : Set rgx = New RegExp
rgx.Pattern = "^[A-Za-z0-9]+$"
alphanumeric = rgx.Test(val)
End Function
Function validate(val, criterion)
Dim arrCriterion : arrCriterion = Split(criterion, "|")
Dim criteria
validate = True
For Each criteria in arrCriterion
Dim paramListPos : paramListPos = InStr(criteria, "(")
If paramListPos = 0 Then
validate = GetRef(criteria)(val)
Else
Dim paramList
paramList = Split(Mid(criteria, paramListPos + 1, Len(criteria) - paramListPos - 1), ",")
criteria = Left(criteria, paramListPos - 1)
validate = GetRef(criteria)(val, paramList)
End If
If Not validate Then Exit For
Next
End Function
Having provided this I have to say though that if you are familiar with PHP then JScript would be a better choice on the server. In Javascript you can call a method like this:-
function test(val) { return val + " has been tested"; )
var myvar = "test"
Response.Write(this[myvar]("Thing"))
If you are talking about VBScript, it doesn't have that kind of functionality. (at least not to my knowledge) I might attempt it like this :
Select myvar
case "test":
test
case "anotherSub":
anotherSub
else
defaultSub
end select
It's been a while since I wrote VBScript (thank god), so I'm not sure how good my syntax is.
EDIT-Another strategy
Personally, I would do the above, for security reasons. But if you absolutely do not like it, then you may want to try using different languages on your page. I have in the past used both Javascript AND VBScript on my Classic ASP pages (both server side), and was able to call functions declared in the other language from my current language. This came in especially handy when I wanted to do something with Regular Expressions, but was in VBScript.
You can try something like
<script language="vbscript" runat="server">
MyJavascriptEval myvar
</script>
<script language="javascript" runat="server">
function MyJavascriptEval( myExpression)
{
eval(myExpression);
}
/* OR
function MyJavascriptEval( myExpression)
{
var f = new Function(myExpression);
f();
}
*/
</script>
I didn't test this in a classic ASP page, but I think it's close enough that it will work with minor tweaks.
Use the "Execute" statement in ASP/VBScript.
Execute "Response.Write ""hello world"""
PHP's ability to dynamically call or create functions are hacks that lead to poor programming practices. You need to explain what you're trying to accomplish (not how) and learn the correct way to code.
Just because you can do something, doesn't make it right or a good idea.
ASP does not support late binding in this manner. What are you trying to do, in a larger sense? Explain that, and someone can show you how to accomplish it in asp.
Additionally, you might consider "objectifying" the validation functionality. Making classes is possible (though not widely used) in VB Script.
<%
Class User
' declare private class variable
Private m_userName
' declare the property
Public Property Get UserName
UserName = m_userName
End Property
Public Property Let UserName (strUserName)
m_userName = strUserName
End Property
' declare and define the method
Sub DisplayUserName
Response.Write UserName
End Sub
End Class
%>