Class VB Example Problems

  • From: "Marvin Hunkin" <startrekcafe@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 20 Oct 2008 19:16:50 +1100

Hi.
can any one help?

got some errors, doing a chapter of a programming book called Programming in 
Visual Basic by Julia K and A Milspaw, Magraw Hill Press.
will post my code and the example code example in a word document.
if any one can help, would be appreciative.
now, tried looking on msdn, but found only really complex to do with 
classess.
can any one help or point me out to fix these problems.
cheers Marvin.
ps: using visual basic .dot net express 2008 on a windows Vista Machine, 
using jaws 10 Beta 3.
and changed the book sale variable, menus, were being a pain, so have got 
buttons, and will paste the error messages as well.

'Program: Chapter 12 BookSale Step-by-Step
'Programmer: Marvin Hunkin
'Date: Monday October 20 2008
'Description: Calculate sales price using the BookSale class.
' Instantiate aBookSale as a new object of the BookSale class.
'Folder: Ch12SBS


Public Class frmBookSale

' Declare the new object.

 Private BookSale As BookSale
















Private Sub btnCalculateButton_Click(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles btnCalculateButton.Click


' Calculate the extended price for the sale.
Try

' Instantiate the object and set the properties.


With Me

BookSale = New BookSale(tbTitleTextBox.Text)     _
Integer.Parse(tbQuantityTextBox.Text), Decimal.Parse(.tbPriceTextBox.Text))

' Calculate and format the result.


BookSale.tbExtendedPriceTextBox.Text.ToString("N")







End With


Catch ex As Exception


MessageBox.Show("Enter numeric data.", "R And n R Book Sales", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


End Try


End Sub

Private Sub btnClearButton_Click(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles btnClearButton.Click

' Clear the screen controls.

With Me
.tbQuantityTextBox.Clear()
.tbPriceTextBox.Clear()
.tbExtendedPriceTextBox.Clear()

With .tbTitleTextBox
.Clear()
.Focus()

End With


End With







End Sub

Private Sub btnExitButton_Click(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles btnExitButton.Click

' Exit the program.



Me.Close()

End Sub
End Class



STEP 1: Type the remarks at the top of the form's code.

'Program: Chapter 12 BookSale Step-by-Step
'Programmer: Your Name
'Date: Today's Date
'Description: Calculate sales price using the BookSale class.
' Instantiate aBookSale as a new object of the BookSale class.
'Folder: Ch12SBS


The user interface that uses the
new BookSale class; the
completed form for the step-by-
step exercise.





Declare the New Object
STEP 1: Declare the object variable in the Declarations section, right under
the Public Class salesForm statement.

' Declare the new object.
Private aBookSale As BookSale

Write the Code
STEP 1: In the CalculateSaleToolStripMenuItem event procedure, write the
code to instantiate the BookSale object, assign the values to the prop-
erties, calculate the extended price, and assign the result to extend-
edPriceTextBox. Notice that IntelliSense pops up with the properties
and method of your new BookSale class.

Private Sub CalculateSaleToolStripMenuItem_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles CalculateSaleToolStripMenuItem.Click
' Calculate the extended price for the sale.

Try
' Instantiate the object and set the properties.
With Me
aBookSale = New BookSale(.titleTextBox.Text, _
Integer.Parse(.quantityTextBox.Text), Decimal.Parse(.priceTextBox.Text))
' Calculate and format the result.
.extendedPriceTextBox.Text = aBookSale.ExtendedPrice.ToString("N")
End With
Catch ex As Exception
MessageBox.Show("Enter numeric data.", "R 'n R Book Sales", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub

STEP 2: Code the ClearToolStripMenuItem_Click procedure.

Private Sub ClearToolStripMenuItem_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
' Clear the screen controls.

With Me
.quantityTextBox.Clear()
.priceTextBox.Clear()
.extendedPriceTextBox.Clear()
With .titleTextBox
.Clear()
.Focus()
End With
End With
End Sub

STEP 3: Code the ExitToolStripMenuItem_Click procedure.

Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
' Exit the program.

Me.Close()
End Sub


Error 1 Type 'BookSale' is not defined. 
C:\DOCS\Tafe\CertificateFourProgramming\CertFour\Programming\VisualBasic\Book\VisualBasicProgramming\ChapterTwelve\Example\Ch12SBS\Ch12SBS\frmBookSale.vb
 
13 22 Ch12SBS
Error 2 Type 'BookSale' is not defined. 
C:\DOCS\Tafe\CertificateFourProgramming\CertFour\Programming\VisualBasic\Book\VisualBasicProgramming\ChapterTwelve\Example\Ch12SBS\Ch12SBS\frmBookSale.vb
 
41 16 Ch12SBS
Error 3 End of statement expected. 
C:\DOCS\Tafe\CertificateFourProgramming\CertFour\Programming\VisualBasic\Book\VisualBasicProgramming\ChapterTwelve\Example\Ch12SBS\Ch12SBS\frmBookSale.vb
 
42 1 Ch12SBS


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts:

  • » Class VB Example Problems