Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8346161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:55:14+00:00 2026-06-09T06:55:14+00:00

I am having an issue with VBS variable value assignment: Dim varName varName =

  • 0

I am having an issue with VBS variable value assignment:

Dim varName  
varName = function(x, y)
varName = function(x, y)

function is a recursive function, which calls itself:

Function function(x, y)
    If IsObject(dicColumnIndices) Then
        function = CInt(dicColumnIndices.Item(y))
    Else
        Set oCDSGrid = %MyAppObject%
        Set dicColumnIndices = CreateObject("Scripting.Dictionary")
        intColumnCount = oCDSGrid.ActiveSheet.Columns.Count
        For i = 0 To intColumnCount - 1
            dicColumnIndices.Add oCDSGrid.ActiveSheet.Columns.Item(i).Label, i
        Next

        function x, y
    End If
End Function

As far as I can see, the variable value assignment only happens on the second try. I figured it has something to do with my function recursively calling itself (the issue is gone in case I remove the recursive call), but I shall very much like to learn what are the roots of this behaviour.

I looked up both StackOverflow and the Internet with no luck.

Edit:
In order to solve this issue, I had to remove the recursive call:

Function function(x, y)
If IsObject(dicColumnIndices) Then
    function = CInt(dicColumnIndices.Item(y))
Else
    Set oCDSGrid = %MyAppObject%
    Set dicColumnIndices = CreateObject("Scripting.Dictionary")
    intColumnCount = oCDSGrid.ActiveSheet.Columns.Count
    For i = 0 To intColumnCount - 1
        dicColumnIndices.Add oCDSGrid.ActiveSheet.Columns.Item(i).Label, i
    Next

    function = CInt(dicColumnIndices.Item(y))
End If
End Function

Edit 2: Finally, with help from MSDN I got the wrong part – it is the second call

function x, y

which returns the value into nothing, must be changed to:

function = function x, y

Thanks everyone!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:55:15+00:00Added an answer on June 9, 2026 at 6:55 am

    A function shouldn’t be called function, and varname is a lousy name for a variable. More to the point: In VBScript a function isn’t a function (does not return something) if you don’t ‘assign to the function name’:

      Dim s : s = "abcdefg"
      Dim l : l = recLen(s)
      WScript.Echo "recursive length of", qq(s), "=>", l, CStr(l = Len(s))
    
      Function recLen(s)
        If "" = s Then
           recLen = 0
        Else
           recLen = 1 + recLen(Mid(s, 2))
        End If
      End Function
    

    (The length of an empty string is 0; for longer strings it’s 1 + the length of the string’s ‘tail’)

    Update (thanks to AutomatedChaos):

    Function qq( vStringable )
      qq = """" & vStringable & """"
    End Function
    

    Update II (to answer Eugene’s question in comment):

    To make a function to return something, you’ll have to assign the value to return to a variable having the same name as the function. Your original code didn’t (even if the name “function” was replaced by the ‘real’ name).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having issue in checking which input has been clicked using unobstructive javascript.
Having some issue with my function call please. I have a situation that I
I'm having issue assigning regex value to a string. Issue that I have is
I'm having issue with calling a method with l-value of an abstract class. The
I am having issue with my js function within a ADF Faces af:interator .
I am trying to display an array which by itself is no issue. However,
I'm having issue with WPF and the way it should be implemented which wondering
Having issue with slider navigation. Works perfectly fine when there are no other unordered
I having issue that content assistant / intellisense is working in methods such as
Hi guys I am having issue I have this query: SELECT * FROM useraccount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.