Forum Discussion

Vahan's avatar
Vahan
Contributor
14 years ago

Error when calling one function from another

I have to scripts: A & B. Each script has only one function in it. I want the function in script A to call the function in script B. I have also added the 'USEUNIT B to the beginning of script A. When I run script A I get an error message "Object doesn't support this property or method: '<functionname>'" . Can anyone tell me where I am going wrong?

Here is the code:

Script A


'USEUNIT CheckCurrentAllergiesForItem

Function SetAndCheckCommonAllergies(object, action)

  DIM grid, match

  SET grid = Aliases.Amazing_Charts.frmPatientAllergies.CurrentAllergy_fra.gridPatientAllergies

  select Case object.Text

    case "Ace Inhibiters" item = "angiotensin converting enzynme inhibitor"

    case "Codeine" item = "codeine"

    case "Penicillins" item = "penicillin"

  End Select

  If action = TRUE Then

    If object.wState = cbUnchecked Then       'If checkbox is unchecked then click it, if not then do nothing

      object.Click  

    End if    

  Else

    If object.wState = cbChecked Then       'If checkbox is checked then click it, if not then do nothing

      object.Click  

    End if

  End if

  SetAndCheckCommonAllergies = CheckCurrentAllergiesForItem(item,TRUE)

End Function



Script B


Function CheckCurrentAllergiesForItem (Allergy, Logic)

  DIM grid, match

  SET grid = Aliases.Amazing_Charts.frmPatientAllergies.CurrentAllergy_fra.gridPatientAllergies

  match = FALSE

  For row = 0 to grid.RowCount()-1

    Set Cell = grid.wValue(row,2)

    CellValue = Cell.OleValue

    if Allergy = CellValue Then

      match = TRUE

    End IF

  Next

  If Logic = TRUE Then

    If match = TRUE then

      CheckCurrentAllergiesForItem = TRUE

    Else

      CheckCurrentAllergiesForItem = FALSE

    End if

  Else

    If match = TRUE then

      CheckCurrentAllergiesForItem = FALSE

    Else

      CheckCurrentAllergiesForItem = TRUE

    End if

  End If

End Function

  • Hi Chris,



    Actually, when you have two accessible identifiers with the same name in the same unit (in your example, 'AlterOrder' declared via USEUNIT and 'AlterOrder' declared as a function), any 'AlterOrder' function call should fail due to identifier conflicts if you don't use its full name. This behavior is correct. As for why such calls succeed in some of your projects, I cannot say anything for sure without having an example demonstrating both a failing and a succeeding case.



    Do you use VBScript in all cases? I'm asking because it is case-insensitive. If you use JScript (case-sensitive), there shouldn't be conflicts since 'AlterOrder' and 'alterOrder' are different identifiers in this case.