Can I bind strings to property names at runtime?

Results 1 to 2 of 2

Thread: Can I bind strings to property names at runtime?

  1. #1
    Join Date
    Dec 1969

    Default Can I bind strings to property names at runtime?

    I have a situation where I&#039;m uploading a file with ASPUpload and I want to serve the constraints on that file from a database (vs. hardcoding the constraining rules). The idea is that we can create new upload file types with new constraints without opening up the ASP code.<BR><BR>My issue is this: I want to be able to key property names into the database and have them bound to the upload object at runtime.<BR><BR>Example - now we might do:<BR><BR>[code language="VBScript"] If FileUpload.ImageWidth &#062; 100 Then ...[/code]<BR><BR>but instead I&#039;d like to do something that might look like:<BR><BR>[code language="VBScript"] If FileUpload.GetPropertyMethod("ImageWidth") &#062; 100 Then ...[/code]<BR><BR>where the "GetPropertyMethod" allows me to access ImageWidth via a string - which means I could also do:<BR><BR>[code language="VBScript"] If FileUpload.GetPropertyMethod(propNameFromDatabase) &#062; 100 Then ...[/code]<BR><BR>I realize I can use Execute to run arbitrary code - that&#039;s my fallback, but I was looking for something a little cleaner.<BR><BR>Can I iterate through props by number, find a prop name and then call it by name?<BR><BR>Any help?<BR><BR>DC

  2. #2
    Join Date
    Dec 1969

    Default No...

    If you were coding in C++ you could. Because under that covers that&#039;s exactly what happens when you use a property/method with an ActiveX object. <BR><BR>VBS takes the name you give in<BR><BR>and treats it as a string and then does a lookup of that name in the type table for the referenced object and ... Well, you get the idea.<BR><BR>But the VBS designers didn&#039;t provide a way to dynamically supply that string.<BR><BR>I *certainly* would NOT use EXECUTE (or EVAL). Both are HUGE eaters of CPU time, compared to standard VBS code. [I wish they&#039;d never been introduced into the language.]<BR><BR>Ugly though it might be, I&#039;d suggest a SELECT CASE if you think you really need this capability. It will be TONS faster than an EXECUTE.<BR><BR>Function getUploadProperty( fu, what, value )<BR> SELECT CASE what<BR> CASE "width"<BR> getUploadProperty = (fu.ImageWidth &#062; value)<BR> CASE "height"<BR> getUploadProperty = (fu.ImageHeight &#062; value)<BR> ...<BR> END SELECT<BR>End Function<BR><BR>...<BR>truth = getUploadProperty( FileUpload, "width", 100 )<BR>...<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts