Re: Finding out if array has been dimensioned??

From: Howard Kaikow (kaikow_at_standards.com)
Date: 08/18/04


Date: Wed, 18 Aug 2004 07:18:27 -0400

You have to redim the array to the appropriate size before you start reading
the file.
But how do you know the number of elements in the file?
If you cannot redim in advance and you will have to do a redim preserves as
many times as is necessary.

-- 
http://www.standards.com/; See Howard Kaikow's web site.
"JB" <no@way.com> wrote in message
news:OguKiWTgEHA.3192@tk2msftngp13.phx.gbl...
> Helmut Weber wrote:
> > Hi JB,
> > hm..., I wonder,
> > with "option explicit" code shouldn't run at all, if a variable
> > wasn't declared (dim) . Without "option explicit", the variable is
> > dimensioned (declared) at runtime. What are the conditions, that
> > prevent the declaration? Or am I missing the point, and you want to
> > know, if the array, that didn't have an index, was redimensioned?
> > Then, have a look at this:
> > ' option explicit
> > -----
> > Dim MyArray() As String
> > On Error Resume Next
> > MsgBox UBound(MyArray)
> > If Err.Number = 9 Then
> >    MsgBox "no index" & Chr(13) & _
> >    Err.Description
> > End If
> >
> > ---
> > Greetings from Bavaria, Germany
> > Helmut Weber, MVP
> > "red.sys" & chr(64) & "t-online.de"
> > Word XP, Win 98
> Yeah Helmut..Sorry that's what I meant.
>
> I thought there might have been a handy function like IsArray (I know
> this is different) that could tell me if the array had an index?
>
> It's the ReDim portion that I'm having trouble with as I'm trying to
> write a text file with values from the doc custom styles and populate a
> listbox with the custom style values.
>
> Problem is when I come accross a doc that has no custom styles  <g>
>
> On Error GoTo CloseFile
>
> count = UBound(aStyArrName()) + 1 'here if no index falls over!!
>
> Open filename For Output As #filenumber
>
>      Print #filenumber, "[Setup]"
>      Print #filenumber, "TemplateName=" & frmStyles.txtTemplateName
>      Print #filenumber, "Count=" & count
>      Print #filenumber, ""
>
>      For i = 0 To count - 1
>          Print #filenumber, "[Style" & " " & i + 1 & "]"
>          Print #filenumber, "Name=" & aStyArrName(i)
>          Print #filenumber, "Size=" & aStyArrSize(i)
>          Print #filenumber, "FontType=" & aStyArrFont(i)
>          Print #filenumber, "StyleType=" & aStyArrStyleType(i)
> Print #filenumber, ""
>      Next
> CloseFile:
> Close #filenumber
>
> frmStyles.lstStyleNames.Clear
> count = UBound(aStyArrName()) + 1
> For i = 0 To count - 1
>      frmStyles.lstStyleNames.AddItem aStyArrName(i)
> Next
>
> etc.........
>
> Any pointers?
>
> J
>
>


Relevant Pages

  • Re: Help Please - Searching a large text file
    ... Actually you can speed that part of it up about three or four times by writing it in such a way that it does not Redim the array every single time through the loop. ... Dim LensDataArrayAs String, FileNumber As Long ...
    (comp.lang.basic.visual.misc)
  • Re: Help Please - Searching a large text file
    ... an array with about 500 elements to start with, and only Redim it when the ... Dim LensDataArrayAs String, FileNumber As Long ...
    (comp.lang.basic.visual.misc)
  • Re: ReDim not working as expected. Array expert needed.
    ... with ReDim, so I commented out the ReDim statement, and ran the procedure to ... Dim MyArray As Variant ' Declare nonarray variant. ... array comes out dimensioned as ... Sub ArrayStudies3 differs from Sub ArrayStudies2 only in that MyArray ...
    (microsoft.public.excel.programming)
  • Re: Sub to extract uniques from 200k data in xl03
    ... The first returns an array of the unique elements of the input array; ... Dim i As Long, p As Object, q As String ... ReDim outputArrayTransposeTo UBound, _ ...
    (microsoft.public.excel.programming)
  • Re: Sub to extract uniques from 200k data in xl03
    ... The first returns an array of the unique elements of the input array; by default it is a case-sensitive, 1-based, vertical array. ... Dim i As Long, p As Object, q As String ... ReDim outputArrayTransposeTo UBound, _ ...
    (microsoft.public.excel.programming)

Loading