+ Reply to Thread
Results 1 to 2 of 2

Variable reference

Hybrid View

  1. #1
    DoctorG
    Guest

    Variable reference

    I use the following call to fetch a number from another open spreadsheet.

    The call is successful, the FetchWages Function works as expected and
    assigns the result to its 3rd Parameter (named wages in the FetchWages
    function).

    Yet, upon returning, the wnCurWages parameter in the calling program remains
    0.

    Is it a problem of variable declaration, scope, reference or what?

    Call Application.Run("Misthoi.xls!FetchWages", wcCurEmpl, Format(wnCurDate,
    "#"), wnCurWages)
    .......
    Public Function FetchWages(emp_code, search_date, wages)

    Workbooks("Misthoi.xls").Activate
    Worksheets("Data").Activate
    evaluate_string = "MATCH(1,(R_CODES=" & emp_code & ")*(R_FROM<=" &
    search_date & ")*(R_TO >=" & search_date & "),0)"
    table_row = Evaluate(evaluate_string)

    If IsNumeric(table_row) Then
    wages = Application.Index(Range("D_WAGES"), table_row, 7)
    Else
    wages = 0
    End If

    End Function


  2. #2
    DoctorG
    Guest

    RE: Variable reference

    OK, I figured it out myself. A function's return value is its own name.

    The following code works...

    Public Function FetchWages(emp_code, search_date)

    Workbooks("Misthoi.xls").Activate
    Worksheets("Data").Activate
    evaluate_string = "MATCH(1,(R_CODES=" & emp_code & ")*(R_FROM<=" &
    search_date & ")*(R_TO >=" & search_date & "),0)"
    table_row = Evaluate(evaluate_string)

    If IsNumeric(table_row) Then
    FetchWages = Application.Index(Range("D_WAGES"), table_row, 7)
    Else
    FetchWages = 0
    End If

    End Function


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1