Results 1 to 2 of 2

Thread: [RESOLVED] [2005] Nested Loop problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    22

    Resolved [RESOLVED] [2005] Nested Loop problem

    The Program has two files USpres.txt, and usSenate, the program needs to display all presidents that served in the US.Senate. The problem is fixed with the code below. Thanks

    Code:
    Public Class frmUSPRES
        Dim strUSPres, strUSSenate As String
        Private Sub btnCompute_Click(ByVal sender As System.Object, _
                    ByVal e As System.EventArgs) Handles btnCompute.Click
    
            Dim sr1 As IO.StreamReader = IO.File.OpenText("uspres.txt")
            Do While sr1.Peek <> -1
                strUSPres = sr1.ReadLine
                Dim sr2 As IO.StreamReader = IO.File.OpenText("ussenate.txt")
                Do While sr2.Peek <> -1
                    strUSSenate = sr2.ReadLine
                    If strUSPres = strUSSenate Then
                        strUSPres = strUSSenate
                        lstOutput.Items.Add(strUSPres)
                    End If
                Loop
            Loop
    Last edited by peterdfl; May 10th, 2007 at 09:02 AM.

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Nested Loop problem

    This would read 2 more lines:
    vb Code:
    1. If sr1.ReadLine = sr2.ReadLine Then

    What you probably want is:
    vb Code:
    1. If strUSPres = strUSSenate Then
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

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