sadrasjd
sadrasjd

Reputation: 61

Asp Classic put the Sub in the function... Can i?

why now return ....Syntax error

Can i put the Sub rutine in the function? Or better way for this?!

Function SumerizePlanArrays(f_String, f_Type)

   Set dic = CreateObject("Scripting.Dictionary")
   Sub Add(s)
       weight = Split(s,"$")(0)
       values = Split(s,"$")(1)
       pipes = Split(values, "|")
       For Each line In pipes
           val = Split(line, ",")
           if f_Type = 1 then
               dic(val(1)) = (dic(val(1))*weight/100) + CInt(val(2))
           elseif f_Type = 2 then
               dic(val(1)) = dic(val(1)) + CInt(val(2))
           end if
       Next
   End Sub

   arrString = Split(f_String,"#")
   For i = 0 to UBound(arrString)
       'wei = Split(arrString(i),"$")(0)
       Add arrString(i)
   Next

   Set a = CreateObject("System.Collections.ArrayList")
   For Each key In dic.Keys
       a.Add "0," & key & "," & dic(key)
   Next
   a.Sort
   result = Join(a.ToArray, "|")

   SumerizePlanArrays = result

End Function

Microsoft VBScript compilation error '800a03ea'

Syntax error

/inc_func_projects.asp, line 2592

Sub Add(s)
^

Upvotes: 1

Views: 1613

Answers (1)

user1945782
user1945782

Reputation:

No - you can't put a sub within a function, except in JavaScript or in the server side version called JScript. VBScript and JScript are two completely different languages, however.

You should be doing this...

Function SumerizePlanArrays(f_String, f_Type)

   Set dic = CreateObject("Scripting.Dictionary")

   arrString = Split(f_String,"#")
   For i = 0 to UBound(arrString)
       'NOTE: Updated the call to reflect comment by sadrasjd...
       Add arrString(i, f_Type, dic)
   Next

   Set a = CreateObject("System.Collections.ArrayList")
   For Each key In dic.Keys
       a.Add "0," & key & "," & dic(key)
   Next
   a.Sort
   result = Join(a.ToArray, "|")

   SumerizePlanArrays = result

End Function

Sub Add(s, type, dic)
    'NOTE: ^Updated the parameters to reflect comment by sadrasjd^
    weight = Split(s,"$")(0)
    values = Split(s,"$")(1)
    pipes = Split(values, "|")
    For Each line In pipes
        val = Split(line, ",")
        if type = 1 then
            dic(val(1)) = (dic(val(1))*weight/100) + CInt(val(2))
        elseif type = 2 then
            dic(val(1)) = dic(val(1)) + CInt(val(2))
        end if
    Next
End Sub

NOTE: Updated the call to reflect the suggestion made by sadrasjd.

Upvotes: 3

Related Questions