Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:50:10+00:00 2026-06-13T22:50:10+00:00

If I place a breakpoint at the line currentrow = MyParser.ReadFields() , currentrow still

  • 0

If I place a breakpoint at the line currentrow = MyParser.ReadFields()
, currentrow still contains the values of the previous line parsed from the file. After currentrow = MyParser.ReadFields()
executes, the current file line values are stored.

Since currentrow is declared inside the While loop, shouldn’t the previous currentrow value be out of scope when re-entering the While loop? Why does currentrow still retain values from the last line in the file?

Do I need to change Dim currentrow As String()
to Dim currentRow() = New String() {}? Why?

If File.Exists(filename) Then
        Using MyParser As New FileIO.TextFieldParser(filename)
            MyParser.TextFieldType = FileIO.FieldType.Delimited
            MyParser.SetDelimiters("~")
            While Not MyParser.EndOfData
                Try
                    Dim currentrow As String()
                    'at this point, currentrow still contains prev values
                    currentrow = MyParser.ReadFields()
                Catch 
                End Try
            End While
        End Using
End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:50:11+00:00Added an answer on June 13, 2026 at 10:50 pm

    Because you have only declared the loop variable, as against this which results in a correct value of Nothing on every iteration:

    Dim currentrow As String() = Nothing
    

    or even better

    Dim currentrow As String() = MyParser.ReadFields()
    

    “Dim” by itself, without the explicit initialization, will be optimized out as redundant.

    Even if you assign Nothing, it will always be reset to Nothing on every iteration. If you only declare the variable it will always contain the “wrong” old value even if you would use Console.Write or MessageBox.Show afterwards.

    So always assign a default value in a loop variable to avoid side-effects.

    Sidenote C# avoids this error source with the compiler warning CS0165: Use of unassigned local variable ‘variablename’.

    So if you would try to use that unassigned variable before it gets assigned you would not even be able to compile with C#. I don’t know why VB.NET allows it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I place the .html (which consist of the .js web link) file in the
If I decide to place this in my .htaccess file: IndexIgnore */* RewriteEngine ON
I have the following line in my Window stanza in the XAML file: Closing=Window_Closing
I've added a Break on Exception breakpoint as discussed on previous threads and discussed
When I step through the following code in MSVC 2012 I place a breakpoint
I have a line of code like this return foo(barIn); If I place a
I want to know how to place a conditional breakpoint in Eclipse. I have
Whenever I place a breakpoint down in Xcode 3.2.1, for whatever reason the editor
In a big GWT web project, if suppose we place a breakpoing over a
My place of work currently uses CVS. A git migration is planned but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.