Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   What is Wrong with this If Statement? Please Help. (http://www.programmingforums.org/showthread.php?t=14983)

kewlgeye Jan 19th, 2008 6:36 PM

What is Wrong with this If Statement? Please Help.
 
Hello,


You will notice that some of the code wrapped, so disregard this please.

When I run the program I have one message in a group box on a summary form and another message in a group box below that. When on the input page I input information for the second textbox and click the calculate button, it keeps showing me only the first 2 messages "the one above and below" however, when I click the button again, or close it refreshes the information with the other 2 messages properly.

I need this to display the messages I have below the first time I press the calculate button, and I can't figure out why, I think it must have something to do with my if statements, because the form displays correctly all the information, however, I have to click the calculate button twice, or select the close button.

What do you think?



Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Calculate the totals to see if staffing is needed in certain areas or not.

Dim messageString As String
Dim messageString2 As String
Dim messageString3 As String
Dim messageString4 As String
Dim messageString5 As String
Dim messageString6 As String
Dim messageString7 As String
Dim messageString8 As String
Dim countaDecimal As Decimal = 9 - cpaTextBox.Text
Dim cpaMaxDecimal As Decimal = cpaTextBox.Text - 9
Dim countbDecimal As Decimal = 13 - cpbTextBox.Text
Dim cpbMaxDecimal As Decimal = cpbTextBox.Text - 13



' Team A Calculations.
With Me

If cpaTextBox.Text < 9 Then
messageString = "Checkpoint A is understaffed by " & countaDecimal & " player(s)."
.cparesponse = messageString
messageString2 = "Send " & countaDecimal & " player(s) to CheckPoint A."
.cparecommendation = messageString2
summaryForm.ShowDialog()

If cpaTextBox.Text > 9 Then
messageString3 = ""
.cparesponse = messageString3
messageString4 = "You can send " & cpaMaxDecimal & " player(s) from Team A to other locations if needed."
.cparecommendation = messageString4
Else
End If

' Team B Calculations

If cpbTextBox.Text < 13 Then
messageString5 = "Team B is understaffed by " & countbDecimal & " player(s)."
.cpbresponse = messageString5
messageString6 = "Send " & countbDecimal & " player(s) to Team B."
.cpbrecommendation = messageString6
summaryForm.ShowDialog()


If cpbTextBox.Text > 13 Then
messageString7 = ""
.cpbresponse = messageString7
messageString8 = "You can send " & cpbMaxDecimal & " player(s) from Team B to other locations if needed."
.cpbrecommendation = messageString8
Else
End If
End If
End If
End With
End Sub

kewlgeye Jan 20th, 2008 12:47 PM

Re: What is Wrong with this If Statement? Please Help.
 
I figured it out. Thank you all who may have looked at this thread.

The solution was to place the summaryForm.ShowDialog at the bottom, or to the last 2 labels of the calculation.

I also needed to use ElseIf statements. And modify the code a bit so that it wouldn't produce any message if the exact number was entered.

Thanks again

Multumesc
Cpaciba
Gracias

PhilBon Jan 20th, 2008 6:25 PM

Re: What is Wrong with this If Statement? Please Help.
 
Next time use the code=vb tags like this:
:

  1. if (2=2) then
  2. messagebox("Same number")
  3. else
  4. messagebox("Not the same number")
  5. end if

it will look better

Ooble Jan 20th, 2008 11:14 PM

Re: What is Wrong with this If Statement? Please Help.
 
Just as a point of interest: part of the point of [code] tags is that they preserve indenting. If there's no indenting, please consider going back and putting some in - it makes the code a lot more readable.

Steel9561 Jul 21st, 2008 9:03 AM

Re: What is Wrong with this If Statement? Please Help.
 
If cpaTextBox.Text < 9 Then
messageString = "Checkpoint A is understaffed by " & countaDecimal & " player(s)."
.cparesponse = messageString
messageString2 = "Send " & countaDecimal & " player(s) to CheckPoint A."
.cparecommendation = messageString2
summaryForm.ShowDialog()

If cpaTextBox.Text > 9 Then
messageString3 = ""
.cparesponse = messageString3
messageString4 = "You can send " & cpaMaxDecimal & " player(s) from Team A to other locations if needed."
.cparecommendation = messageString4
Else
End If


-----------------------------------------------------------------------------------------------------

I can see here that you basically have to if comparisons without an if statement. See you have one "If" after another. This is not acceptable in VB6.

If cpaTextBox.Text > 9 Then

should bbe

elseIf cpaTextBox.Text > 9 Then


All times are GMT -5. The time now is 4:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC