Solved

Set the number of elements in an array from input receivied via console.

Posted on 2006-07-20
5
179 Views
Last Modified: 2010-04-23
I need to Dimension an array of integers and set the number of elements in the array based on the response recieved from the console.  Can someone provide an example.  I have tried the example below, but Lenth is read only.

       Dim arValues() As Integer   ' Array to store values
       Dim intElements As Integer   ' The number elements or values to be entered  
       Console.Write("Number of elements in the array (less than 100) : ")
       intElements = Console.ReadLine()
        ' arValues.Length = Int32.Parse(intElements)

I am looking for some guidance or sample code that will help me complete this.  Any information will be greatly appreciated.  Thanks.  DC900

My Environment
    Visual Studio 2005 & VB.NET
0
Comment
Question by:dc900
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 150 total points
ID: 17147098
Possibly a ReDim?


Dim arValues() As Integer   ' Array to store values
Dim intElements As Integer   ' The number elements or values to be entered  
Console.Write("Number of elements in the array (less than 100) : ")
intElements = Console.ReadLine()
ReDim arValues(Int32.Parse(intElements))
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 150 total points
ID: 17147222
Just declare the array after you read the console input:

        Dim intElements As Integer = Integer.Parse(Console.ReadLine())
        Dim arValues(i) As String
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question