Results 1 to 5 of 5

Thread: 2008 Array Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    2

    2008 Array Question

    Hello all, I am new to the forums and I have a question. I am new to VB and am working on a project that is taking information from a .dat file and placing it into an array. Now the .dat file looks kinda like so:

    100101011010010
    101010101010101someones name
    001110001110001someoneelses name
    etc..

    I am trying to take the first line, which is the key to a test and verify the results with following lines and the persons name. Then display how many they got correct and how many they got wrong with the persons name. So, my question is can I read the element of the array and only read the numbers and then print out the name some other time? Should I just fill the array with one character at time and go from there? Is there some trick to making this array or a command that I can utilize to make this easier than it seems?

    I appreciate the help, thanks all:

    -Logoman

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: 2008 Array Question

    you could use this:

    vb Code:
    1. Dim lines() As String = IO.File.ReadAllLines("yourfile.dat")
    2. Dim names(lines.GetUpperBound(0), 1) As String
    3. Dim answers As String = lines(0)
    4. For x As Integer = 1 To lines.GetUpperBound(0)
    5.       Dim correct As Integer = 0
    6.       names(x, 0) = lines(x).Substring(answers.Length)
    7.       For z As Integer = 0 To answers.Length - 1
    8.            If lines(x).Substring(z, 1) = answers.Substring(z, 1) Then
    9.               correct += 1
    10.            End If
    11.       Next
    12.       names(x, 1) = CStr(correct)
    13. Next

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Re: 2008 Array Question

    I am going to be using a streamreader to read the file in, are there any tricks to that?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: 2008 Array Question

    search the forum for streamreader

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: 2008 Array Question

    You could convert the key and answers to bitarray and XOR the key and each answer, ending up with incorrect responses.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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