I'm not a programmer but, taking my first VB 2008 course and one of the problems is asking me to write a variable code in a TextBox called TitleTextBox and in the box you should be able to write something and have it change.
The book is not very helpful and I could use some help.
Software/Hardware used:
Visual Basic 2008
ASKED:
November 27, 2009 1:42 AM
UPDATED:
August 2, 2011 2:32 PM
The question is not clear. Could you please be more specific, and tell us what exactly you need help with ?
Thanks,
Ok, can you post your code ?
So we can take a look and try to help.
‘Project: Chapter Example BookSales
‘Date: November 26, 2009
‘Programmer: Mary Erban Practice
‘Description: This project inputs sales information for books,It calculates the extened price and discount for a sale. Uses variables, constants, and calculations. Note that no erro trapping is included in this version of the program.
‘Folder: CH03BookSales
Public Class BookSalesForm
‘Declare the variables.
Dim QuantityInteger, NumberInteger As Integer
Dim PriceDecimal, ExtendedPriceDecimal, DiscountDecimal, DiscountedPriceDecimal As Decimal
‘Declare a string variable.
Dim NameString As String
‘Declare integer variables.
Dim CounterInteger As Integer
Dim MaxInteger As Integer = 100
‘Declare the constant.
Const DISCOUNT_RATE_Decimal As Decimal = 0.15
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
‘Print the form.
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
‘Calculate the price and discoutn.
Dim QuantityInteger As Integer
Dim PriceDecimal, ExtendedPriceDecimal, DiscountDecimal, _
DiscountedPriceDecimal As Decimal
Try
‘Convert quantity to numberica variables.
QuantityInteger = Integer.Parse(QuantityTextBox.Text)
Try
‘Convert price if quantity was successful.
PriceDecimal = Decimal.Parse(PriceTextBox.Text)
Catch ex As Exception
End Try
Catch ex As Exception
End Try
‘Convert input values to numberic variables.
QuantityInteger = Integer.Parse(QuantityTextBox.Text)
PriceDecimal = Decimal.Parse(PriceTextBox.Text)
‘Caluclate values.
ExtendedPriceDecimal = QuantityInteger * PriceDecimal
DiscountDecimal = Decimal.Round( _
(ExtendedPriceDecimal * DISCOUNT_RATE_Decimal), 2)
DiscountedPriceDecimal = ExtendedPriceDecimal – DiscountDecimal
‘Fomat and display answers.
ExtendedPriceTextBox.Text = ExtendedPriceDecimal.ToString(“C”)
DiscountTextBox.Text = DiscountDecimal.ToString(“N”)
DiscountedPriceTextBox.Text = DiscountedPriceDecimal.ToString(“C”)
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
‘Clear previous amounts from the form.
TitleTextBox.Clear()
PriceTextBox.Clear()
ExtendedPriceTextBox.Clear()
DiscountTextBox.Clear()
DiscountedPriceTextBox.Clear()
With QuantityTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
‘Exit the program.
Me.Close()
End Sub
Private Sub PriceTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PriceTextBox.TextChanged
‘Display the price per book.
PriceTextBox.Text = PriceDecimal.ToString(“C”)
End Sub
Private Sub BookSalesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub QuantityTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuantityTextBox.TextChanged
‘Display the number of books purchased numerically.
QuantityInteger = Integer.Parse(QuantityTextBox.Text)
End Sub
Private Sub TitleTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TitleTextBox.TextChanged
‘Display the title of the book.
TitleTextBox.Text = TitleTextBox.Text
End Sub
Private Sub ExtendedPriceTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExtendedPriceTextBox.TextChanged
‘Calculate the product.
ExtendedPriceTextBox.Text = (QuantityInteger * PriceDecimal).ToString(“C”)
End Sub
Private Sub DiscountTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiscountTextBox.TextChanged
‘Display the discount.
DiscountTextBox.Text = Decimal.Parse(DISCOUNT_RATE_Decimal * ExtendedPriceDecimal).ToString(“C”)
End Sub
Private Sub DiscountedPriceTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiscountedPriceTextBox.TextChanged
‘Display the discounted price of the purchase)
DiscountedPriceDecimal = (ExtendedPriceDecimal – DiscountDecimal).ToString(“C”)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
‘Displays title Book Sales.
End Sub
End Class
PROJECT: A company currently is having a sale with 15% discount . Need to be able to put the # of books, title of the book, price of the book. In another group calculate the extended price, calculate the 15% and have it display and then display the total cost of the book after the discount. Also to use try and catch blocks.
Check out this book except, Murach’s VB 2008. It has some good tips on Visual Basic 2008 and coding