0

im making a program for school (in VB.NET) where i have a listview. When the user enters a customer name and presses "OK"it is outputted in the listview as a "o"

the code for the program is:

Public Class Form1
Dim w As IO.StreamWriter

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    lstOutput.Items.Clear()

End Sub


Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    End

End Sub

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
    Dim sfile As New SaveFileDialog
    With sfile
        .Title = "Choose your path to save the information"
        .InitialDirectory = "C:\"
        .Filter = ("ONLY Text Files (*.txt) | *.txt")
    End With

    If sfile.ShowDialog() = Windows.Forms.DialogResult.OK Then
        Dim Write As New IO.StreamWriter(sfile.FileName)
        Dim k As ListView.ColumnHeaderCollection = lstOutput.Columns
        For Each x As ListViewItem In lstOutput.Items
            Dim StrLn As String = ""
            For i = 0 To x.SubItems.Count - 1
                StrLn += k(i).Text + " :" + x.SubItems(i).Text + Space(3)
            Next
            Write.WriteLine(StrLn)
        Next
        Write.Close() 'Or  Write.Flush()
    End If
End Sub

Private Sub txtDiscPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub btnAdd_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim secondform As New Form2
    secondform.ShowDialog()

    Dim item As ListViewItem
    item = lstOutput.Items.Add(secondform.CustomerName)
    item.SubItems.Add(secondform.Item)
    item.SubItems.Add(secondform.ItemPrice)
    item.SubItems.Add(secondform.Quantity)
    item.SubItems.Add(secondform.TotalPrice)
    item.SubItems.Add(secondform.DiscPerc)
    item.SubItems.Add(secondform.DiscPrice)
    item.SubItems.Add(secondform.PaymentMethod)


End Sub
End Class

and for the second form, where the user enters the information the code is:

Public Class Form2
Public CustomerName As String
Public Item As String
Public ItemPrice As Double
Public Quantity As Integer
Public TotalPrice As Integer
Public DiscPerc As Double
Public DiscPrice As Double
Public PaymentMethod As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    CustomerName = Val(txtCustName.Text)
    Item = Val(txtItemName.Text)
    ItemPrice = Val(txtItemPrice.Text)
    Quantity = Val(txtQuantity.Text)
    TotalPrice = Val(txtTtlPrice.Text)
    DiscPerc = Val(txtDiscPerc.Text)
    DiscPrice = Val(txtDiscPrice.Text)
    PaymentMethod = Val(txtPaymentMethod.Text)
    Me.Close()
End Sub
End Class

I've been stuck on this for ages, any help is appreciated!

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
  • https://msdn.microsoft.com/en-us/library/k7beh1x9(v=vs.90).aspx – Sam Axe Apr 06 '15 at 08:23
  • additionally, [money values](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) should always be [`Decimal`](https://msdn.microsoft.com/en-us/library/364x0z75.aspx), not [`Double`](https://msdn.microsoft.com/en-us/library/678hzkk9.aspx). – Sam Axe Apr 06 '15 at 08:27
  • Also, in the future, only post the code that is directly relevant for the issue at hand. If you make us read a whole bunch of junk we tend to get cranky. – Sam Axe Apr 06 '15 at 08:30
  • 1
    Turning on [Option Strict](https://msdn.microsoft.com/en-us/library/zcd4xwzs%28v=vs.100%29.aspx) and not trying to concatenate strings with `+` would be a good start. – The Blue Dog Apr 06 '15 at 12:54
  • +1 for @TheBlueDog suggestion. Use `Option Strict` and you would have seen the source of your error. Since txtCustName.Text is already a string, there is no need to call `Val` on it, and in fact, it is `Val` which is returning your 0 result, since the textbox does not contain a numeric value. – Chris Dunaway Apr 06 '15 at 15:21

0 Answers0