Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter
Odd Behavior of Counter Odd Behavior of Counter
Odd Behavior of Counter
Go Back  Xtreme Visual Basic Talk > > > Odd Behavior of Counter


Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2014, 07:27 PM
jojo69 jojo69 is offline
Freshman
 
Join Date: Oct 2008
Posts: 30
Default Odd Behavior of Counter


I have a spreadsheet with the first column as:

I. TOTAL EXPENDITURES
value
value
value
.
.
II. REVENUES
value
value
value
.
III. REIMBURSEMENT
value
value

I want to locate the titles (I-III) and use them to process the values.

Code from the main program:

Code:
k=0
totexp = getbounds(k, "I. TOTAL EXPENDITURES", a1)

rev = getbounds(k, "II. REVENUES", a1)

d = getbounds(k, "III. REIMBURSEMENT", a1)
The function called is:

Code:
Function getbounds(ByRef k As Integer, ByVal inlabel As String, ByRef a1 As SpreadsheetGear.IRange) As Integer

        Dim label As String

        Do
            k = k + 1

            label = a1.Cells(k, 0).Value

        Loop While (label <> inlabel)

        Return k

    End Function
The program runs most of the time, but sometimes goes past the label (inlabel parameter) and gives an error.

I cannot understand why it runs smoothly most of the times and not others.

There are breakpoints as well as I might continue through exceptions. Thanks for your help.
Reply With Quote
  #2  
Old 12-01-2014, 08:48 PM
Cerian Knight's Avatar
Cerian KnightOdd Behavior of Counter Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

If I am understanding your code (therefore making the assumption that SpreadsheetGear.IRange represents the entire first column and you want the function return to be a ones based row index), then the first call to getbounds will always return both k and totexp equal to 1 (which is the index of TOTAL EXPENDITURES). Obviously not what you intended. Therefore, the second call will return both k and rev equal to 'TOTAL EXPENDITURES' last value index + 1 (which is the index of REVENUES).

To correct the issue quickly for functionality, but induce total lack of clarity:
Code:
k=0
totexp = getbounds(k, "II. REVENUES", a1) - 1
rev = getbounds(k, "III. REIMBURSEMENT", a1) - 1
d = getbounds(k, "IV. END OF DATA", a1) - 1 'created title IV (or pass inlabel as "" instead if you can guarantee the last value will remain blank)
I don't intend for you to use the above code as a final solution, just as a stepping stone to see that it does what (I think) you originally intended... to illustrate the error in your logic. If you can't move the titles to separate columns, then wrapping would be a better choice (e.g. the last value of each title is the same as the title, but add a slash '/' to the name and search the entire column for both the title and /title as an integrity check).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 12-01-2014 at 08:54 PM.
Reply With Quote
Reply

Tags
oddk


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter Odd Behavior of Counter
Odd Behavior of Counter
Odd Behavior of Counter
 
Odd Behavior of Counter
Odd Behavior of Counter
 
-->