Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21842

Simple Subtraction Code Misbehaves!

$
0
0
My apologies for using large font. At 73 years, I need to look at big fonts. That said, I am now posting full code. This code works only for MOON-STRN. All other combinations, i.e MOON-MERC, MOON-VENS, MOON-SUNN, MOON-MARS and MOON-JUPT do not subtract correctly.

Opening form.

Private Sub cmdnext_Click()
If txtascndt.Text = "MOON" Or txtascndt.Text = "MERC" Then
Form1.Visible = True
Form1.lblrotascldplt.Caption = txtascndt.Text
Form1.lblcuconplt.Caption = txtcucon.Text
Form1.txtsu.Text = txtsu.Text
Form1.txtmo.Text = txtmo.Text
Form1.txtma.Text = txtma.Text
Form1.txtme.Text = txtme.Text
Form1.txtju.Text = txtju.Text
Form1.txtve.Text = txtve.Text
Form1.txtst.Text = txtst.Text

ElseIf txtascndt.Text = "VENS" Or txtascndt.Text = "SUNN" Then
Form2.Visible = True
Form2.lblrotascldplt.Caption = txtascndt.Text
Form2.lblcuconplt.Caption = txtcucon.Text
Form2.txtsu.Text = txtsu.Text
Form2.txtmo.Text = txtmo.Text
Form2.txtma.Text = txtma.Text
Form2.txtme.Text = txtme.Text
Form2.txtju.Text = txtju.Text
Form2.txtve.Text = txtve.Text
Form2.txtst.Text = txtst.Text

ElseIf txtascndt.Text = "MARS" Or txtascndt.Text = "JUPT" Or txtascndt.Text = "STRN" Then
Form3.Visible = True
Form3.lblrotascldplt.Caption = txtascndt.Text
Form3.lblcuconplt.Caption = txtcucon.Text
Form3.txtsu.Text = txtsu.Text
Form3.txtmo.Text = txtmo.Text
Form3.txtma.Text = txtma.Text
Form3.txtme.Text = txtme.Text
Form3.txtju.Text = txtju.Text
Form3.txtve.Text = txtve.Text
Form3.txtst.Text = txtst.Text
End If
End Sub

The following code operates when txtascndt.Text = "MOON" and txtcucon accepts one of the other five names i.e MERC, VENS, SUNN, MARS, JUPT and STRN. on the opening page. Data in these two text boxes is entered by user.

Code on the second form

1.MOON_STRN COMBINATION

Private Sub cmdmost_Click() ' WORKS FINE..MOON Ascndt and STRN cucon begins

Dim FullName, First As String
Dim ve, mo, mer, su, ma, ju, st, diff As Single


If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "STRN" Then st = txtst.Text
diff = st - mo
txtdif.Text = diff

If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > -6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

End If

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If
End Sub

2. MOON_JUPT COMBINATION

Private Sub cmdmoju_Click() 'MOON Ascndt and JUPT cucon begins
Dim FullName, First As String
Dim ve, mo, mer, su, ma, ju, st, diff As Single

If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "JUPT" Then ju = txtju.Text
diff = ju - mo
txtdif.Text = diff

If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > -6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If

End Sub

3. MOON_MARS COMBINATION

Dim mo, mer, ve, su, ma, ju, st, diff, Text As Single 'MOON Ascndt and MARS cucon begins
Dim FullName, First As String

If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "MARS" Then ma = txtma.Text
diff = ma - mo
txtdif.Text = diff

If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > - 6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If

End Sub


4. MOON_SUNN COMBINATION 'MOON Ascndt and SUNN cucon begins

Private Sub cmdmosu_Click()
Dim mo, mer, ve, su, ma, ju, st, diff, Text As Single
Dim FullName, First As String

If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "SUNN" Then su = txtsu.Text
diff = su - mo
txtdif.Text = diff


If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > -6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If

End Sub

5. MOON_VENS COMBINATION

Private Sub cmdmove_Click() 'MOON ascndt and VENS cucon begins

Dim mo, mer, ve, su, ma, ju, st, diff, Text As Single
Dim FullName, First As String

If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "VENS" Then ve = txtve.Text
diff = ve - mo
txtdif.Text = diff

If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > -6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If

End Sub



6. MOON_MERC COMBINATION

Private Sub cmdmome_Click() ' MOON Ascndt and MERC cucon begins

Dim mo, mer, ve, su, ma, ju, st, diff, Text As Single
Dim FullName, First As String

If lblrotascldplt.Caption = "MOON" Then mo = txtmo.Text
If lblcuconplt.Caption = "MERC" Then mer = txtme.Text
diff = mer - mo
txtdif.Text = diff

If txtdif.Text > -1 And txtdif.Text < 1 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION"

ElseIf txtdif.Text > -6 And txtdif.Text < 6 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION"

ElseIf txtdif.Text < 24 And txtdif.Text > 6 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 36 And txtdif.Text >= 24 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 39 And txtdif.Text > 36 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 51 And txtdif.Text >= 39 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 54 And txtdif.Text > 51 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 66 And txtdif.Text > 54 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 84 And txtdif.Text > 66 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 96 And txtdif.Text >= 84 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text < 114 And txtdif.Text > 96 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 126 And txtdif.Text >= 114 Then
txtreply1.Text = "FAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 174 And txtdif.Text > 126 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

ElseIf txtdif.Text <= 186 And txtdif.Text > 174 Then
txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

Else: txtreply1.Text = "UNFAVOURABLE CONFIGURATION."

FullName = txtreply1.Text
First = Left(FullName, 2)
If First = "UN" Then
txtreply1.BackColor = vbRed
txtreply1.ForeColor = &H80000008
ElseIf First = "FA" Then
txtreply1.BackColor = vbGreen
txtreply1.ForeColor = &H80000008
End If

End Sub

Data that goes in text boxes txtmo, txtme, txtve, txtsu, txtma, txtju and txtst could vary from -360 to 360, upto three places of decimal. I hope this should be adequate to identify the cause of error in subtraction. Thanks for your time and help.

Viewing all articles
Browse latest Browse all 21842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>