Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > code doesn't continue after while loop


Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2012, 10:14 AM
tilky tilky is offline
Newcomer
 
Join Date: Nov 2011
Posts: 21
Default code doesn't continue after while loop


I have a short code which reads three lines of a file at a time and then updates 3 arrays (one for each line. I started with there being only 3 lines in the file, and wanted to read them.
Code:
        While EOF(1) = False
            ReDim arrIP(LoopCount), arrUsername(LoopCount), arrPassword(LoopCount)
            IP = LineInput(1)
            Username = LineInput(1)
            Password = LineInput(1)
            arrIP(LoopCount) = IP
            arrUsername(LoopCount) = Username
            arrPassword(LoopCount) = Password
            LoopCount = LoopCount + 1
            Label3.Text = LoopCount
        End While
        Me.Close()
i set label3.text to the amount of times it looped to make sure it didn't keep looping. It gets to 1 and doesn't get any higher (which is what is supposed to happen). However, the Me.close never runs (the program stays open). What am i doing wrong here?
Reply With Quote
  #2  
Old 07-10-2012, 11:29 AM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,739
Default

How are the lines terminated? The following works fine for me:
Code:
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim arrIP() As String
        Dim arrUsername() As String
        Dim arrPassword() As String
        Dim LoopCount As Integer
        Dim IP As String
        Dim Username As String
        Dim Password As String
        FileOpen(1, "C:\temps.txt", OpenMode.Output, OpenAccess.Write, OpenShare.Default)
        Print(1, "10.10.10.2" & vbCrLf)
        Print(1, "Me" & vbCrLf)
        Print(1, "MePass" & vbCrLf)
        Print(1, "10.10.10.3" & vbCrLf)
        Print(1, "You" & vbCrLf)
        Print(1, "YouPass" & vbCrLf)
        FileClose(1)
        FileOpen(1, "C:\temps.txt", OpenMode.Input, OpenAccess.Read, OpenShare.Default)
        While EOF(1) = False
            ReDim Preserve arrIP(LoopCount), arrUsername(LoopCount), arrPassword(LoopCount)
            IP = LineInput(1)
            Username = LineInput(1)
            Password = LineInput(1)
            arrIP(LoopCount) = IP
            arrUsername(LoopCount) = Username
            arrPassword(LoopCount) = Password
            LoopCount = LoopCount + 1
            Label1.Text = LoopCount
        End While
        FileClose(1)
        Me.Close()
    End Sub
End Class
__________________
"May the code that you write never work in ways that you didn't expect; and may the code that you didn't write never require you to maintain it". - Ancient Chinese Proverb
Reply With Quote
  #3  
Old 07-10-2012, 04:29 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 866
Default

Is that the whole method? Do you have any error handling?

And where do you run this code? If you run it in a Form.Load event handler or a function called from a Form.Load handler, WinForms might be swallowing errors.
__________________
C# _VB.NET _
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->