Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
qv_mypath
Contributor II
Contributor II

Calling the Function from another Function in Macros

Dear All,


I try to change the content of the text field in the macros.


Background: the content of the field is correct per se and should not be changed in the load script etc. The task is to save the states of a certain table in the different files after choosing the values in the field in a loop. The name of each file should be close to the corresponding value in the field. The values in the field however contain chars such as slash, asterisk, colon etc. which are not allowed in a file name.


I can achieve what I want with a list of consecutive replace commands. I thought of separating this list of commands in an extra function (I named it “brush”). However I cannot succeed to get a return value from this second function. The script is below. The message box in the brush function does show the string. However the string is not returned from “brush” into “checkout”. The call to brush function from the checkout function is now commented out.

Thank you very much in advance!

Here the minimal working example.


QlikView Load Skript:


Tab1:
LOAD * INLINE [
    Nr, Name, Txt
    1, name with /, a
    2, another : one \, b
    3, this * one too, c
    4, or / as * mix, d
    5, this : way / or * that, e
]
;

Macro Editor:

sub useit
     call checkout(ActiveDocument, "Name")
end sub



function checkout(qvDoc, Testfield)
     set nName = qvDoc.Fields(Testfield).GetPossibleValues
     for i = 0 to nName.Count - 1
           problem = nName.Item(i).Text
'          problem = brush(problem)
           problem = replace(problem, "/", "_")
           problem = replace(problem, "\", "_")
           problem = replace(problem, ":", " ")
           problem = replace(problem, "*", " ")
           msgbox problem
     next
end function



function brush(str)
     msgbox "In brush " & str
     str = replace(str, "/", "_")
     str = replace(str, "\", "_")
     str = replace(str, ":", " ")
     str = replace(str, "*", " ")
end function

1 Solution

Accepted Solutions
marcus_sommer

I think you are missing:

function brush(str)
      msgbox "In brush " & str
      str = replace(str, "/", "_")
      str = replace(str, "\", "_")
      str = replace(str, ":", " ")
      str = replace(str, "*", " ")

      brush = str
end function

- Marcus

View solution in original post

4 Replies
marcus_sommer

I think you are missing:

function brush(str)
      msgbox "In brush " & str
      str = replace(str, "/", "_")
      str = replace(str, "\", "_")
      str = replace(str, ":", " ")
      str = replace(str, "*", " ")

      brush = str
end function

- Marcus

qv_mypath
Contributor II
Contributor II
Author

Thank you very much Marcus, it did the trick!

It seems to be a peculiarity in the QlikView (at least to me) since I thought that the last evaluated expression should be returned.

Could you please point me to the appropriate place in the documentation? Thanks again!

marcus_sommer

By a function will be the last content of function-name returned and you could write the function in this way:

function brush(str)
      msgbox "In brush " & str
      brush = replace(str, "/", "_")
      brush = replace(brush, "\", "_")
      brush = replace(brush, ":", " ")
      brush = replace(brush, "*", " ")

end function

I'm not sure but I think the most of all programs, for example VBA, VBS and so on, handle it in the same way. This meant qlik is no exception from this.

- Marcus

qv_mypath
Contributor II
Contributor II
Author

Thank you very much again!