Skip to main content
1-Visitor
May 6, 2020
Solved

Problem with a while loop

  • May 6, 2020
  • 3 replies
  • 8710 views

Hi everyone,

 

I´m programming a plate heat exchanger, the flow begin in single-phase and when certain conditions are met, it change to twin-phase.

 

I write a while loop, it works and everything is correct.

 

The first problem comes when I try to introduce some more line and assign a new variable name to it, it fails, I have to reuse a variable name already used inside the loop, it is not solved by declaring the variable outside the program, neither in the program but outside the loop or inside the loop. The failure it gives is the following "" Ldtoken, Ldftn and Ldvirtftn OpCodes cannot have DynamicMethod as their destination ".

 

The second problem appears in the result array, certain variables fail when appearing together in the result array, only if there are two or more of them, one at a time they do not fail. I have observed that the variables that fail are those found from line 17 in the loop, the previous ones do not fail, and it does not matter if I previously declared them outside the program, inside the program but outside the loop or inside the loop. The only solution is to put just one of those variables.

 

I use MC14

 

It's weird, right?

 

Thanks for your help.

 

Greetings, Jesús

Best answer by jesusmor

Hi everybody,

 

One guy give me a operative 15th version, I have installed and both sheets run whitout problem.

 

Which is the reason? Who knows, MC mania.

 

Thanks a lot for your time, I´m glad to meet you and it won´t be the last time I´ll come here.

 

Kind regards!!

 

jesusmor_0-1588958389108.png

 

3 replies

23-Emerald IV
May 6, 2020

Please attach your worksheet.

Without it, there's little we can do.

 

Success!
Luc

jesusmor1-VisitorAuthor
1-Visitor
May 6, 2020

You´re reason, sorry!!

 

I send the attachment

23-Emerald IV
May 6, 2020

Your sheet contains a couple of programming constructs at the bottom, and to the far right. It is very hard to see what works, and what doesn't. As far as I can see the one to the left, called prog() is red, so I guess it doesn't work.

Could you just put two complete programs, one that works, the other with one extra line (as you say) that doesn't.

 

Success!
Luc

25-Diamond I
May 8, 2020

I, too, can confirm that both sheets run without any errors.
Mathcad 15, M050

Can you post a pic with the error message you get in the "fail" sheet and where the error traces back to (right click on the error and chose trace)

jesusmor1-VisitorAuthor
1-Visitor
May 8, 2020

Thanks everybody!!

 

You guys found the trouble, good job!!.


But, the next question is: Why does MC14 fail?, doesn't it has solution?, should I change for the MC15?.

 

I don´t know if this change is possible, it is a work for an university.

 

Let´s going!!

25-Diamond I
May 8, 2020

@jesusmor wrote:

Thanks everybody!!

 

You guys found the trouble, good job!!.


No, obviousy we didn't as we don't experience any error using the versions of MC we use

 



But, the next question is: Why does MC14 fail?, doesn't it has solution?, should I change for the MC15?.

If your university can provide you a license for the current version of Mathcad for free it sure would be a good idea to upgrade to MC15. But if you have a personal license for MC14 and would have to pay to get MC15, I would rather stay with MC14 and wouldn't throw money at PTC.

@VladimirN  has posted here in the past ever so often the release notes for various Mathcad versions. These notes contain a list of bugs which were fixed in the new releases and which new feature were implemented. Maybe you are able to find these threads and can spot something there which may relate to the error message you experience.

 

Again: Can you post a screenshot showing the error message you experience in the "fail" sheet and can you try to trace back the error by right-clicking the red error, choosing "Trace Error" and then clicking on "First". Where does this procedure sends you to?

 

Its hard to say without seeing the error ourselves what the cause for MC14 failing may be.
It sure is bad programming to use a variable in the condition of the while-loop which is not defined when entering the loop the first time (as Luc had pointed out). But I can't say if thats the cause for your trouble as you had done this in the sheet which does not fail for you, too.