Infinity result

jgm

Member
Licensed User
Hi,

I'm doing some simple calculations and got unexpectedly an "infinity" result.

I've got some input fields and some output fields in a few forms.
The calculation that is not working is a simple division:
Scpi = Mcp / Ws

I have a button that I click in order to get calculations done.
When I press that button once, Scpi gets the correct result.
But if I press that button again, Scpi gets the value "infinity"; the variables Mcp and Ws have the same value (Mcp=20; Ws=0.05; I verified that by debugging).
I attached two pictures showing Scpi result after the first run and after the second run.
I've checked every line of the program and found no reason for getting the infinity result since Mcp and Ws are not changed.
Any idea of what could cause that strange behavior?

JGM
 

Attachments

  • 2.jpg
    2.jpg
    9.7 KB · Views: 180
  • 1.jpg
    1.jpg
    9.2 KB · Views: 177

jgm

Member
Licensed User
Wi = 0.05

At the end of the program I wrote two more lines:
- one to display in a new text box the operation (division)
- another to display in another textbox the variable to which the result was assigned

Tb01.Text = Format(Mcp/Wi, "N1")
Tb02.Text = Format(Scpi, "N1")

Tb01 displayed the correct result
Tb02 displayed "infinity"

Those odd things happen when running the program (by pressing F5 "RUN") while in the Visual Designer.

Then I compiled the program and run the compiled version.
Everything went OK. No problems with infinity in the compiled version.
What is going wrong?

jgm
 

jgm

Member
Licensed User
I'v attached the source code.
I'm writing in Portuguese; I believe that does not help much.

There are a few screens but only form01 and form02 are being used.
Division is done on line 83 and displayed on line 98.
Pressing the execute key "Xeq" on form 01, the program shows form 02 with the correct results.
Going back to form01 (pressing the "<" key) and pressing again "Xeq" form 02 is displayed with "infinity" in some textboxes.
That doesn't happen in the compiled version.

jgm
 

klaus

Expert
Licensed User
Longtime User
In lines 83 and 86 you should remove the + sign !

Replace:
B4X:
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]Scps = - Mcp / Ws[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]Scpi = + Mcp / Wi[/FONT][/SIZE]
 
[SIZE=2][FONT=Courier New]Ssbs = - Msb / Ws[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]Ssbi = + Msb / Wi[/FONT][/SIZE]
[/FONT][/SIZE]

by

B4X:
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]Scps = - Mcp / Ws[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]Scpi = Mcp / Wi[/FONT][/SIZE]
 
[SIZE=2][FONT=Courier New]Ssbs = - Msb / Ws[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]Ssbi = Msb / Wi[/FONT][/SIZE]
[/FONT][/SIZE]

Best regards.
 
Top