Results 1 to 9 of 9
  1. #1
    kelliel
    Guest

    LIstbox Weirdness - not reading value prop.

    I have two listbox controls on a Word 97 SR2 VBA form, lstGeneralCourt and lstSpecificCourt.

    In lstGeneralCourt, I populate it via a procedure called in the Initialize procedure of the UserForm.

    I populate lstSpecificCourt based on lstGeneralCourt.ListIndex. The lstGeneralCourt_Change event calls a procedure which, based on lstGeneralCourt.Value, populates lstSpecificCourt with the specific information.

    Result: General courts are USDC, Superior, PTO, etc. When lstGeneralCourt.Value = "USDC", lstSpecificCourts are Western District of Washington, Eastern District of Washington, etc.

    Hopefully the background to this problem is clear.

    I would like to insert in a document all the possibilities of courts, laid out like: General, Specific.

    I run the form (F5), it initializes, then I click the OK command button, which calls the below procedure:

    <pre>Sub PrintOutAllCourts()

    Dim intGCounter As Integer ' for General Court Counter
    Dim intSCounter As Integer ' for Specific Court Counter

    Documents.Add


    For intGCounter = 0 To frmCourtInformation.lstGeneralCourt.ListCount - 1
    frmCourtInformation.lstGeneralCourt.ListIndex = intGCounter
    For intSCounter = 0 To frmCourtInformation.lstSpecificCourt.ListCount - 1
    frmCourtInformation.lstSpecificCourt.ListIndex = intSCounter
    With frmCourtInformation.lstSpecificCourt
    Selection.TypeText frmCourtInformation.lstGeneralCourt.Value
    Selection.TypeText ", "
    Selection.TypeText frmCourtInformation.lstSpecificCourt.Value
    Selection.TypeParagraph
    End With
    Next intSCounter
    Next intGCounter

    End Sub
    </pre>


    Here's the problem. I just get a list like:

    <pre>USDC,
    USDC,
    USDC,
    Superior Court,
    Superior Court,
    Superior Court,
    PTO,
    PTO,
    PTO,
    PTO,
    Appeal,
    Appeal,
    Appeal,
    Miscellaneous,
    Miscellaneous,
    Miscellaneous,
    </pre>


    And, I can't future out why the specific courts are not being listed.

    Ideas?

    Thanks

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LIstbox Weirdness - not reading value prop.

    Lawrence,

    Try this:

    <pre> Dim intGCounter As Integer ' for General Court Counter
    Dim intSCounter As Integer ' for Specific Court Counter
    Documents.Add
    For intGCounter = 0 To lstGeneralCourt.ListCount - 1
    For intSCounter = 0 To lstSpecificCourt.ListCount - 1
    Selection.TypeText lstGeneralCourt.List(intGCounter) & ", " & _
    lstSpecificCourt.List(intSCounter) & vbCrLf
    Next intSCounter
    Next intGCounter
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    kelliel
    Guest

    Re: LIstbox Weirdness - not reading value prop.

    I'll try it in the morning, at work.

    I thought that I had tried something like that, but maybe not.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LIstbox Weirdness - not reading value prop.

    Lawrence,

    With a little more time to reply, a few thoughts (ie, open for general discussion).

    I'm not sure why the listindex doesn't work well. I ran your procedure once, and it worked as you suggested; I ran it immediately again, and had a different result. Usintg the List(Index) has worked OK for me before, that's why I posted.

    By not using the listindex, the code is shortened as well.

    Also, I'm not fond of using "selection.typetext". As a quick, I posted a shorter selection.typetext- but the trouble with using "selection" is that it physically shifts the screen around- and slows down processing- quite visibly at times.

    I'd prefer to use the "range" object for posting text- or, if possible, to set up text and then put it into the document only once:

    So:<pre>Dim rngData As Range
    Documents.Add
    Set rngData = ActiveDocument.Range
    rngData.Text = rngData.Text & "AAA" & vbcrlf
    rngData.Text = rngData.Text & "BBB"
    </pre>

    Is better than:<pre>Dim rngData As Range
    Documents.Add
    Selection.TypeText "AAA"
    Selection.Typeparagraph
    Selection.Text "BBB"
    </pre>



    You can shortent the way you add rngData.text- but it probably won't have the same performance improvement as using ranges.

    Every use of "Selection." seems to invoke a window refersh- and that is expensive, relative to other operations.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    kelliel
    Guest

    Re: LIstbox Weirdness - not reading value prop.

    I found that the results were quirky, too.

    In defense of Selection.TypeText. [img]/forums/images/smilies/smile.gif[/img] This little procedure was just to get on paper what was happening. Finally, after a lot of fooling around, I manually manipulated the results. I then had to send the page to my "client" to see if it was meeting the design criteria.

    Even though I have used Selection a lot, for "production" code, I usually surround it with ScreenUpdating = False, or the new LockWindow procedure I have discovered (with y'll's help).

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LIstbox Weirdness - not reading value prop.

    Lawrence,

    I've found "selection" is something I've used heaps, because that's what I get when I record an action. It's only after some time I've found out about ranges (most of all coming from Wordbasic). It's only a very long time later that I've started to learn about ranges- and I've found them so much faster. Even "screenupdating=false" doesn't compare with the speed of using ranges.

    It's even more effective when using two objects (flaky untested code to follow- ideas only are important

    <pre>Dim rngDataFrom as Range, rngDataTo as Range, i as long
    set rngDataFrom = ActiveDocument.Range
    Documents.Add
    Set rngDataTo = ActiveDocument.Range
    for i = 1 to 5
    rngDataTo.Text = rngDataFrom.Bookmarks("AddFromHere" & i).Text
    next
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    kelliel
    Guest

    Re: LIstbox Weirdness - not reading value prop.

    I finally took the time to compare your code with mine.

    I haven't used the listbox control very often; therefore, I am not aware of what to use when. That is why I chose ListIndex, instead of List.

    Thanks. Works great.

  8. #8
    kelliel
    Guest

    Re: LIstbox Weirdness - not reading value prop.

    I guess the only way that using Range will come second nature is to use it! Period! Even in the down-and-dirty-quicky procedures.

    Thanks.

  9. #9
    kelliel
    Guest

    Re: LIstbox Weirdness - not reading value prop.

    Using your two posts, this is what I came up with:

    <pre>Sub PrintOutAllCourts()

    Dim intGCounter As Integer ' for General Court Counter
    Dim intSCounter As Integer ' for Specific Court Counter
    Dim rngMy As Range

    Documents.Add

    Set rngMy = ActiveDocument.Range

    For intGCounter = 0 To frmCourtInformation.lstGeneralCourt.ListCount - 1
    For intSCounter = 0 To frmCourtInformation.lstSpecificCourt.ListCount - 1
    rngMy.Text = frmCourtInformation.lstGeneralCourt.List(intGCount er) & ", " & _
    frmCourtInformation.lstSpecificCourt.List(intSCoun ter) & vbCrLf
    rngMy.Collapse wdCollapseEnd
    Next intSCounter
    Next intGCounter

    End Sub
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •