Click here to Skip to main content
15,906,467 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: printing RTB contents Pin
Duncan Edwards Jones14-Oct-07 0:44
professionalDuncan Edwards Jones14-Oct-07 0:44 
QuestionEditing Text Files and Creating new one of them Pin
Kalpeshpatelbyk13-Oct-07 2:07
Kalpeshpatelbyk13-Oct-07 2:07 
AnswerRe: Editing Text Files and Creating new one of them Pin
pmarfleet13-Oct-07 4:40
pmarfleet13-Oct-07 4:40 
AnswerRe: Editing Text Files and Creating new one of them Pin
Christian Graus13-Oct-07 10:29
protectorChristian Graus13-Oct-07 10:29 
QuestionTargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 2:02
redjen13-Oct-07 2:02 
AnswerRe: TargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 2:03
redjen13-Oct-07 2:03 
GeneralRe: TargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 14:29
redjen13-Oct-07 14:29 
QuestionHow to assign case to the event handler ? Pin
liv2luv13-Oct-07 1:59
liv2luv13-Oct-07 1:59 
I have this question :

A gas pump calculates the cost of gas at a local gas station. The station charges 2.09 per gallon for regular grade gas, $2.16 per gallon for special grade gas and $2.26 per gallon for the super grade gas. The click event handler for each button calls a method to compute the total cost
from the number of gallons entered and the selected grade.

I have attempted this way :


Public Class FrmGasolineCalculator
Inherits System.Windows.Forms.Form

'Labels for the form are defined here
Friend WithEvents lblTitle As System.Windows.Forms.Label 'Title label
Friend WithEvents lblLabel1 As System.Windows.Forms.Label 'Label to prompt user input
Friend WithEvents lblLabel3 As System.Windows.Forms.Label 'Label to display the output

'Read one number from the user as an input
Friend WithEvents txtInput As System.Windows.Forms.TextBox
Friend WithEvents txtResult As System.Windows.Forms.Label 'Result will be displayed here

'Reads input and calculates result accordingly
Friend WithEvents btnRegular As System.Windows.Forms.Button
Friend WithEvents btnSpecial As System.Windows.Forms.Button
Friend WithEvents btnSuperplus As System.Windows.Forms.Button

Dim result As Decimal


Function Calculate(ByVal Total As Decimal) As Decimal

Dim Quantity As Integer = 0
txtInput.Text = Convert.ToInt32(Quantity)

Total = 0

Dim Cost As Decimal

Select Case Cost

Case 2.09
Total = Quantity * 2.09
Return Total

Case 2.16
Total = Quantity * 2.16
Return Total

Case 2.26
Total = Quantity * 2.26
Return Total

End Select

End Function


Private Sub Regular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Regular.Click
txtResult.Text = Convert.ToDecimal(result)
result = 0

If Not txtInput.Text = " " Then

result = Calculate(result)

End If


End Sub
End Class

I have not handled the other two buttons Special and Superplus because the programming will be the same.

Error is :

Object reference not set to an instance of an object. How to handle this ?

Thanks
AnswerRe: How to assign case to the event handler ? Pin
Luc Pattyn13-Oct-07 3:09
sitebuilderLuc Pattyn13-Oct-07 3:09 
QuestionFile splitting Logic Pin
DON34512-Oct-07 23:53
DON34512-Oct-07 23:53 
AnswerRe: File splitting Logic Pin
Guffa13-Oct-07 0:53
Guffa13-Oct-07 0:53 
AnswerRe: File splitting Logic Pin
Luc Pattyn13-Oct-07 3:11
sitebuilderLuc Pattyn13-Oct-07 3:11 
QuestionProblem in Running EXE on Network when using ODBCConnection Object Pin
kkb_200112-Oct-07 21:12
kkb_200112-Oct-07 21:12 
AnswerRe: Problem in Running EXE on Network when using ODBCConnection Object Pin
Dave Kreskowiak13-Oct-07 3:52
mveDave Kreskowiak13-Oct-07 3:52 
QuestionHelp needed to Manipulate CSV Cell data..... Pin
paulk1112-Oct-07 12:26
paulk1112-Oct-07 12:26 
AnswerRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 3:48
mveDave Kreskowiak13-Oct-07 3:48 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 4:39
paulk1113-Oct-07 4:39 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 5:00
mveDave Kreskowiak13-Oct-07 5:00 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 6:01
paulk1113-Oct-07 6:01 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 6:09
paulk1113-Oct-07 6:09 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 9:11
mveDave Kreskowiak13-Oct-07 9:11 
QuestionBindingSource Pin
sabr4912-Oct-07 9:04
sabr4912-Oct-07 9:04 
AnswerRe: BindingSource Pin
pmarfleet12-Oct-07 10:11
pmarfleet12-Oct-07 10:11 
GeneralRe: BindingSource Pin
sabr4912-Oct-07 10:40
sabr4912-Oct-07 10:40 
GeneralRe: BindingSource Pin
nlarson1112-Oct-07 10:58
nlarson1112-Oct-07 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.