|
Thank you Sascha for you're answer
Yes I know that you are volunteers but i said it's "urgent" because it been so long that i'm looking for a solution.
I've run it step by step and it dosen't make changes and for that reason i didn't know what to do :/
and i'm sure that the problem is in that part.
Thanks again
|
|
|
|
|
iRow is a Double which makes little sense for a row counter. I don't think it's the cause of the problem but I'd change it to Integer .
As iRow is incremented unconditionally and all other loops are For-Each-loops it's not obvious to me where and why this code would loop indefinitely.
Dorsaf Ouersighni wrote: I've run it step by step and it dosen't make changes So your next task for debugging is to determine why it doesn't make changes (which would lead to a loop termination).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I really don't know why The WHY is what i'm looking for.
and As you said " all other loops are For-Each-loops it's not obvious to me where and why this code would loop indefinitely. "
Even when i changed iRow to Integer, nothing changes and there is nothing warning in the project; no erreurs and no warning
That's disturbing
|
|
|
|
|
Dorsaf Ouersighni wrote: I really don't know why The WHY is what i'm looking for. If a loop gets executed indefinitely it's because its condition to keep running keeps evaluating to true. So, if it's the while-loop that executes indefinitely
While (iRow <= (DataGridView_impot.Rows.Count - 1))
then it has to be because iRow always has a value lower than the amount of rows. That's not intended of course - so you would have to find out (using the debugger) why this is so in order to fix it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks a lot Sascha
I think that's TRUE. When i changed iRow bigger than the condition, it stop executing indefinitely.
I will try to fix it immediatly.
I really appreciate you're effort and thank you very much
I will send you back the result
Have a nice day
By the way you have a beautiful name
|
|
|
|
|
I'm guessing that the infinite looping doesn't occur within the posted Sub. Instead, I assume, e.HasMorePages always gets set to true so that the PrintPage-event automatically gets fired again so the Sub gets called again. You can verify this by placing a debug-breakpoint on this line:
If bMorePagesToPrint Then
When you get there, inspect the value of bMorePagesToPrint (I suspect it will always be true ) and then press F5 (continue execution until next breakpoint) which will probably get you to that same line again and again.
If this is the case, then the condition on this line
If (iTopMargin + (iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top))) Then never evaluates to false so that bMorePagesToPrint always gets set to true . Then you would have to figure out why this condition never evaluates to false - this is hard to guess for me by looking at the code only.
Dorsaf Ouersighni wrote: By the way you have a beautiful name Thank you
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thanks a lot Sascha
The whole problem was "()" wrong and when i remove it, it doesn't execute infinitly
If (iTopMargin + iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top)) Then
instead of
If (iTopMargin + (iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top))) Then
it stays just to reorganize my DataGridView in the previw dialog before printing it
|
|
|
|
|
Dorsaf Ouersighni wrote: thanks a lot Sascha You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I would recommend you to always use
Option Strict On
(at the very top of your code files).
With that option active Visual Studio would have given you an error (along the lines "can't implicitly convert from boolean to integer") for that line where you got the brackets wrong. Basically it forces you to always express your intent clearly and thus avoids situations like these.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I really appreciate your help
I will use it. Thank you very much
|
|
|
|
|
I would go one step further than what Sascha recommends.
Open Tools > Options
In the left pane select Projects and Solutions > VB Defaults
On the right side set Option Strict to On.
Now all new projects have this as a default setting.
For your current project right click the project in the Solution Explorer and select Properties.
In the left pane select Compile .
Set Option Strict to On.
From now on you have these settings for all files.
And in my personal opinion you should do the same for Option Explicit and Option Infer .
|
|
|
|
|
Thanks Jörgen
That was really helpful
|
|
|
|
|
|
I didn't pay enough attention to what you wrote in your original post: "infinite loop at the number of pages". What exactly do you mean by that?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I mean that when it counts the number of pages to print it doesn't stop counting
|
|
|
|
|
Dorsaf Ouersighni wrote: I really don't know why The WHY is what i'm looking for.
That's the entire point behind using the debugger. The debugger isn't there to tell you what's wrong with your code. It's there to tell you what's wrong with your understanding of it. Seriously, the debugger is there to debug YOU, not really the code. Using the debugger is the fastest way to learn about the code you've written and the conditions under which it runs.
|
|
|
|
|
|
Dim iRow As Double
While (iRow <= (DataGridView_impot.Rows.Count - 1))
Firstly you should not use a Double as a loop counter, always use integers. Secondly, you should initialise the variable to zero to begin the loop. Uninitialised variables generally contain garbage, and could quite conceivably contain some extremely large negative value.
|
|
|
|
|
Richard MacCutchan wrote: Uninitialised variables generally contain garbage, and could quite conceivably contain some extremely large negative value.
That's true in C/C++, but not in .NET code. The variable will always be initialized to its default value.
However, it's still a good idea to explicitly initialize it. In C#, you'd get a compiler error if you didn't.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
that's true. it isn't the same as C/C++
Thanks Richard
|
|
|
|
|
Thank you; I should know this, and I am sure it has been explained more than once before. But at my advanced age there is so much rubbish rattling around in my head ...
|
|
|
|
|
You're welcome
Never mind. Everybody will atteind the advanced age Mr Richard
|
|
|
|
|
thanks Richard,
even when i initialise iRow to zero and use it as Integer, nothing changes.
and when i use an Integer, it will be automatically initialised to zero
|
|
|
|
|
OK, so that is a starting point. Now you need to step through the code with your debugger to find out why the loop never terminates.
|
|
|
|
|
Quote: Sascha wrote :
If a loop gets executed indefinitely it's because its condition to keep running keeps evaluating to true. So, if it's the while-loop that executes indefinitely
While (iRow <= (DataGridView_impot.Rows.Count - 1))
then it has to be because iRow always has a value lower than the amount of rows. That's not intended of course - so you would have to find out (using the debugger) why this is so in order to fix it.
And that's true and i'm trying to fix it
Any suggestions ?!
modified 26-Jan-16 9:45am.
|
|
|
|