Getting a type mismatch when I try to make an assignment in an LS agent. Following are excerpts form the code:
Class Product
Public type As String
Public name As String
Public mktcompany As String
Public newapprovalstate List As String
Public apprcomments List As String
Public unid As String
Public myRef As Product 'Reference to an object of this class
End Class
.
.
.
Dim arr_Comments
Redim arr_Comments(0)
arr_Comments(0) = “”
Dim commentItem As Variant
.
.
.
For i=0 To Ubound(arr_States)
Set item = doc.GetFirstItem( “Cdate_” & Cstr(i) )
Set commentItem = doc.GetFirstItem(“Comments_” & Cstr(i) )
.
.
.
Redim Preserve arr_Comments(i)
Set arr_Comments(i) = commentItem
.
.
.
For i=0 To Ubound( arr_PMStateAppr )
prod(doccount).newapprovalstate(i)= arr_PMStateApprDates( i ) & " " & arr_PMStateAppr( i )
prod(doccount).apprcomments(i) = Cstr(arr_Comments(i))
Next
I get the type mismatch on the line
prod(doccount).apprcomments(i) = Cstr(arr_Comments(i))
I’ve run debug and arr_comments(i) is a variant and apprcomments(i) is a string … what am I doing wrong???
Thanks in advance.
Subject: Array type mismatch
Mary,
Since newapprovalstate is a list object, your list tag needs to be a string, not a numeric value as you are passing it with your i variable.
According to the help documentation on List:
A list is initially empty. You add elements to it with statements of the following form:
listName( listTag ) = value
where listName is the name of the list, listTag is a string that uniquely identifies the element, and value is the value you want to assign to the element.
You may need to covert i to a string before you assign your value–i’d bet dollars to donuts that the data type of the tag is causing the type mismatch.
hth.
brandt
Subject: RE: Array type mismatch
Hi Brandt,
I tried your suggestion w/o any luck. Thanks for your help.
Subject: Array type mismatch
And why are you using:
For i=0 To Ubound( arr_PMStateAppr )
???
Use ForAll.
Subject: RE: Array type mismatch
I didn’t write this code … only trying to add some more lines of output to a report it e-mails out. So that’s why it’s not using “forall”.
hcl-bot
November 8, 2006, 12:33pm
6
Subject: RE: Array type mismatch
You need to redim and preserve the array contents as follows:
For i=0 To Ubound( arr_PMStateAppr )
prod(doccount).newapprovalstate(i)= arr_PMStateApprDates( i ) & " " & arr_PMStateAppr( i )
If i=0 then redim prod(doccount).apprcomments(i)
If i > 0 then redim preserve prod(doccount).apprcomments(i)
prod(doccount).apprcomments(i) = Cstr(arr_Comments(i))
Next