Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 19th, 2008, 6:36 PM   #1
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 39
Rep Power: 0 kewlgeye is on a distinguished road
Question 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 is offline   Reply With Quote
Old Jan 20th, 2008, 12:47 PM   #2
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 39
Rep Power: 0 kewlgeye is on a distinguished road
Thumbs up 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
kewlgeye is offline   Reply With Quote
Old Jan 20th, 2008, 6:25 PM   #3
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 170
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
Re: What is Wrong with this If Statement? Please Help.

Next time use the code=vb tags like this:
vb Syntax (Toggle Plain Text)
  1. if (2=2) then
  2. messagebox("Same number")
  3. else
  4. messagebox("Not the same number")
  5. end if
it will look better
PhilBon is offline   Reply With Quote
Old Jan 20th, 2008, 11:14 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,435
Rep Power: 8 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch statement and strings gamerfelipe C 5 Apr 14th, 2007 11:20 AM
What's wrong with this code? titaniumdecoy Python 25 Jun 12th, 2006 12:46 PM
What is wrong with this code? c0ldshadow Visual Basic .NET 5 Dec 5th, 2005 5:37 PM
Trouble with a swith statement cjaime C 10 Nov 8th, 2005 11:09 AM
C++ vs. C# --- OOPS wrong thread sorry Stash Project Ideas 0 Jul 1st, 2005 11:28 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:38 AM.

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