Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:23:11+00:00 2026-06-13T06:23:11+00:00

I need a little help. My code is work 99% correctly except for one

  • 0

I need a little help. My code is work 99% correctly except for one little thing.

I’m making what’s called “Cafeteria Survey” which tallies responses from a ComboBox, which the user inputs them self.

The issue here is that it tallies (places a *) the number 1 less than the number I chose in the ComboBox.

If I add + 1 on the end of SelectedIndex it places the * with the correct number, but it doesn’t do it for #10
responses(ratingComboBox.SelectedIndex) += 1

Any help would be fantastic. Thanks in advance.

Here’s my code:

Public Class CafeteriaSurveyForm

Dim choices As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim responses(0 To 11) As Integer
Dim responseCounter As Integer = 0

' displays histogram
Sub DisplayHistogram()

    outputTextBox.Text = ("Rating" & vbTab & "Frequency")

    For i As Integer = 0 To choices.GetUpperBound(0)
        For ii As Integer = 1 To responses(i)
            outputTextBox.Text &= ("*")
        Next
        outputTextBox.Text &= (vbNewLine & choices(i) & vbTab)
    Next


End Sub ' DisplayHistogram

Private Sub CafeteriaSurveyForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ratingComboBox.DataSource = choices
End Sub

Private Sub submitButton_Click(sender As System.Object, e As System.EventArgs) Handles submitButton.Click
    responseCounter += 1

    responses(ratingComboBox.SelectedIndex) += 1

    DisplayHistogram()

End Sub

End Class ' CafeteriaSurveyForm
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:23:12+00:00Added an answer on June 13, 2026 at 6:23 am

    Your display function is a little backward. Here is what you have now:

    For i As Integer = 0 To choices.GetUpperBound(0)
        For ii As Integer = 1 To responses(i)
            outputTextBox.Text &= ("*")
        Next
        outputTextBox.Text &= (vbNewLine & choices(i) & vbTab)
    Next
    

    For every loop it is writing the asterisks to the previous line (because the new line is done after). If you increase the selected index it wrote them in the correct location but never got to write the asterisks for #10 because it exited the for loop before it got a chance.

    This is what it should be:

    For i As Integer = 0 To choices.GetUpperBound(0)
        outputTextBox.Text &= (vbNewLine & choices(i) & vbTab)
        For ii As Integer = 1 To responses(i)
            outputTextBox.Text &= ("*")
        Next
    Next
    

    Or even

    For i As Integer = 0 To choices.GetUpperBound(0)
        outputTextBox.Text &= vbNewLine & choices(i) & vbTab & New String("*", responses(i))
    
    Next
    

    Now the choices and responses arrays are synced using the same indexes and are accessed during the same loop iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little help with my code here. So far, when I go
I work on a code base which is mostly C with a little C++,
I am designing my database using code first and I need a little help
Need a little help from you guy's. I am making a check where element
I need little help for url rewriting in wordpress. basically what i need: mydomain.com/mysomewordpresspost
I would need little help here. I'm trying to get the git respository from
Need a little help with a SQL / ActiveRecord query. Let's say I have
Need a little help with my jquery here I want all my button with
I need a little help with an if statement in php. I'm trying to
I need a little help setting up a HTTP Post in C#. I appreciate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.