1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB.Net - my array isn't storing the data

Discussion in 'Software Development' started by fish613, Jan 30, 2007.

Thread Status:
Not open for further replies.
  1. fish613

    fish613 Account Closed Thread Starter

    Jan 27, 2007
    I have a subroutine that is supposed to read data from some combo-boxes into a two-dimensional array. As far as I can tell, it isn't doing so properly, but I have no idea at all what is wrong with the code used. Can anyone help at all? Even if it's just to show me the error without a solution, I'll be very grateful.
    The relevant code is posted below. It is a program for recording votes in an election.
    Thanks in advance!

    The code is as follows:

    Private Sub btSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSubmit.Click

    'Read the votes into the two-dimensional array "votes()"

    'Counts the vote
    numvotes = numvotes + 1

    lbNumvotes.Text = "There have been " & numvotes & " votes recorded so far"

    'Displays the votes in a listbox
    Dim i As Integer
    For i = 0 To 5
    If (votes(numvotes, i)) <> -1 Then
    lbxVotes.Items.Add((votes(numvotes, i)) & vbNewLine)
    End If
    Next i
    End Sub

    Sub readvotes()
    'Reads the vote into the bi-dimensional "votes" array
    '"numvotes" gives how many votes have been cast
    votes(numvotes, 0) = cbxChoice1.SelectedIndex
    votes(numvotes, 1) = cbxChoice2.SelectedIndex
    votes(numvotes, 2) = cbxChoice3.SelectedIndex
    votes(numvotes, 3) = cbxChoice4.SelectedIndex
    votes(numvotes, 4) = cbxChoice5.SelectedIndex
    votes(numvotes, 5) = cbxChoice6.SelectedIndex
    End Sub
  2. OBP


    Mar 8, 2005
    I do not know VB.Net at all but I assume that it has a message box function?
    If so then I would place a message box after each of the lines in the sub Readvotes() to read the array and the selection .
    In VBA this would be
    votes(numvotes, 0) = cbxChoice1.SelectedIndex
    msgbox votes(numvotes, 0) & " - " " & cbxChoice1.SelectedIndex

    In that way you can establish if the choice is being picked up from the list and if it is being assigned to the array member.
  3. fish613

    fish613 Account Closed Thread Starter

    Jan 27, 2007
    OBP, thanks so much! I added a loop to do what you suggested, and the votes were being recorded fine, but not displayed in the listbox correctly. I can now continue with the program.
    Thank you again!
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/539670

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice