Assign function return value to an array

V

Varun

Hey Guys,

Need some help on this...I have a function named geomsascii which returns
multiple values i.e. the function name get an array assigned to it.

I'd like to take the function's return values and put them in a different
array (layer_array) in main program but when I do that I get "can't assign to
array" error.

What am I doing wrong and how to fix this?

Thank you.

_____________________________________
Private Sub CommandButton1_Click()
Dim layer_array() As String

MenDesCont = MentDesContPath

layer_array = geomsasciiparse() <-----problem line - get CAN'T ASSIGN
ARRAY error

End Sub
_____________________________________

Public Function geomsasciiparse() As String

Dim logical_layer() As String
Dim logicallayernumber As Integer
Dim arraynumber As Integer

Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGeomsAsciiFile As Object

'Buf array stores words from each line
Dim Buf() As String

'Dimming array
'ReDim logical_layer(0)


'opening geoms_ascii file as read only from Mentor Design Container
Set objGeomsAsciiFile = objFSO.OpenTextFile(MenDesCont & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

'look for first instance of _LAYER_DEFNITION in geoms_ascii
If InStr(strLine, "_LAYER_DEFINITION") <> 0 Then

Buf() = qc_Split(strLine)

'extract logical layer number from ARTWORK_01_LAYER_DEFNITION
logicallayernumber = Mid(Buf(1), 9, 2)

'need to redim logical_layer so it can be assigned to geomsasciiparse later
ReDim Preserve logical_layer(CInt(logicallayernumber))

'ignore when ARTWORK_LAYER_DEFINITION = 00 in geoms_ascii
If logicallayernumber <> "00" Then

For buf_idx = 1 To UBound(Buf)

If InStr(Buf(buf_idx), "SIGNAL") <> 0 Or _
InStr(Buf(buf_idx), "POWER") <> 0 Then

logical_layer(CInt(logicallayernumber)) = Buf(buf_idx)
Exit For
End If
Next
End If
End If
Loop

'get rid of empty array values

'For arraynumber = 1 To UBound(logical_layer)
'If logical_layer(arraynumber) = "" Then
'ReDim Preserve logical_layer(arraynumber - 1)
'Exit For
'End If
'Next arraynumber

geomasasciiparse = logical_layer

objGeomsAsciiFile.Close

End Function
 
B

Bob Phillips

Try using variants

Private Sub CommandButton1_Click()
Dim layer_array AS Variant

MenDesCont = MentDesContPath

layer_array = geomsasciiparse()

End Sub
_____________________________________

Public Function geomsasciiparse() As Variant

Dim logical_layer AS Variant
Dim logicallayernumber As Integer
Dim arraynumber As Integer

Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGeomsAsciiFile As Object

'Buf array stores words from each line
Dim Buf() As String

'Dimming array
'ReDim logical_layer(0)


'opening geoms_ascii file as read only from Mentor Design Container
Set objGeomsAsciiFile = objFSO.OpenTextFile(MenDesCont & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

'look for first instance of _LAYER_DEFNITION in geoms_ascii
If InStr(strLine, "_LAYER_DEFINITION") <> 0 Then

Buf() = qc_Split(strLine)

'extract logical layer number from ARTWORK_01_LAYER_DEFNITION
logicallayernumber = Mid(Buf(1), 9, 2)

'need to redim logical_layer so it can be assigned to geomsasciiparse later
ReDim Preserve logical_layer(CInt(logicallayernumber))

'ignore when ARTWORK_LAYER_DEFINITION = 00 in geoms_ascii
If logicallayernumber <> "00" Then

For buf_idx = 1 To UBound(Buf)

If InStr(Buf(buf_idx), "SIGNAL") <> 0 Or _
InStr(Buf(buf_idx), "POWER") <> 0 Then

logical_layer(CInt(logicallayernumber)) = Buf(buf_idx)
Exit For
End If
Next
End If
End If
Loop

'get rid of empty array values

'For arraynumber = 1 To UBound(logical_layer)
'If logical_layer(arraynumber) = "" Then
'ReDim Preserve logical_layer(arraynumber - 1)
'Exit For
'End If
'Next arraynumber

geomasasciiparse = logical_layer

objGeomsAsciiFile.Close

End Function
 
G

gimme_this_gimme_that

I think this is the short answer to your question.

Notice the parenthesis after "As String".

Public Function geomsasciiparse() As String()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top