Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can Step through but when run defines variable wrong

Hi, thanks for helping

When I step through the following code (lots of junk removed so it
should be easier to read) it works fine, however when I run it it works
fine until i = 527 then I get an error, and TimetoPM's value is wrong.
It comes out negative even when the formula makes it positive?

For i = 1 To LoopNumber Step 1
Ttotal = 0
Tevent = 0
WeightedAge = 0
y = 1
x = 0
Do
If WeightedAge = 0 Then
Tf = Alpha * ((WeightedAge / Alpha) ^ Beta - Log(1 - Rnd))
^ (1 / Beta) - WeightedAge
TimeToPM = (Period * y - Ttotal)
If Tf < TimeToPM Then 'If (Time to fail) < (Time of next
SM - Time of Last Event)
'stuff in here but no defining of TimetoPM
Else
'more stuff but TimetoPM is not changed
WeightedAge = WeightedAge + TimeToPM * (1 -
RestoreFactor)
End If
y = y + 1 'update SM multiple counter for System
Time option
End If
Ttotal = Tevent + Tm
Else
x = 1
End If
Loop While x = 0
Next

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Can Step through but when run defines variable wrong

It looks to me that if yoour Ttotal is greater than y or if RestoreFactor is
greater than 1 then TimetoPM will be negative. If that is the case, then you
can put an error handling "If ... then" in there to accomodate it or use "on
error next" to bypass it, depending on what you expect as a result.

"sportzrule" wrote:

Hi, thanks for helping

When I step through the following code (lots of junk removed so it
should be easier to read) it works fine, however when I run it it works
fine until i = 527 then I get an error, and TimetoPM's value is wrong.
It comes out negative even when the formula makes it positive?

For i = 1 To LoopNumber Step 1
Ttotal = 0
Tevent = 0
WeightedAge = 0
y = 1
x = 0
Do
If WeightedAge = 0 Then
Tf = Alpha * ((WeightedAge / Alpha) ^ Beta - Log(1 - Rnd))
^ (1 / Beta) - WeightedAge
TimeToPM = (Period * y - Ttotal)
If Tf < TimeToPM Then 'If (Time to fail) < (Time of next
SM - Time of Last Event)
'stuff in here but no defining of TimetoPM
Else
'more stuff but TimetoPM is not changed
WeightedAge = WeightedAge + TimeToPM * (1 -
RestoreFactor)
End If
y = y + 1 'update SM multiple counter for System
Time option
End If
Ttotal = Tevent + Tm
Else
x = 1
End If
Loop While x = 0
Next


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Drop Down List with Step by Step Instructions for 2007 remarkable Excel Worksheet Functions 2 March 22nd 09 04:36 AM
How show value of variable by mouse-over in debug single step mode Chet Shannon[_4_] Excel Programming 10 January 6th 06 03:31 PM
How show value of variable in single step debug mode? Chet Shannon[_4_] Excel Programming 2 November 28th 05 06:57 AM
What is the step-by-step procedure for making a data list? Bobgolfs56 Excel Discussion (Misc queries) 1 April 23rd 05 02:19 PM
I need step by step instructions to create a macro for 10 imbedde. diana Excel Worksheet Functions 3 January 31st 05 01:56 AM


All times are GMT +1. The time now is 06:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"