Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Taking value from one array and assigning to another array

Guys,

I am not able to figure out why I am getting the subscript out of range
error for the when the below sub is ran...the problem line is:

logical_layer(logicallayernumber) = Buf(buf_idx)

The sub opens up a file then parses each line until the required line is
found and then puts every word in that line into an array named Buf.

I'd like to take the value from the Buf array and put into another (new)
array named logical_layer - can you help me figure out what's wrong?

Thanks for help.





Sub geomsasciiparse()
Dim logical_layer() As Variant
Dim logicallayernumber As Integer

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

Dim Buf() As String

Set objGeomsAsciiFile = objFSO.OpenTextFile(path1 & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

If InStr(strLine, "_LAYER_DEFINITION") < 0 Then

Buf() = qc_Split(strLine)

logicallayernumber = Mid(Buf(1), 9, 2)

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(logicallayernumber) = Buf(buf_idx)


Exit For

End If

Next


End If


End If
Loop

objGeomsAsciiFile.Close

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Taking value from one array and assigning to another array

I think you need to Redim logical_layer() as you increment logicallayernumber
(you are incrementing by one each time, I hope?) Something like

logicallayernumber = Mid(Buf(1), 9, 2)
Redim Preserve logical_layer(logicallayernumber)

Hope this helps,

Hutch

"Varun" wrote:

Guys,

I am not able to figure out why I am getting the subscript out of range
error for the when the below sub is ran...the problem line is:

logical_layer(logicallayernumber) = Buf(buf_idx)

The sub opens up a file then parses each line until the required line is
found and then puts every word in that line into an array named Buf.

I'd like to take the value from the Buf array and put into another (new)
array named logical_layer - can you help me figure out what's wrong?

Thanks for help.





Sub geomsasciiparse()
Dim logical_layer() As Variant
Dim logicallayernumber As Integer

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

Dim Buf() As String

Set objGeomsAsciiFile = objFSO.OpenTextFile(path1 & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

If InStr(strLine, "_LAYER_DEFINITION") < 0 Then

Buf() = qc_Split(strLine)

logicallayernumber = Mid(Buf(1), 9, 2)

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(logicallayernumber) = Buf(buf_idx)


Exit For

End If

Next


End If


End If
Loop

objGeomsAsciiFile.Close

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Taking value from one array and assigning to another array

You haven't defined any bounds for the logical_layer array.
Need to do that first: a VBA array is not like other languages' associative
arrays where you can arbitrarily assign values.
If that what you need then maybe use Scripting.Dictionary instead.

Tim.


"Varun" wrote in message
...
Guys,

I am not able to figure out why I am getting the subscript out of range
error for the when the below sub is ran...the problem line is:

logical_layer(logicallayernumber) = Buf(buf_idx)

The sub opens up a file then parses each line until the required line is
found and then puts every word in that line into an array named Buf.

I'd like to take the value from the Buf array and put into another (new)
array named logical_layer - can you help me figure out what's wrong?

Thanks for help.





Sub geomsasciiparse()
Dim logical_layer() As Variant
Dim logicallayernumber As Integer

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

Dim Buf() As String

Set objGeomsAsciiFile = objFSO.OpenTextFile(path1 & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

If InStr(strLine, "_LAYER_DEFINITION") < 0 Then

Buf() = qc_Split(strLine)

logicallayernumber = Mid(Buf(1), 9, 2)

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(logicallayernumber) = Buf(buf_idx)


Exit For

End If

Next


End If


End If
Loop

objGeomsAsciiFile.Close

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Taking value from one array and assigning to another array

Thanks Guys - that was it! Much appreciated.

"Tim Williams" wrote:

You haven't defined any bounds for the logical_layer array.
Need to do that first: a VBA array is not like other languages' associative
arrays where you can arbitrarily assign values.
If that what you need then maybe use Scripting.Dictionary instead.

Tim.


"Varun" wrote in message
...
Guys,

I am not able to figure out why I am getting the subscript out of range
error for the when the below sub is ran...the problem line is:

logical_layer(logicallayernumber) = Buf(buf_idx)

The sub opens up a file then parses each line until the required line is
found and then puts every word in that line into an array named Buf.

I'd like to take the value from the Buf array and put into another (new)
array named logical_layer - can you help me figure out what's wrong?

Thanks for help.





Sub geomsasciiparse()
Dim logical_layer() As Variant
Dim logicallayernumber As Integer

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

Dim Buf() As String

Set objGeomsAsciiFile = objFSO.OpenTextFile(path1 & "\geoms_ascii", 1)

Do While Not objGeomsAsciiFile.AtEndOfStream
strLine = objGeomsAsciiFile.Readline

If InStr(strLine, "_LAYER_DEFINITION") < 0 Then

Buf() = qc_Split(strLine)

logicallayernumber = Mid(Buf(1), 9, 2)

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(logicallayernumber) = Buf(buf_idx)


Exit For

End If

Next


End If


End If
Loop

objGeomsAsciiFile.Close

End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Taking the Zeros out of an array when displaying Bullytt Excel Discussion (Misc queries) 7 January 7th 10 09:32 PM
Assigning to an array Geoff Excel Programming 7 June 13th 08 07:21 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R[_2_] Excel Programming 3 November 13th 07 04:08 PM
Assigning 10x1 array to 2nd collumn of 10x3 array Alan Beban[_2_] Excel Programming 0 July 30th 04 01:38 AM
Assigning 10x1 array to 2nd collumn of 10x3 array Myrna Larson Excel Programming 0 July 29th 04 11:57 PM


All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"