|
-
Jun 20th, 2015, 03:47 AM
#1
Thread Starter
Junior Member
[RESOLVED] Create new aray on button click
I'm developing a program that reads in the contents of all tab delimited value text files in an array, and then assigns the different values within the file into arrays. This means that for each file read in the program will have to create a new public array on a button click and automatically generate the array's name, however i have no idea how to do this.
I have no idea how to declare a public array
Here's an example of what i want to do in basic pseudocode. The steps i do not know how to perform are colour coded blue.
General Declarations
Arrayindex as integer
DirectoryIndex as Integer
Valueindex as integer
Filecontents As string
Filepath As String() 'Filepath is an array containing the file locations in a directory
On buttonclick event
For DirectoryIndex = 0 to UBound(Filepath) 'this loop reads in the contents of each index of DirectoryIndex
Create new Public Array of strings as "ValueArray" + ArrayIndex(5) this needs to create a new array capable of storing 6 different values, and shares the same index as the index of Filepath(), i.e. ValueArray1() contains the values given from the contents of Filepath(1)
Filecontents = Readin(Filepath) 'Filecontents is used as a temporary store for the contents of the text file
While Valueindex < 6 Read Filecontents into "ValueArray" + ArrayIndex(Valueindex) until instance of TAB encountered
On TAB encounter Valueindex = Valueindex + 1
This loop reads in the text foudn in the Filecontents varaible until it reaches an instance of the a gap where the tab button has been pressed (as the values in the file are separated using instances of tab gaps)
Endwhile
Next DirectoryIndex
Thanks
-
Jun 22nd, 2015, 11:09 AM
#2
Re: [RESOLVED] Create new aray on button click
You can create a List(Of T) where the T is a String array. Then in your button click you'd use IO.File.ReadAllText and Split by the Tab char. Here is an example using a Console Application:
Code:
Imports System
Imports System.Collections.Generic
Imports Microsoft.VisualBasic
Public Module Module1
Private files As List(Of String())
Public Sub Main()
files = New List(Of String())
Do
Console.Write("Path: ")
Dim path As String = Console.ReadLine()
If IO.File.Exists(path) Then
files.Add(IO.File.ReadAllText(path).Split(ControlChars.Tab))
End If
Loop
End Sub
End Module
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|