Hi, I'm a student who's taking a computer programming class that uses VB 2010. I have no earlier experience with VB so I'm still a beginner even though I've been in the class for about 2 months now. We have to write program code that will save an output file under a specified name (whatever the user types into the file name txt box). But before this is done, the program must calculate a unit cost and list price based on the information the user enters and display these values in labels. My program is doing that correctly (this routine occurs after the user selects a department from the drop down combo box). However, the user is then supposed to click the "enter" button, which will write all of the information to an output file.
I'm having a few problems: 1. In my line of code converting the input in the Cost txt box from string to double (VB is showing an error that the number must be less than infinity)
Also, 2. The program obviously isn't writing to an output file right now beacuse of that error, but the file is showing up in the designated path (C:/temp:/...etc) How do i make the file show up under the specified name the user types into the file name txt box?
Thanks!
I'm having a few problems: 1. In my line of code converting the input in the Cost txt box from string to double (VB is showing an error that the number must be less than infinity)
Also, 2. The program obviously isn't writing to an output file right now beacuse of that error, but the file is showing up in the designated path (C:/temp:/...etc) How do i make the file show up under the specified name the user types into the file name txt box?
Thanks!
Code:
Imports System.IO
Public Class Form1
Dim fvOutput As StreamWriter
Private Sub btnCreate_Click(sender As System.Object, e As System.EventArgs) Handles btnCreate.Click
fvOutput = File.CreateText("C:/temp/(txtFileName.Text).txt")
txtFileName.Focus()
End Sub
Private Sub btnAppend_Click(sender As System.Object, e As System.EventArgs) Handles btnAppend.Click
fvOutput = File.AppendText("C:/temp/txtFileName.Text.txt")
txtFileName.Focus()
End Sub
Private Sub cboDepartment_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboDepartment.SelectedIndexChanged
Dim dblUnitCost As Double
Dim dblListPrice As Double
Dim dblCost As Decimal
Dim intQuantity As Integer
dblCost = CStr(txtCost.Text)
intQuantity = CStr(txtQuantity.Text)
If cboDepartment.Text = "Clothing" Then
dblListPrice = dblUnitCost + (dblUnitCost * 0.4)
ElseIf cboDepartment.Text = "Hardware" Then
dblListPrice = dblUnitCost + (dblUnitCost * 0.35)
Else
dblListPrice = dblUnitCost + (dblUnitCost * 0.3)
End If
lblDisplayUnitCost.Text = dblUnitCost.ToString("c")
lblDisplayListPrice.Text = dblListPrice.ToString("c")
End Sub
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
Dim strStockNumber, strItemName As String
Dim dblCost, dblUnitCost, dblListPrice As Double
Dim intQuantity As Integer
strStockNumber = txtStockNumber.Text
strItemName = txtItemName.Text
dblCost = CStr(txtCost.Text)
txtCost.Text = dblCost.ToString("c")
intQuantity = CStr(txtQuantity.Text)
lblDisplayUnitCost.Text = dblUnitCost
lblDisplayListPrice.Text = dblListPrice
fvOutput.WriteLine("Stock" & vbTab & "Item" & vbTab & "Cost" & vbTab & "Quantity" & vbTab & "Dept." & vbTab & "Unit Cost" & vbTab & "List Price")
fvOutput.WriteLine(strStockNumber & vbTab & strItemName & vbTab & dblCost & vbTab & intQuantity & vbTab & cboDepartment.SelectedIndex & vbTab & lblDisplayUnitCost.Text & vbTab & lblDisplayListPrice.Text)
txtFileName.Clear()
txtStockNumber.Clear()
txtItemName.Clear()
txtCost.Clear()
txtQuantity.Clear()
cboDepartment.SelectedIndex = -1
lblDisplayUnitCost.Text = ""
lblDisplayListPrice.Text = ""
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
fvOutput.Close()
Me.Close()
End Sub
End Class