5 Replies - 1584 Views - Last Post: 08 February 2008 - 08:30 PM Rate Topic: -----

#1 BrownSugar82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-February 08

If Then Else

Post icon  Posted 05 February 2008 - 04:58 PM

		Dim hours As Single
		Dim servicefees As Decimal
		Const PackageA As Single = 9.95
		Const PackageB As Single = 14.95
		Const PackageC As Single = 19.95
		hours = Val(txtHours.Text)

		If txtHours.Text.Trim.Length = 0 Then
			MessageBox.Show("Please enter number of hours used.", "ErrorMessage", MessageBoxButtons.OK, MessageBoxIcon.Error)
			txtHours.Focus()
		Else
			If IsNumeric(txtHours.Text) = False Then
				MessageBox.Show("Please enter numbers only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
				txtHours.Focus()
			Else
				If Val(txtHours.Text) <= 0 Then
					MessageBox.Show("Hours must be greater than 0.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
				Else
					If Val(txtHours.Text) >= 745 Then
						MessageBox.Show("Hours cannot be greater than 744.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
						txtHours.Focus()
					Else
						If radPackageA.Checked = True Then
							If Val(txtHours.Text) <= 10 Then
								lblServiceFees.Text = FormatCurrency(PackageA)
							Else
								If Val(txtHours.Text) >= 10 Then
									lblServiceFees.Text = FormatCurrency(PackageA + ((txtHours.Text - 10) * 2))

							   Else
							   If radPackageB.Checked = True Then
								If Val(txtHours.Text) <= 20 Then
									lblServiceFees.Text = FormatCurrency(PackageB)
								Else
									If Val(txtHours.Text) >= 20 Then
										lblServiceFees.Text = FormatCurrency(PackageB + ((txtHours.Text - 20) * 1))
									End If
								End If
							End If
						End If
						End If
					End If
				End If
			End If
		End If   



I can't get the Radio button with PackageB to work. PackageA and the calculations work. PLEASE HELP

Is This A Good Question/Topic? 0
  • +

Replies To: If Then Else

#2 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: If Then Else

Posted 05 February 2008 - 06:14 PM

Else
*If Val(txtHours.Text) >= 10 Then
lblServiceFees.Text = FormatCurrency(PackageA + ((txtHours.Text - 10) * 2))

Else
If radPackageB.Checked = True Then
If Val(txtHours.Text) <= 20 Then


the problem to me looks like it is when the system hits * then it says "ok this is what i need to do" and when thats done it jumps down to the end if.

Also, the check for radiobuttonB is inside of the IF statement for the radiobuttonA being checked.

	Dim hours As Single
		Dim servicefees As Decimal
		Const PackageA As Single = 9.95
		Const PackageB As Single = 14.95
		Const PackageC As Single = 19.95
		hours = Val(txtHours.Text)

		If txtHours.Text.Trim.Length = 0 Then
			MessageBox.Show("Please enter number of hours used.", "ErrorMessage", MessageBoxButtons.OK, MessageBoxIcon.Error)
			txtHours.Focus()
		Else
			If IsNumeric(txtHours.Text) = False Then
				MessageBox.Show("Please enter numbers only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
				txtHours.Focus()
			Else
				If Val(txtHours.Text) <= 0 Then
					MessageBox.Show("Hours must be greater than 0.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
				Else
					If Val(txtHours.Text) >= 745 Then
						MessageBox.Show("Hours cannot be greater than 744.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
						txtHours.Focus()
					Else
						If radPackageA.Checked = True Then
							If Val(txtHours.Text) <= 10 Then
								lblServiceFees.Text = FormatCurrency(PackageA)
							Else
								If Val(txtHours.Text) >= 10 Then
									lblServiceFees.Text = FormatCurrency(PackageA + ((txtHours.Text - 10) * 2))

								End If
								If radPackageB.Checked = True Then
									If Val(txtHours.Text) <= 20 Then
										lblServiceFees.Text = FormatCurrency(PackageB)
									Else
										If Val(txtHours.Text) >= 20 Then
											lblServiceFees.Text = FormatCurrency(PackageB + ((txtHours.Text - 20) * 1))
										End If
									End If
								End If
								End If
							End If
						End If
					End If
				End If
			End If
	End Sub



That might work, im not 100% positive, but you can always come back and post if there still is a problem. Hope it works :)

This post has been edited by ferrari12508: 05 February 2008 - 06:18 PM

Was This Post Helpful? 0
  • +
  • -

#3 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: If Then Else

Posted 07 February 2008 - 06:02 PM

EDIT: Just noticed that ferrari12508 already said this, but I'll leave up the code just in case.
Your problem lies in your If Then... Else logic. Essentially, your statement that checks to see if radPackageB is selected is nested within your statement testing if radPackageA is selected.

Here's a quick snippet that might help you (change from Else....If to ElseIf to improve readability, almost the same functionality).

Dim hours As Single
Dim servicefees As Decimal
Const PackageA As Single = 9.95
Const PackageB As Single = 14.95
Const PackageC As Single = 19.95
hours = Val(txtHours.Text)

If txtHours.Text.Trim.Length = 0 Then
			MessageBox.Show("Please enter number of hours used.", "ErrorMessage", MessageBoxButtons.OK, MessageBoxIcon.Error)
			txtHours.Focus()
ElseIf IsNumeric(txtHours.Text) = False Then
			MessageBox.Show("Please enter numbers only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
			txtHours.Focus()
ElseIf Val(txtHours.Text) <= 0 Then
			MessageBox.Show("Hours must be greater than 0.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf Val(txtHours.Text) >= 745 Then
			MessageBox.Show("Hours cannot be greater than 744.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
			txtHours.Focus()
ElseIf radPackageA.Checked = True Then
			If Val(txtHours.Text) <= 10 Then
				lblServiceFees.Text = FormatCurrency(PackageA)
			ElseIf Val(txtHours.Text) >= 10 Then
				lblServiceFees.Text = FormatCurrency(PackageA + ((txtHours.Text - 10) * 2))
			End If
ElseIf radPackageB.Checked = True Then
			If Val(txtHours.Text) <= 20 Then
				lblServiceFees.Text = FormatCurrency(PackageB)
			ElseIf Val(txtHours.Text) >= 20 Then
				lblServiceFees.Text = FormatCurrency(PackageB + ((txtHours.Text - 20) * 1))
			End If
End If


This post has been edited by aceofspades686: 07 February 2008 - 06:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: If Then Else

Posted 07 February 2008 - 06:52 PM

Since I believe they found your problem I do have a suggestion. You're using VB6 Libraries in VB.Net, at some point in time those will be versioned out, try sticking to the .Net Libraries in the future :)
Was This Post Helpful? 0
  • +
  • -

#5 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: If Then Else

Posted 08 February 2008 - 12:28 AM

View PostPsychoCoder, on 7 Feb, 2008 - 05:52 PM, said:

Since I believe they found your problem I do have a suggestion. You're using VB6 Libraries in VB.Net, at some point in time those will be versioned out, try sticking to the .Net Libraries in the future :)

I agree with you wholeheartedly. Never mix the old technologies with the new, unless there is no other option.
Was This Post Helpful? 0
  • +
  • -

#6 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: If Then Else

Posted 08 February 2008 - 08:30 PM

View Postjayman9, on 8 Feb, 2008 - 12:28 AM, said:

View PostPsychoCoder, on 7 Feb, 2008 - 05:52 PM, said:

Since I believe they found your problem I do have a suggestion. You're using VB6 Libraries in VB.Net, at some point in time those will be versioned out, try sticking to the .Net Libraries in the future :)

I agree with you wholeheartedly. Never mix the old technologies with the new, unless there is no other option.

Well this is what im being taught and i will still use it. ohh well, im taking java next year
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1