11 Replies Latest reply: Nov 30, 2011 5:47 AM by Dan-Ketil Jakobsen RSS

    Using Variables in GetContent

    Dan-Ketil Jakobsen

      Hi

       

      I have onve variable vSQL, this is set in a button and looks like:

       

      = 'EXEC master.dbo.xp_AnalogWideHistory ' & vBatchStartTime & ', ' & vBatchStopTime & ', ' & 100000 & ', ' & vTag

       

      The button then run a macro where I try to use this in EDX

       

      SET SQL = ActiveDocument.Variables(vSQL)

       

      (...)

      GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName >vSQL</i_VariableName ><i_VariableValueList ><string>" & SQL.GetContent.String & "</string></i_VariableValueList ></Global>"

       

      When I run the macro I get the following error:

      Object required: 'SQL'

      and it then highlights the last part of the GetEDXRequestString mentioned above.

       

       

      What am I doing wrong?

       

      Dan

        • Using Variables in GetContent
          Miguel Angel Baeyens de Arce

          Hi Dan,

           

          SQL is a keyword fro QlikView, just change the name of the variable to xSQL or something different.

           

          Hope that helps.

           

          Miguel

            • Using Variables in GetContent
              Dan-Ketil Jakobsen

              Hi Miguel.

               

              Tahnks for your post, unfortunately this dod not help

              I tried changing it to varSQL, but get this error:

               

              Object required: 'varSQL'

               

              Dan

                • Re: Using Variables in GetContent
                  Miguel Angel Baeyens de Arce

                  Dan,

                   

                  Maybe it's a typo, but the variable needs to be enclosed in double quotes:

                   

                  SET SQL = ActiveDocument.Variables("vSQL")
                  

                   

                  So you can refer later to it

                   

                  SQL.GetContent.String
                  

                   

                  Hope that helps.

                   

                  Miguel

                    • Using Variables in GetContent
                      Dan-Ketil Jakobsen

                      This is how it looks right now:

                       

                      Dim varSQL

                      'Dim stringSQL

                       

                      SET varSQL = ActiveDocument.Variables("vSQL")

                      'SET stringSQL = SQL.GetContent.String

                       

                      (...)

                       

                      GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName >vSQL</i_VariableName ><i_VariableValueList ><string>" & varSQL.GetContent.String & "</string></i_VariableValueList ></Global>"

                       

                      Still no effect.

                       

                      But I also now tested to output the "vSQL" in a msgbox, like: msgbox("String: " & vSQL). This returns empty.

                       

                      The error that I get is still:

                      Object required: 'varSQL'

                       

                      But I am now not sure if that is because the variable it self is set to empty(as shown in the msgbox) or is it in the method that I try to use it.....

                       

                      Dan

                        • Re: Using Variables in GetContent
                          Miguel Angel Baeyens de Arce

                          Hi Dan,

                           

                          Go to the Settings menu, Variable Overview, find vSQL and set any random value just to make sure that the macro works fine. As far as I see, the code seems to be all right and varSQL is an object provided vSQL exists in the document and has any value. Check that you are not declaring varSQL in one sub and calling from another as a "private" variable.

                           

                          Hope that helps.

                           

                          Miguel

                            • Using Variables in GetContent
                              Dan-Ketil Jakobsen

                              I tried to change the vSQL to 'dan'.

                              Also created a textobject showing the value: = 'sql: ' & vSQL

                               

                              This now shows 'dan'.

                              When hitting the button the msgbox appears but still no data in it.

                               

                               

                              Dan

                                • Re: Using Variables in GetContent
                                  Miguel Angel Baeyens de Arce

                                  Dan,

                                   

                                  Then it must be something else, because the variable exists and gets the value. The following macro lines should do to check whether a variable is created has some content:

                                   

                                  Sub CheckVariable
                                       SET vCheck = ActiveDocument.Variables("vVariableNameHere")
                                       MsgBox(vCheck.GetContent.String)
                                  End Sub
                                  

                                   

                                  That should return the value of the variable "vVariableNameHere".

                                   

                                  Something in previous lines of macro is overwriting the variable value perhaps?

                                   

                                  Hope that helps.

                                   

                                  Miguel

                                    • Using Variables in GetContent
                                      Dan-Ketil Jakobsen

                                      Now we are talking.

                                      I found the problem with the variabel at least.

                                      I have two buttons, one that saves the variables and one that runs the macro.

                                      I had to place the vSQL in both buttons. Not sure why, but now that part works.

                                       

                                      I still cant get the code to run, but at least the variabel is now part of the string.

                                       

                                      Tried these two lines

                                      'GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName >vSQL</i_VariableName ><i_VariableValueList ><string>" & varSQL.GetContent.String & "</string></i_VariableValueList ></Global>"

                                       

                                      GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName ></i_VariableName ><i_VariableValueList ></i_VariableValueList ></Global>"

                                       

                                      The latter one works, but that one does not hold any info about the variable, so obviously it will not affect anything. But it runs.

                                      I need to get the top one to run in some manner.

                                       

                                      Thanks for your help and patience so far!

                                       

                                      Dan

                                        • Re: Using Variables in GetContent
                                          Miguel Angel Baeyens de Arce

                                          Hi Dan,

                                           

                                          I'd use the same macro for both things. You can use the CALL to call another sub or function within a different sub, so although you have two different subs (one that sets the variable the other that runs the trigger) the main is called only once, and this calls to the one that sets the variable.

                                           

                                          Sub SetVariable
                                               SET vSQL = ActiveDocument.Variables("vSQL")
                                               vSQL.SetContent "Something", true
                                          End Sub
                                          
                                          
                                          Sub TriggerEDX
                                               Call SetVariable
                                               '' You need to create the object in this function (it's private)
                                               SET vSQL = ActiveDocument.Variables("vSQL") 
                                               '' This line shoud print the string Something
                                               MsgBox(vSQL.GetContent.String) 
                                          End Sub
                                          

                                           

                                          Hope that helps.

                                           

                                          Miguel

                                            • Using Variables in GetContent
                                              Dan-Ketil Jakobsen

                                              Thanks.

                                              The code stores the vSQL value.

                                               

                                              I f I now get to solve the problem of actually running it I would be home free.

                                                • Re: Using Variables in GetContent
                                                  Dan-Ketil Jakobsen

                                                  Maybe you know why this happends:

                                                   

                                                  In the last line I add varSQL

                                                   

                                                  GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName >varSQL</i_VariableName ><i_VariableValueList ><string>" & varSQL.GetContent.String & "</string></i_VariableValueList ></Global>"

                                                   

                                                  This gives an error: Object required: 'varSQL'

                                                   

                                                  Why?

                                                   

                                                  I tried to add ActiveDocument.Reload at the bottom.

                                                  When running from server this works just fine, running from client does not work.

                                                  So it seems that what I need to make happend is that the edx should eb able to reload the document somehow.

                                                   

                                                  Dan