6 Replies - 641 Views - Last Post: 02 August 2012 - 11:16 AM Rate Topic: -----

#1 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

How to clear items from a listBox (trickier than usual)

Posted 20 June 2012 - 11:55 PM

Hello and thank you for looking at this :)

I enter a name into a text box as well as a score (from 0-100) into a separate text-box then i press 'Add to array'
and they go into the array BUT THE DON'T SHOW UP until i press "Show me the array.
Once i press "show me the array" i get my names and scores in 2 separate parallel arrays (which is what i want)
but now i need to assign a grade to each student (preferably next to each students score and name.
I have no idea how to do this, possibly use Case-where or a series of 'If' statements?

My Program Display: http://puu.sh/Cw1d
All of my code:
 

Public Class frmCreateArray
    Dim Names(21) As String
    Dim NamesCount, ListCount As Integer
    Dim Ages(21) As Double
    Dim AgesCount, ListCount2 As Integer
    Dim sum As Integer
    Dim NumberCount As Integer
    Dim Total As Double
    Dim Average As Double
    Dim Item As Double

    Private Property items As Object

    Private Sub cmdEnterThisName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnterThisName.Click
        NamesCount = NamesCount + 1
        Names(NamesCount) = txtNamesGoHere.Text
        AgesCount = AgesCount + 1
        Ages(AgesCount) = txtAgesGoHere.Text
        lblCounter.Text = Str(NamesCount) + " Students Entered"
        lblCounter.Text = Str(AgesCount) + " Students Entered"
        txtNamesGoHere.Text = "" : txtAgesGoHere.Text = ""
        txtNamesGoHere.Focus()
    End Sub
    Private Sub frmCreateArray_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NamesCount = 0
        AgesCount = 0
    End Sub

    Private Sub cmdShowListArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowListArray.Click
        For Me.ListCount = 1 To NamesCount
            lstListNames.Items.Add(Names(ListCount))
        Next
        For Me.ListCount2 = 1 To AgesCount
            lstListAges.Items.Add(Ages(ListCount2))
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click
        txtNamesGoHere.Text = ""
        txtAgesGoHere.Text = ""
        lblavg.Text = "..."
        lstListNames.Items.Clear()
        lstListAges.Items.Clear()
        lblCounter.Text = " Number of names entered"
        txtNamesGoHere.Focus()
    End Sub

    Private Sub btnAvg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAvg.Click
        For Each Me.Item In lstListAges.Items
            Total = 0
            For Me.AgesCount = 0 To AgesCount
                Total = Total + Ages(AgesCount)
            Next
            lblavg.Text = Total / NamesCount
        Next
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtNamesGoHere.Text = ""
        txtAgesGoHere.Text = ""
    End Sub
End Class



:) Thanks for your help :-) :batman:

WRONG NAME! :0 SORRY! :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: How to clear items from a listBox (trickier than usual)

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,935
  • Joined: 19-May 09

Re: How to clear items from a listBox (trickier than usual)

Posted 21 June 2012 - 03:52 PM

Well, if you keep doing things the way you are doing them, you'll need another array for grades. However, I would use a multidimensional array if I were going to use arrays in the first place. On the other hand, I really wouldn't use arrays at all!

The way to go here is to create a List of Structures. Here's an example. Create a structure called, say, Student, with three elements: Name, Age, Grade. Then create a List(Of Student). Each time you add, just create a Student variable. Maybe Dim cStudent as Student. Then set cStudent.Name, cStudent.Age, and cStudent.Grade. Then call your List's Add method. You can then run through the list when you're done, and populate your listboxes.

Much easier to keep track of everything this way. Lets the computer organize your data more.
Was This Post Helpful? 0
  • +
  • -

#3 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: How to clear items from a listBox (trickier than usual)

Posted 21 June 2012 - 09:42 PM

I will look up some tutorials on Multidimensional arrays. The user will enter different names and scores but the grades will be distributed based on the mark entered. e.g.
| James | 60 | Grade: Credit |
| Bob | 70 | Grade: Credit |
| Albert | 94 | Grade: High Distinction |
| Tony | 25 | Grade: Participation |

Above: Names array | Mark array | Grades
Each category has its own array.
I need to use ListBox's for the Names and Marks data. But could the last grades data be set in labels? or another list box?


Ps. Thank you so much for helping me :)
Was This Post Helpful? 0
  • +
  • -

#4 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: How to clear items from a listBox (trickier than usual)

Posted 21 June 2012 - 10:05 PM

How about something like this:

IF Ages(1) Or lstListAges(1) = <50 Then
   lbl1.text = "Grade: Participation"



Argh this is driving me crazy :stupid:
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,935
  • Joined: 19-May 09

Re: How to clear items from a listBox (trickier than usual)

Posted 26 June 2012 - 09:02 AM

Looks like your attention span is down to about two sentences, because that's all you appear to have read of my post. That's pretty typical of someone who is driving himself crazy, and you have my sympathy.

So here, let me help.

The way to go here is to create a list of structures. :hammer:
The way to go here is to create a list of structures. :hammer:
The way to go here is to create a list of structures. :hammer:

Are you paying attention yet? I could repeat it again if you need me to. :lol:

This post has been edited by BobRodes: 26 June 2012 - 09:04 AM

Was This Post Helpful? 0
  • +
  • -

#6 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: How to clear items from a listBox (trickier than usual)

Posted 26 June 2012 - 10:57 PM

I made a Select Case statement, its okay. Thanks for your help anyway <3
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,935
  • Joined: 19-May 09

Re: How to clear items from a listBox (trickier than usual)

Posted 02 August 2012 - 11:16 AM

Suit yourself. But the way to go here is to create a list of structures. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1