Results 1 to 11 of 11
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    run code incorrect value - debug correct value? (word97 sr2b)

    Hi

    I have code which does the following:
    for purely formatting purposes in my doc

    I have a table with 1 column & 4 rows
    my code obtains the lines within each cell & then calculates the total lines.
    eg the 1st cell may has 5 lines, when I step thru my code the variable returned is the correct value ie 5 lines.
    However if I run the code (ie no breakpoints) for the 1st cell the variable will return an incorrect value of 1line - therefore the rest of my code which is based on the total lines calculated ie the formatting is thrown all out.

    the starting position is the 1st cell & my code goes to a bookmark in this 1st cell.

    I've checked & defined all my variables correctly.
    Has anyone come across this issue?
    I'm not quite sure if you require more information? please let me know.

    many thanks
    Diana

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: run code incorrect value - debug correct value? (word97 sr2b)

    It would help if you posted your code, or at least the part that counts the lines within a cell. You could also attach a (dummy) document that demonstrates the problem.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Part1 - run code incorrect value -

    Hi Hans

    I've attached my code in the .txt file & a sample doc in the next post.
    In the bit of code that determines the type of template its returning the value 1 for the 1st cell.

    eg at the lines of...
    'if template is NSW_District or NSW_Supreme -obtain the total lines for the top 3 cells
    If strNSWCourt = "District" Or strNSWCourt = "Supreme" Then

    'however if the template is NSW_Land&Environment - obtain the total lines for cells 1,3 & 4
    ElseIf strNSWCourt = "Land" Then

    The 1st cell has a minium of 5 lines - however the 1st time the code is run returns the value of 1.
    However if I step thru the code or occasionally when I rerun the code the value returned is correct.

    I really have no idea whats going on.
    if you can find anything please let me know it would be greatly appreciated.
    Diana

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Part2: run code incorrect value

    HI Hans

    part 2 - attached is my dummy test doc to play around with.

    Diana

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Part1 - run code incorrect value -

    In Word97, can you do this? In Word2000, this is an alternative to using the dialog:

    lngLines = Selection.Range.ComputeStatistics(wdStatisticLines )

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Part1 - run code incorrect value -

    I'll give it ago...& let you know the results.
    many thanks Diana

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Part2: run code incorrect value

    I tested your code and document in Word 2002. The behavior of the function seems to be flaky indeed - sometimes, the code doesn't seem to be executed at all. Try "compiling" the code: in the Visual Basic Editor, select Debug | Compile, then save the template or document containing the code. In my tests, it worked OK after that. If the code is not "compiled", it is not initialized correctly, it seems.

    BTW: I don't understand why you assign the line count to one variable, convert it to a string, then assign it to another variable, and assign that to the return value of the function. The following is equivalent (plus it has error handling):

    Public Function ObtainLineCount() As Long
    On Error GoTo ErrHandler
    'select the text in the table cell area
    Selection.SelectRow
    Selection.Cells(1).Range.Select
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    ' Either this (from Jefferson)
    ObtainLineCount = Selection.Range.ComputeStatistics(wdStatisticLines )
    ' Or this (from your original code)
    With Dialogs(wdDialogToolsWordCount)
    .Execute
    ObtainLineCount = .Lines
    End With
    Selection.Collapse wdCollapseStart
    Exit Function
    ErrHandler:
    MsgBox Err.Description
    End Function

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Part2: run code incorrect value

    Hi Hans -

    I always compile my code.
    I added your amended code >tested it & it worked OK.
    I'll wait to see the response when the users furhter test & work with it.

    many thanks
    Diana

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Part2: run code incorrect value

    I've used & amended Hans code & obtained the page numbers found of the search.
    I created a template & placed the template in our startup directory.
    now when I open Word - I get the error message '5180 cannot open up template'. >click OK & I can use the code OK.

    by the way in Woodys Lounge were has the Search feature disappeared to? as I used that quite often.

    any ideas?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Part2: run code incorrect value

    Don't know what causes the error in Word.

    About the Search feature: see <post#=250092>post 250092</post#> and <post#=253135>post 253135</post#>.

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Part2: run code incorrect value

    cheers Diana

Posting Permissions

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