Small problem

Dhruva

Member
Joined
Sep 23, 2004
Messages
12
Programming Experience
Beginner
Hi, I was doing my exercise in VB.NET launguage. Have a problem in capturing the user response for a message dialog.

Following is the code:


If tradeInAllowanceValueDecimal = 0D Then

messageString = "Do you have any trading-in Allowance Value ?"

MessageBox.Show(messageString, "Trading-in allowance Amount: ", MessageBoxButtons.YesNo, _

MessageBoxIcon.Information)

EndIf



If whichButtonDialogResult = DialogResult.Yes Then

Call clearButton_Click(sender, e)

With tradeInallowanceTextBox

.SelectAll()

.Focus()

EndWith

EndIf

Also dimmed the variable whichButtonDialogResult as DialogResult Object.

Now the questions are
1) When the user is clicking yes when the message box appeared on the screen, the same is not getting transfered to DialogResult.yes.
Basically the 2nd If statement of checking the dialog result is never getting satisfying.

2) The above Big "IF" is inside the TRY CATCH block. If the user says "yes" I need to come out of this TRY CATCH block, rather just need to exit out of this event. what is the way for that.
I can't put another IF statement encircling the CATCH blocks, that is not getting accepted. I also can't put this dialog result before the TRY CATCH block, because this is not the first field on the screen, I can't check this first before checking the primary fields.

Could you please let me know the way for this.
 
