anault24
asked on
Visual Basic Sequential Access File- Displaying dollar sign with two decimal places
Who knows how to format the numbers entered into the txtGrossPay.txt to have a dollar sign ($) with two decimal places, that also displays in the list box?
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtGrossPay_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGrossPay.KeyPress
' allows the text box to accept only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
' saves a gross pay amount to a sequential access file
' declare a StreamWriter variable
Dim outfile As IO.StreamWriter
'open the file for append
outfile = IO.File.AppendText("gross.txt")
' write the name on a seperate line in the file
outfile.WriteLine(txtGrossPay.Text)
' close the file
outfile.Close()
' clear the list box, then set focus
lstContents.Items.Clear()
txtGrossPay.Focus()
End Sub
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' reads gross pay amount from a sequential access file
' and displays them in the list
' declare variables
Dim inFile As IO.StreamReader
Dim strGrossPay As String
'determine whether file exists
If IO.File.Exists("gross.txt") Then
' open file for input
inFile = IO.File.OpenText("gross.txt")
'process loop instructions until end of file
Do Until inFile.Peek = -1
strGrossPay = inFile.ReadLine
'add gross pay amount to list box
lstContents.Items.Add(strGrossPay)
Loop
'close the file
inFile.Close()
Else
MessageBox.Show("Can't seem to find her for you sir!")
End If
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.