Visual Basic - Help displaying multiple items


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Visual Basic - Help displaying multiple items

  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Exclamation Visual Basic - Help displaying multiple items

    This is my Code, and i have been trying to make thebutton so that it will automatically show everything from Mercury venus and etc and i have make it so that it show Mercury - Pluto in seperate lines but than i am not able to make it to show the name instead it only show String[]Array in every line any ideas how to fix it so that instead of string[]Array it will show each name correctly. Below is the picture attached as an example of how thefinal result will look like
    Code:
    Public Class Form1
     
        Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
            'Number of planets before Pluto was "let go"
            Const intNUM_PLANETS As Integer = 9
            'Planet names
            Dim strArrayPlanetNames() As String =
            {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
            'diameter of each planet in miles
            Dim dblArrayPlanetSizes() As Double =
            {3031, 7521, 7926, 4223, 88846, 74898, 31763, 30800, 1430}
            strArrayPlanetNames = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
     
            For intX = 0 To intNUM_PLANETS - 1
                'output name and size 
                lstPlanets.Items.Add(strArrayPlanetNames)
                'output bar chart on next line
            Next
        End Sub
     
    End Class
    Screenshot after button clicked.png
    Last edited by Hack; 08-21-2013 at 08:29 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    As your question deals with VB.NET rather than VB Classic I have moved your thread to the .NET forum section.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Comments:
    Code:
            'Planet names
            Dim strArrayPlanetNames() As String =
            {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
    '
    'Don't need this-->        strArrayPlanetNames = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
    '      
            For intX = 0 To intNUM_PLANETS - 1
                'output name and size 
     ' -->    lstPlanets.Items.Add(strArrayPlanetNames)  '<--  here you were showing the entire array, 9 times
                lstPlanets.Items.Add(strArrayPlanetNames(intX))  '<-- just show each array element
                'output bar chart on next line
            Next

    Final Version:
    Code:
    Public Class Form1
     
        Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
            'Number of planets before Pluto was "let go"
            Const intNUM_PLANETS As Integer = 9
            'Planet names
            Dim strArrayPlanetNames() As String =
            {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
            'diameter of each planet in miles
            Dim dblArrayPlanetSizes() As Double =
            {3031, 7521, 7926, 4223, 88846, 74898, 31763, 30800, 1430}
     
            For intX = 0 To intNUM_PLANETS - 1
                'output name and size 
                lstPlanets.Items.Add(strArrayPlanetNames(intX))
                'output bar chart on next line
            Next
        End Sub
     
    End Class

Similar Threads

  1. Replies: 1
    Last Post: 09-18-2008, 07:34 AM
  2. Replies: 3
    Last Post: 11-09-2007, 06:32 AM
  3. Replies: 2
    Last Post: 12-11-2006, 10:56 AM
  4. Replies: 3
    Last Post: 03-02-2001, 03:06 AM
  5. Need help displaying few items at a time
    By computerdude7 in forum Web
    Replies: 1
    Last Post: 01-23-2001, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center