VB.NET:
Dim dlgResult as DialogResult
[size=2][color=#0000ff]If[/color][/size][size=2] tradeInAllowanceValueDecimal = 0D [/size][size=2][color=#0000ff]Then
   [/color][/size][size=2]dlgResult = MessageBox.Show("[/size][size=2]Do you have any trading-in Allowance Value?[/size][size=2]", "Trad-in allowance", MessageBoxButtons.YesNo,  MessageBoxIcon.Information)
   [/size][size=2][color=#0000ff]If[/color][/size][size=2] dlgResult = DialogResult.Yes [/size][size=2][color=#0000ff]Then
    [/color][/size][size=2][color=#0000ff]Call[/color][/size][size=2] clearButton_Click(sender, e)
    [/size][size=2][color=#0000ff]With[/color][/size][size=2] tradeInallowanceTextBox
	  .SelectAll()
	  .Focus()
    [/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff] With
   [/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff] If
[/color]End If[/size]
 
Problem with DialogResult

Thanks JuggaloBrotha. You have solved half of my problem. I have liitle more left out here. Following is the Total Code:

VB.NET:
[size=2][color=#0000ff]If[/color][/size][size=2] carSalePriceTextBox.Text <> "" [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2][color=#0000ff]Try
 
[/color][/size][size=2]carSalePriceDecimal = [/size][size=2][color=#0000ff]Decimal[/color][/size][size=2].Parse(carSalePriceTextBox.Text)
 
[/size][size=2][color=#0000ff]Try
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] tradeInallowanceTextBox.Text = [/size][size=2][color=#0000ff]String[/color][/size][size=2].Empty [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]tradeInallowanceTextBox.Text = tradeInAllowanceValueDecimal.ToString
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2]tradeInAllowanceValueDecimal = [/size][size=2][color=#0000ff]Decimal[/color][/size][size=2].Parse(tradeInallowanceTextBox.Text)
 
[/size][size=2][color=#0000ff][CODE]
If tradeInAllowanceValueDecimal = 0D Then
messageString = "Do you have any trading-in Allowance Value ?"
 
whichButtonDialogResult = MessageBox.Show(messageString, "Trading-in allowance Amount: ", MessageBoxButtons.YesNo, _
 
MessageBoxIcon.Information)
 
End If
 
 
 
If whichButtonDialogResult = DialogResult.Yes Then
 
Call clearButton_Click(sender, e)
 
With tradeInallowanceTextBox
 
.SelectAll()
 
.Focus()
 
End With
 
End If

[/color][/size]If stereoSystemCheckBox.Checked = TrueThen

accessoriesFinishCostDecimal += STEREO_SYSTEM_PRICE_Decimal 'Adding to accessories total for stereo

EndIf

If stereoSystemCheckBox.Checked = TrueThen

accessoriesFinishCostDecimal += STEREO_SYSTEM_PRICE_Decimal 'Adding to accessories total for stereo

EndIf

If leatherInteriorCheckBox.Checked = TrueThen

accessoriesFinishCostDecimal += LEATHER_INTERIOR_PRICE_Decimal

EndIf'Adding to accessories total for leather

If ComputerNavigationCheckBox.Checked = TrueThen

accessoriesFinishCostDecimal += COMPUTER_NAVIGATION_PRICE_Decimal

EndIf'Adding to accessories total for Computer

If pearlizedRadioButton.Checked = TrueThen

accessoriesFinishCostDecimal += PEARLIZE_PRICE_Decimal 'Adding to accessories total for pearlized

ElseIf customizedDetailingRadioButton.Checked = TrueThen'Adding to accessories total for Customized

accessoriesFinishCostDecimal += CUSTOMIZED_DETAILING_PRICE_Decimal

EndIf

subTotalChargeDecimal = accessoriesFinishCostDecimal + carSalePriceDecimal

salesTaxChargeDecimal = subTotalChargeDecimal * TAX_RATE_Decimal

totalChargeDecimal = subTotalChargeDecimal + salesTaxChargeDecimal

amountDueToSellerDecimal = totalChargeDecimal - tradeInAllowanceValueDecimal

amountDueTextBox.Text = amountDueToSellerDecimal.ToString("C")

tradeInallowanceTextBox.Text = tradeInAllowanceValueDecimal.ToString("C")

totalLabel.Text = totalChargeDecimal.ToString("C")

salestaxLabel.Text = salesTaxChargeDecimal.ToString("C")

subTotalLabel.Text = subTotalChargeDecimal.ToString("C")

accessoriesFinishLabel.Text = accessoriesFinishCostDecimal.ToString("C")

carSalePriceTextBox.Text = carSalePriceDecimal.ToString("C")

calculateButton.Enabled =
False



messageString = "Total Amount Due :" _

& ControlChars.NewLine _

& ControlChars.NewLine _

& "Customer need to pay : " & amountDueToSellerDecimal.ToString("C")

MessageBox.Show(messageString, "Total Due Amount: ", MessageBoxButtons.OK, _

MessageBoxIcon.Information)

Catch ex As FormatException

messageString = "Please enter digits only for Trade allowance"

MessageBox.Show(messageString, "Invalid Entry for trade allowance", MessageBoxButtons.OK, _

MessageBoxIcon.Error)

With tradeInallowanceTextBox

.SelectAll()

.Focus()

EndWith

EndTry

Catch ex As FormatException

messageString = "Please enter the base price in digits only"

MessageBox.Show(messageString, "Invalid Entry", MessageBoxButtons.OK, _

MessageBoxIcon.Error)

With carSalePriceTextBox

.SelectAll()

.Focus()

EndWith

EndTry

Else

messageString = "Input is required for car base price"

MessageBox.Show(messageString, "No vaue is entered for car sale price", MessageBoxButtons.OK, _

MessageBoxIcon.Error)

With carSalePriceTextBox

.SelectAll()

.Focus()

EndWith

EndIf

If tradeInAllowanceValueDecimal > totalChargeDecimal Then

messageString = "Amount is due to customer since trade-in allowance is greater than the car total price" _

& ControlChars.NewLine _

& ControlChars.NewLine _

& "Customer gets back : " & amountDueToSellerDecimal.ToString("C")

MessageBox.Show(messageString, "Customer gets Money", MessageBoxButtons.OK, _

MessageBoxIcon.Information)

EndIf

EndSub


[/CODE]

Please notice that the Dialogresult is isnside a try and Catch block. Though I am calling the Clear Button procedure when the Dialogresult is yes, It goes and performs the clear procedure and then again going back and performing the calculations. I need to skip all these and just throw a screen to the user to reinput the values.


I tried to use the following IF statement just after the Calling clear procedure, but that is not getting accepted.

If whichButtonDialogResult = DialogResult.Yes Then

... Do all the calculations ( This has the Catch Statements here)

End-if

Could you please let me know how do I achieve this ?
 
VB.NET:
  If whichButtonDialogResult = DialogResult.Yes Then
	Try
	  'Call clear procedure
	Catch ex As Exception
	  'Error handler
	End Try
  Else 'meaning is was a result of no
	Try
	  'Do calculations
	Catch ex As Exception
	  'Error handler
	End Try
  End If
End Sub

is what you want, right? the code you posted (from what i can tell, sorry i didnt overly examin it) shows the calculation which looks fine to me..
 
Back
Top