1

I am currently doing a project for my computing course, where I let the user enter workout names, for each workout they can give a number of exercises and for each exercise they can track either distance, time, weight, sets or reps.

    Public Class Form1
    Dim workoutValue(14) As String
    Dim exerciseValue(14, 9) As String
    Dim workoutCounter As Integer
    Dim exerciseCounter As Integer
    Dim progressValue(14, 9, 4) As String
    Dim reps, sets, weight, distance, time As Integer



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        For i = 1 To 15
            workoutValue(i - 1) = CStr(i)
            workoutcomboBox1.Items.Add(i)
            workoutcomboBox2.Items.Add((workoutValue(i - 1)))
            workoutcomboBox3.Items.Add((workoutValue(i - 1)))
        Next
        workoutcomboBox1.SelectedIndex = 0
        workoutcomboBox2.SelectedIndex = 0

        For i = 1 To 10
            For x = 0 To 14
                exerciseValue(x, i - 1) = CStr(i)
            Next
            exercisecombobox1.Items.Add(i)
            exercisecomboBox2.Items.Add(i)
        Next
        exercisecombobox1.SelectedIndex = 0
        workoutcomboBox3.SelectedIndex = 0
        reps = 0
        sets = 1
        weight = 2
        distance = 3
        time = 4

        For i = 0 To 14
            For x = 0 To 9
                For y = 0 To 4
                    progressValue(i, x, y) = ""
                Next
            Next
        Next
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles workoutdataButton.Click
        workoutCounter = workoutcomboBox1.SelectedIndex
        workoutValue(workoutCounter) = txtworkoutvalueInput.Text
        workoutcomboBox2.Items.RemoveAt(workoutCounter)
        workoutcomboBox2.Items.Insert(workoutCounter, workoutValue(workoutCounter))
        workoutcomboBox3.Items.RemoveAt(workoutCounter)
        workoutcomboBox3.Items.Insert(workoutCounter, workoutValue(workoutCounter))

    End Sub

    Private Sub exercisedataButton_Click(sender As Object, e As EventArgs) Handles exercisedataButton.Click
        exerciseCounter = exercisecombobox1.SelectedIndex
        workoutCounter = workoutcomboBox2.SelectedIndex
        exerciseValue(workoutCounter, exerciseCounter) = txtexercisevalueInput.Text

    End Sub


    Private Sub workoutcomboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles workoutcomboBox3.SelectedIndexChanged
        exercisecomboBox2.Items.Clear()
        For i = 0 To 9
            exercisecomboBox2.Items.Insert(i, exerciseValue(workoutcomboBox3.SelectedIndex, CStr(i)))
        Next
    End Sub
    Private Sub progressButton_Click(sender As Object, e As EventArgs) Handles progressButton.Click
        exerciseCounter = exercisecomboBox2.SelectedIndex
        workoutCounter = workoutcomboBox3.SelectedIndex
        If repscheckBox.Checked = True Then
            progressValue(workoutCounter, exerciseCounter, reps) = repstxtBox.Text
        End If
        If setscheckBox.Checked = True Then
            progressValue(workoutCounter, exerciseCounter, sets) = setstxtBox.Text
        End If
        If weightcheckBox.Checked = True Then
            progressValue(workoutCounter, exerciseCounter, weight) = weighttxtBox.Text
        End If
        If distancecheckBox.Checked = True Then
            progressValue(workoutCounter, exerciseCounter, distance) = distancetxtBox.Text
        End If
        If timecheckBox.Checked = True Then
            progressValue(workoutCounter, exerciseCounter, time) = timetxtBox.Text
End If
        Label1.Text = progressValue(1, 1, 0)
    End Sub
End Class

This is what I have made so far (excuse my awful use and understanding of the language). The program works but I want the data the user enters to persist when they close the program! I looked into using objects because you can save the data for objects into a serial file. But I can't find a way to use the objects in a similar way to my arrays. Any help or advice would be greatly appreciated!

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
DJHolmes97
  • 11
  • 1
  • vb6 or vb.net choose one. they aren't the same – Fᴀʀʜᴀɴ Aɴᴀᴍ Feb 04 '16 at 16:55
  • Fixed, sorry about that! – DJHolmes97 Feb 04 '16 at 16:58
  • It's not VB6 but looks VB.Net –  Feb 04 '16 at 17:22
  • It is .NET I changed the tag – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 17:23
  • I guess you are asking how to save the data. Write it down somewhere. Classes are ideal for keeping data about one thing together (vs broken up into different arrays). [This answer should help you](http://stackoverflow.com/a/34164458/1070452) get started with 21st century equivalents of arrays. – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 17:26
  • Wow I am clueless! Thanks for the help – DJHolmes97 Feb 04 '16 at 17:35
  • Extra question then, all these lists are great for making the equivalent to two dimensional arrays but what about a three dimensional array? – DJHolmes97 Feb 04 '16 at 17:47
  • If you want to attract the attention of someone when more than one person has commented you need to ping them using `@theirname` else you are yelling into the void. *you* get pinged for each comment because it is your post. I assume 14 means there are 15 exercises? what is the meaning of 9? – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 17:50
  • @Plutonix thanks for being patient, okay for there are 15 workouts that people can name. Then for each workout there are 10 exercises that people can also name. Then there are 5 different progression that you can track. reps, sets, weight, distance or time. These are also saved as strings just for ease. So I would have one list tracking the workout names, then 15 more lists to track the possible exercises and their progressions for each exercise? – DJHolmes97 Feb 04 '16 at 17:55
  • Ok, first 15 is an arbitrary limit *you* set so you know how big to make the array. Not needed. Same for 10 (I think). I'm not clear on workout vs exercise vs progressions. What is the difference between an Exercise and a Workout? – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 18:00
  • @Plutonix Well a workout is like leg day, the exercises are like squats or leg press, then the progressions are the reps, weight etc. I know I set the limits but it was so I could make a way of connecting the three. – DJHolmes97 Feb 04 '16 at 18:10
  • This is not quite right, but it might give you an idea: http://pastebin.com/eNYPLAaG once you have the structure, the workout history would just be a List(Of Workout) ie a collection class. Saving without a database would just require serializing (as little as 2 lines of code) "leg day" sounds like a schedule or a classification – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 18:18
  • ...lists can be used as the data source for controls. If the user defines 13 exercises they use/rotate, you can assign that list to a combobox – Ňɏssa Pøngjǣrdenlarp Feb 04 '16 at 18:23
  • @Plutonix thanks so much for your help! I guess the only thing for me to do now is to play around with lists and see what I can make! – DJHolmes97 Feb 04 '16 at 18:27

1 Answers1

0

You may want to use a for each loop and export each value of the array to a line in a text file...

Something like this:

Try

Using sw As StreamWriter = File.AppendText("C:\MyFile.txt")
For each value In myArray
sw.WriteLine(value.tostring)
Next
  Catch ex As Exception
MsgBox("Something went wrong:" & ex.tostring)
        End Try
Daniel Santos
  • 188
  • 2
  • 15
  • Though this is probably what I'm going to have to use, If I can work out has to use the lists for this same thing it would probably clean up my code quite a bit. – DJHolmes97 Feb 04 '16 at 18:11