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

Creating/setting a variable in a UDF for use in the script

Hey all,

For a flag I'm attempting to generate, I need to create a function that will read in the current month of a project (in my calendar) and return the next month. I've been having trouble finding good documentation defining the relationship between module (User Defined Function) and the script. Here is the current function I've developed:

function NextMonth(MonthParam)

dim NewMonth

IF MonthParam = "Oct" then set vNewMonth = "Nov"

IF MonthParam = "Nov" then set vNewMonth = "Dec"

IF MonthParam = "Dec" then set vNewMonth = "Jan"

IF MonthParam = "Jan" then set vNewMonth = "Feb"

IF MonthParam = "Feb" then set vNewMonth = "Mar"

IF MonthParam = "Mar" then set vNewMonth = "Apr"

IF MonthParam = "Apr" then set vNewMonth = "May"

IF MonthParam = "May" then set vNewMonth = "Jun"

IF MonthParam = "Jun" then set vNewMonth = "Jul"

IF MonthParam = "Jul" then set vNewMonth = "Aug"

IF MonthParam = "Aug" then set vNewMonth = "Sep"

IF MonthParam = "Sep" then set vNewMonth = "Oct"

end function

A few of the things I'm curious about are:

     - Do you need to define a variable type for an input parameter

     - Can you have a function return a value, or must you set a new variable in the function

     - Can you input a string? How do the quotes work, a single quote is a comment and leaving it blank seems wrong

     - How do you use a variable you set in a function in your script?

1 Solution

Accepted Solutions
Clever_Anjos
Employee
Employee

I would create a variable using this (I usually dont use macros or Vb script)

Date(Addmonths(MakeDate(1900,'$1'),1),'MMM')

and use like this

=$(vNextMonth(02)) // returns 'mar'

Capturar.PNG

View solution in original post

2 Replies
Clever_Anjos
Employee
Employee

I would create a variable using this (I usually dont use macros or Vb script)

Date(Addmonths(MakeDate(1900,'$1'),1),'MMM')

and use like this

=$(vNextMonth(02)) // returns 'mar'

Capturar.PNG

Anonymous
Not applicable
Author

Thanks! works like a charm