Re: Array Type Mismatch



Hi,


You cannot assign a predetermined Array, even if it has the right
dimensions. You can only assign (use on the left side of the equal sign) an
un-determined (redim -able) array.

When you comment out (the valid line)

TextBoxGetLine = result()


which indicated which result is to be returned by your function, your
function STILL RETURNS an array, because of its header (signature):



Public Function TextBoxGetLine( ....arguments... ) As String()



note the As String(). It should be As String without parenthesis, to
return just ONE single string, not an array of string.

When a function is meet, VBA creates a variable with the name of the
function. Here, VBA creates a variable TextBoxGetLine As String(). That
variable is an array of string, and CAN accept the instruction

TextBoxGetLine = result()


since it is redim-able. If you comment it out, you just get a redim-able
array as result. The problem is not there, but it is when you try to
capture the result in your ***CALLING*** code:


myVariable(index) = TextBoxGetLine( ... )


So, either remove the () in the function signature (AND return JUST ONE
STRING), either keep your function as it is, and make your variable a
redim-able variable, in your CALLING code (and do NOT use a index):

myRedimable = TextBoxGetLine( ... )

and not

myRedimable(index) = TextBoxGetLine( ... )


either, finally, make your variable, in you calling code, as VARIANT rather
than as STRING (but that means you just move the problem to somewhere else
in your code, I think).


Hoping it may help,
Vanderghast, Access MVP




"State Troopers" <StateTroopers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F683963B-198A-4EF9-912F-6163627D27DD@xxxxxxxxxxxxxxxx
Hi.

I tried commenting out:
TextBoxGetLines = result()

and I still recieve the type mismatch error.

strArray is pre-determined ...strArray(6) as string

Am I passing the variables correctly,
strArray(i) = TextBoxGetLines(txtDone, False)

From what I can tell the function requires a "textbox" name, and a
true/false.
Function TextBoxGetLines(tb As TextBox, Optional KeepHardLineBreaks As
Boolean) As String()


...and the loop for the array

For i = 0 To UBound(strArray)
strArray(i) = TextBoxGetLines(txtDone, False)
Debug.Print i & " " & strArray(i)
Next


I have no idea why I am getting type mismatch.

your help is appreciated.

Thanks.
-State



"Michel Walsh" wrote:

Hi,


Your function return an array of string and you try to fit this array
inside
a container devised to hold just a single string (I assume strArray is
dim
as String(), not as Object() ).

=======================
Public Sub Void()
Dim array1(1 To 2) As String
Dim array2() As String
Dim array3(1 To 2) As Variant
Dim array4() As String

array2 = Split("aaa bbb ccc")
array3(1) = array2
array4 = array2
array1(1) = array2


End Sub
========================


the last executable line produces your mismatch, comment it and every
thing
is fine.

You can:
assign an array of string to a redim-ensionable array of string
(array2 = split(...) )
assign an array of string to a variant or an object container
(array3(1) = array2)
assign an array of string to a redim-ensionable array of string (
array4=array2)

You cannot:
assign an array to a non-variant non-object container
assign an array to a non-redim-ensionable array: array3=array1
would fail, even if both are dimmed as array (1 to 2) and even if a
variant
can hold a string.


That is assuming you use VBA6. Previous versions (Access 97 and older)
don't
necessary play the same game, and don't have built-in functions like
split.


Hoping it may help,
Vanderghast, Access MVP


"State Troopers" <StateTroopers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:F88EA92C-26F6-4759-95C9-ABEABAF313FC@xxxxxxxxxxxxxxxx
Hi.
I am having a problem with one of my functions.

here is the code:


strArray(i) = TextBoxGetLines(txtDone, False)

-------


Function TextBoxGetLines(tb As TextBox, Optional KeepHardLineBreaks As
Boolean) As String()

TextBoxGetLines = result()

End Function




Am I passing the variables into the function correctly?

Thanks.
-State








.



Relevant Pages

  • Re: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)
  • Re: Structure conversion from C++ to VB-2008?
    ... Public Structure AmiVar ... Dim type As Integer ... Public *array as Single ... Public *string as String ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: Array Type Mismatch
    ... Boolean) As String() ... Nothing is stored in the array. ... Dim resultAs String ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)

Loading