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

VS 2013 Making statistics table, encountered a problem, please help me.

$
0
0
Hello guys,
first of all, happy holidays to all. :) I would need some assistance with my code. I've coded a program where you choose your favorite fruit and then the input is added to text file. When a button is pressed, values from text file(filename: persons.txt) is inserted into textbox and formatted to a table.



Fruit is chosen through ComboBox and items into combobox(fruits) are added from another text file(filename: fruits.txt). Content in fruits.txt is written like this:
Code:

"apple"
"pear"
"watermelon"
"banana"

Problem is when I try to make the statistics table in textbox. It works only on certain number of fruits but I want to make it like if I add more fruits into fruits.txt and user picks it up, it is included in statistics table.
Code:

Dim TabelaVsot(50) As Integer
        Dim TabelaBesedil() As String = File.ReadAllLines("fruits.txt", Encoding.UTF8)
        Dim VsotaSadij As Integer

        FileOpen(1, "persons.txt", OpenMode.Input)
        Do Until EOF(1)
            With Zapis
                Input(1, .Ime)
                Input(1, .Spol)
                Input(1, .NajljubseSadje)
                Input(1, .Placilo)
                Input(1, .DatumRojstva)

                VsotaSadij = TabelaVsot(0) + TabelaVsot(1) + TabelaVsot(2) + TabelaVsot(3) + TabelaVsot(4) + TabelaVsot(5)
                Select Case .NajljubseSadje
                    Case Is = 0
                        TabelaVsot(0) += 1
                    Case Is = 1
                        TabelaVsot(1) += 1
                    Case Is = 2
                        TabelaVsot(2) += 1
                    Case Is = 3
                        TabelaVsot(3) += 1
                    Case Is = 4
                        TabelaVsot(4) += 1
                    Case Is = 5
                        TabelaVsot(5) += 1
                    Case Is = 6
                        TabelaVsot(6) += 1
                    Case Is = 7
                        TabelaVsot(7) += 1
                End Select

            End With
            VsotaSadij += 1
        Loop
        FileClose(1)
        txtIzpis.Text &= vbNewLine & "Analiza sadja" & vbNewLine & vbNewLine & "Sadje" & vbTab & vbTab & "Število" & vbNewLine & StrDup(50, "-") & vbNewLine

        For Stevec = 0 To 7
            txtIzpis.Text &= TabelaBesedil(Stevec) & vbTab & vbTab & TabelaVsot(Stevec) & vbTab & vbNewLine
        Next
        txtIzpis.Text &= StrDup(50, "-") & vbNewLine & "Skupaj" & vbTab & vbTab & VsotaSadij & vbNewLine

As far as I understand vb.net, this will only work if fruits.txt contains 7 lines of different fruits. Could someone please help me so it will display statistics table with any number of fruits in that file? I've been searching on Google for almost whole day.
Thank you very much.

Viewing all articles
Browse latest Browse all 27348

Trending Articles



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