[RESOLVED] printing values a tab delimited array-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] printing values a tab delimited array

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2014

    Resolved [RESOLVED] printing values a tab delimited array

    This program has been changed so that it uses a 2 dimensional array instead of a 1 demensional array, so now instead of the data being stored as: ValueArray(0) = test 1, it will be saved as ValueArray(0, 0) = test 1
    If you know how to write the contents of a text delimited file into a two dimensional array it would be appreciated

    I'm writing an algorithm that reads the values in a tab delimited array and stores each value in an array, before writing the contents of each array index into a rich text box.

    this is the file chr(9) is not written in the file but represents a tab spacing:
    test1 chr(9) test2 chr(9) test3 chr(9) test(4) chr(9)

    Dim Importedfile As IO.StreamReader
    Dim tempstring As String = My.Computer.FileSystem.ReadAllText(path + "Testfile.txt")
    Dim Valuesarray(3) As String

    Algorithm (on button click)
    tempstring = Importedfile.ReadLine()
    Valuesarray = tempstring.Split(New Char() {Chr(9)})
    RichTextBox1.Text = Valuesarray(0) + Valuesarray(1) + Valuesarray(2) + Valuesarray(3)

    Whenever i try to execute the code it says:
    "An unhandled exception of type 'System.NullReferenceException' occurred in Tab delimited files.exe

    Additional information: Object reference not set to an instance of an object."

    and the line tempstring = Importedfile.Readline() is highlighted

    thanks for helping
    Last edited by BumpaPumpa; Jun 21st, 2015 at 04:15 AM. Reason: changes in the way the program will work

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Central Europe

    Re: printing values a tab delimited array

    there are several things that i'd recommend you change. the error you get is because you declare Importedfile but you never instantiate it:
    Dim Importedfile As IO.StreamReader 'declaration
    Importedfile = new IO.StreamReader 'instantiation
    some things on your code:
    dont declare things like: "=My.Computer.FileSystem.ReadAllText(path + "Testfile.txt")" the readalltext call should not be part of the declaration but a call from a function (you seem to call them 'algorithms' )
    you Dim Valuesarray(3) As String but why do you know it will have 4 fields? you get the actual fields with the split so could also be 2 or 7 which is no problem but the "(3)" is just zero added value (instead it may confuse someone reading your code)
    why do you display your data in a richtextbox when it appears to be of tabular nature?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2014

    Re: printing values a tab delimited array

    yeah I'm kinda new to this

    this i just a module i'm using as a test run for a larger project, which is why i'm using the rich text box, to see if it works
    I declared the array to hold 4 values because in the main program each array was going to hold 4 values to be used and no more
    But I need to update this information because i've switched to using a 2 dimensional array instead of a single dimensional array, so i'll need to think of a different way of doing this.

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


Click Here to Expand Forum to Full Width

Survey posted by VBForums.