Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Passing variable to subroutine

Hi,

this is actually in consequence of another post of mine - but it's a different issue now and here like everywhere else I like to split things into smaller pieces, then it doesn't get too confusing and it's easier for people to realize whether they can help.

=> I have a large meta_loop across six sheets of an Excel_workbook. It passes a parameter "v_Liste_aktuell" like

    >>  CALL Sofareinigung ($(v_Liste_aktuell))  <<

=> I want to use this variable in the subroutine, so I have to specify it in the >sub< statement at the top of it all, no?

  => I do that >>  sub Sofareinigung (v_list)  <<

=> So within the subroutine, there should now be a variable > v_list < that has the same value as the one I passed in the CALL, yes?

What I find very confusing: It seems - as seen in the Debugger - that QlikView creates a variable with the exact name of the current list - what is in the variable "v_Liste_aktuell" - and that has a NULL value.

The variable > v_list < that I specify in that statement is NOT created - and consequently, the very first step in the entire code - a LOAD from an Excel_file - is wacky because I cannot specify which sheet of the table is supposed to be loaded.

Can someone help me here?

Thanks a lot!

Best regards,

DataNibbler

3 Replies
datanibbler
Champion
Champion
Author

I think I have it - the variable has to be written without the $ in the CALL_statement and taken over by the subroutine with the $ - very confusing ...

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

SET Str1 = 'abcdef';

SET Str2 = 'abcefg';

LET test = CommonStringLength((Str1), (Str2));   -- CommonStringLength is a macro function

Macro code:

function CommonStringLength(Str1, Str2)

  strLength = Max(Len(Str1), Len(Str2))

  For i=1 To strLength

     If Mid(Str1,i,1) <> Mid(Str2,i,1) then     

     CommonStringLength = i-1

     exit for

     end if    

     If i = strLength then CommonStringLength = strLength

  Next

end function

Hope this helps you.

Regards,

Jagan.

datanibbler
Champion
Champion
Author

Hi jagan,

thanks for helping! But I think I have it now.

I didn't think of this because to my knowledge, whenever a variable contains alphanumeric digits, you needed that $-expansion - so I used it in the CALL_statement, too - but there it seems this is not allowed without regard of the variable_contents.

Now the variable is properly passed to the subroutine.

All should be well now - except in the longer run there won't be one workbook with six sheets to load, but six workbooks - the lists have to be exported manually because we will not get access to that tool for automatization, so I will try to keep that effort to the absolute minimum and work with whatever comes out of that tool.