Announcement

Collapse
No announcement yet.

mvdo with a variable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    mvdo with a variable?

    I have been hitting a stone wall - is this even possible...
    "goVar" is pulled from a database.

    Code:
    <MvAssign name="goVar" value="{ data.d.code }"> <MvAssign name="l.ok" value="{ ['functions/buttons.mvc']. goVar() }">
    This seems to fail regardless of what I try... am I missing something?
    William Gilligan - Orange Marmalade, Inc.
    www.OrangeMarmaladeinc.com

    #2

    The ".goVar()" in The open and closing parenthesis don't look right... Is that a function in buttons.mvc? It also seems like
    "<MvAssign name="goVar" value="{ data.d.code }">" might clobber goVar or at least the assign is creating some confusion in the example.
    Need to offer Shipping Insurance?
    Interactive Design Solutions https://www.myids.net
    MivaMerchant Business Partner | Certified MivaMerchant Web Developer
    Competitive Rates, Custom Modules and Integrations, Store Integration
    AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
    My T-shirt Collection is mostly MivaCon T-shirts!!

    Comment


      #3
      You asked mvdo with a variable?

      You have a variable and function with the same name. While it's OK to have them the same, to avoid confusing yourself and the compiler it's better to declare the variable type (e.g. l. or g.)
      Code:
      <MvAssign name="l.goVar" value="{ data.d.code }">
      Also you have a space before the function name so try this.
      Code:
      <MvAssign name="l.ok" value="{ ['functions/buttons.mvc'].goVar() }">
      However, I'm not sure from your question if that's what your trying to do. Are you trying to pass the variable to the function?
      Code:
      <MvAssign name="l.ok" value="{ ['functions/buttons.mvc'].goVar( l.goVar  ) }">
      OR 
      <MvAssign name="l.ok" value="{ ['functions/buttons.mvc'].goVar( data.d.code  ) }">
      Last edited by RayYates; 01-29-16, 09:49 AM.
      Ray Yates
      "If I have seen further, it is by standing on the shoulders of giants."
      --- Sir Isaac Newton

      Comment


        #4
        Ray, I am trying to pass the variable AS the function.

        In other words - pull the function name from a database, and then run that function.
        data.d.code is the "code" field from my database. It contains the name of the function to be run.
        How do I run that function?

        The space you mention was a typo - not in the actual code.

        It seems to me that I must hard code the actual function name. I am trying to _not_ do that.

        Bill
        William Gilligan - Orange Marmalade, Inc.
        www.OrangeMarmaladeinc.com

        Comment


          #5
          You can not do that directly but it is possible. Since goVar is a string that contains a function call, what you want is to evaluate that string AS a function and not as a string.

          The only "built in" way to do that in Miva Script is by using the old MvFilter trick I learned from Ivo. Below is scripting I used to use in Toolbelt. Since SMT now has assign and eval I dont mind sharing.

          module_code: used to open a temporary dbf file and keep it open so subsequent calls don't have to re-open the file.
          expression: Is a string containing the function you wish to evaluate.
          retval: Is the variable that will hold the return value.

          NOTE:
          Your expression must be using global variables since local variables will not be available to the filter. Use MvREFERENCE to get around that.
          You can not call functions in external files. Functions in the same file and of course Miva functions are ok.
          This particular function has not been optimized, but unless you are calling it more than a few hundred times it will be fast enough.
          The only other way to do this is using inline assembly code.

          Code:
          <MvFUNCTION NAME="EvalExp" PARAMETERS="module_code, expression, retval var" STANDARDOUTPUTLEVEL="">
              <MvASSIGN NAME="l.retval" VALUE="">
              <MvIF EXPR="{ (ISNULL l.expression) OR (ISNULL l.module_code) }">
                  <MvFUNCTIONRETURN>
              </MvIF>
              <MvASSIGN NAME="l.FilterIsOpen" VALUE="{ 'g.' $ l.module_code $ '_isOpen'  }">
          
              <MvIF EXPR="{ isdigit(glosub(l.expression,'.','')) }">
                  <MvCOMMENT>allow simple none string numbers to be evaluated (e.g. 0, 1.2, 22) </MvCOMMENT>
                  <MvASSIGN NAME="l.expression" VALUE="{ asciichar(39) $ l.expression $ asciichar(39) }">
              </MvIF>
          
              <MvIF EXPR="{ NOT fexists(l.module_code $ '.dbf') }">
                  <MvCREATE  NAME="{ l.module_code }"
                             DATABASE="{ l.module_code $ '.dbf' }"
                             FIELDS="active BOOL" >
                  <MvASSIGN NAME="{ l.module_code $ '.d.active' }" VALUE="{ 1 }">
                  <MvADD NAME="{ l.module_code }">
                  <MvASSIGN NAME="{ l.FilterIsOpen }" VALUE="{ 1 }">
              <MvELSE>
                  <MvIF EXPR="{ NOT miva_variable_value(l.FilterIsOpen) }">
                      <MvOPEN NAME="{ l.module_code }" DATABASE="{ l.module_code $ '.dbf' }">
                      <MvIF EXPR="{ NOT g.MvOPEN_Error }">
                          <MvASSIGN NAME="{ l.FilterIsOpen }" VALUE="{ 1 }">
                      </MvIF>
                  </MvIF>
              </MvIF>
          
              <MvIF EXPR="{ NOT g.MvOPEN_Error }">
                  <MvASSIGN NAME="l.filter" VALUE="{ 'Interpret(' $ l.expression $ ', l.retval)' }">
                  <MIVA MvFILTER_ERROR="nonfatal,nodisplay">
                  <MvFILTER NAME="{ l.module_code }" FILTER_TYPE="variable" FILTER="l.filter">
          
                  <MvIF EXPR="{ g.MvFILTER_ERROR }">
                      <MvASSIGN NAME="l.err" VALUE="{ glosub(g.MvFILTER_ERROR,'filter:',' expression: <font color=aa0000>' $ l.expression $ ' </font>') }">
                     <MvFUNCTIONRETURN VALUE = "{ Error( l.module_code, l.err, '' ) }">
                  </MvIF>
              </MvIF>
          </MvFUNCTION>
          
          <MvFUNCTION NAME="Interpret" PARAMETERS="expression, ret var"  STANDARDOUTPUTLEVEL="">
              <MvASSIGN NAME="l.ret" VALUE="{ l.expression }">
          </MvFUNCTION>



          Ray Yates
          "If I have seen further, it is by standing on the shoulders of giants."
          --- Sir Isaac Newton

          Comment

          Working...
          X