Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27220

Adding values in a textfile

$
0
0
I'm trying to multiple two values in a textfile together and then add all the totals together into one value.
This is my form:
Attachment 99285
When someone clicks the "Values" in the menu bar, a drop down menu pops up and shows 3 options: all, non fic, or fic.

This is my textfile:
Left Behind, Lahaye, F, 7, 11.25
A Tale of Two Cities, Dickens, F, 100, 8.24
Hang a Thousand Trees with Ribbons, Rinadi, F, 30, 16.79
Saffy's Angel, McKay, F, 20, 8.22
Each Little Bird that Sings, Wiles, F, 10, 7.70
Abiding in Christ, Murray, N, 3, 12.20
Bible Prophecy, Lahaye and Hindson, N, 5, 14.95
Captivating, Eldredge, N, 12, 16.00
Growing Deep in the Christian Life, Swindoll, N, 11, 19.95
Prayers that heal the Heart, Virkler, N, 4, 12.00
Grow in Grace, Ferguson, N, 3, 11.95
The Good and Beautiful God, Smith, N, 7, 11.75
Victory Over the Darkness, Anderson, N, 12, 16.00

Depending on which one the person clicks in the dropdown menu, the total value of either all the books, all the nonfic books, or all the fic books will be displayed. I'm trying the "If...Then" and at first all my values were displaying as 0, but now it wont't even finish debugging. Any ideas?

Code:
Private Sub menuValues_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuValues.Click
Dim inventory() As inspecs
Dim books() As String = File.ReadAllLines("Books.txt")
Array.Sort(books)
Dim n As Integer = books.Count - 1
ReDim inventory(n)
Dim line As String
Dim data() As String


For i As Integer = 0 To n
line = books(i)
data = line.Split(","c)
inventory(i).title = data(0)
inventory(i).author = data(1)
inventory(i).category = data(2)
inventory(i).stock = CDbl(data(3))
inventory(i).price = CInt(data(4))
Next
Dim nfv As Integer
menuValuesNonFic.Checked = True
menuValuesAll.Checked = False
menuValuesFic.Checked = False
If menuValuesNonFic.Checked = True Then
If data(2) = "N" Then
nfv = (data(3) * data(4))
End If
MessageBox.Show(FormatCurrency("Values: " & nfv))
End If
Dim ficv As Integer
If menuValuesNonFic.Checked = False Then
If menuValuesFic.Checked = True Then
If data(2) = "F" Then
ficv = (data(3) * data(4))
End If
MessageBox.Show(FormatCurrency("Values: " & ficv))
End If
End If
Dim allv As Integer
If menuValuesNonFic.Checked = False Then
If menuValuesAll.Checked = True Then
allv = (data(3) * data(4))
MessageBox.Show(FormatCurrency("Values: " & allv))
End If
End If
End Sub

I'm new to Visual basic so any help would be appreciated!
Attached Images
 

Viewing all articles
Browse latest Browse all 27220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>