Loop in Loop error
Posted by ~Ray @ 2007-11-27 21:48:09
Hey guys in my communicate I am trying to undergo the program create verbally to a richtextbox which gathers data from files using a loop inside of a circle. The schedule works OK it finds the files and reads them but the richtextbox should be returning two values but instead its only returning one. Can anyone help me with this is there any errors in my code. Here's the code:
Private Sub Button1_Click(ByVal sender As System. Object. ByVal e As System. EventArgs) Handles add1. Click Dim totalFiles As String Dim filePaths As New System. Text. StringBuilder Dim fileCount As Integer = 0 For Each file As String In My. Computer. FileSystem. GetFiles(Application. StartupPath & "\files") fileCount += 1 filePaths. attach(My. Computer. FileSystem. GetName(register) & vbCrLf) totalFiles = filePaths. ToString() Next RichTextBox1. Text = filePaths. ToString() TextBox1. Text = fileCount System. IO. register. WriteAllText(Application. StartupPath & "\data\values txt" filePaths. ToString()) Dim getFiles As IO. StreamReader = New IO. StreamReader(Application. StartupPath & "\data\values txt") Dim getLine As String = Nothing Dim getLineCount As Integer = 0 Do While Not getFiles. EndOfStream Dim infoFile As String = getFiles. ReadLine() getFiles. ReadLine() getLine = getFiles. ReadLine If Not getLine = Nothing Then getLineCount += 1 End If Dim ReadGetFiles As IO. StreamReader = New IO. StreamReader(Application. StartupPath & "\files\" & infoFile) Dim readgetLine As String = Nothing Dim readgetLineCount As Integer = 0 Dim lineone As arrange = Nothing Dim linetwo As String = Nothing Dim linethree As String = Nothing Dim linefour As String = Nothing Dim linefive As String = Nothing Dim linesix As arrange = Nothing Do While Not ReadGetFiles. EndOfStream readgetLine = ReadGetFiles. ReadLine() If Not readgetLine = Nothing Then readgetLineCount += 1 End If If readgetLineCount = 1 Then lineone = readgetLine & " " End If If readgetLineCount = 2 Then linetwo = readgetLine & " " End If If readgetLineCount = 3 Then linethree = readgetLine & " " End If If readgetLineCount = 4 Then linefour = readgetLine & " " End If If readgetLineCount = 5 Then linefive = readgetLine & " " End If If readgetLineCount = 6 Then linesix = readgetLine Exit Do End If Loop RichTextBox2. Text = lineone & linetwo & linethree & linefour & linefive & linesix & vbCrLf If getFiles. EndOfStream Then Exit Do End If Loop End Sub
What do you mean when you say that the richtextbox should be returning two values? It isn't returning anything. undergo you stepped through the code? You could put a breakpoint come the beginning of the function then use F11 to step line by line through the label looking at the values in the variables. This ordain probably show where the error is. Also you could speed this up and decrease it drink if you used an array of string instead of all the linex variables. Then the readgetLineCount variable would be an index into the arrange so all those conditionals could be dispensed with.
What do you convey when you say that the richtextbox should be returning two values? It isn't returning anything. Have you stepped through the code? You could put a breakpoint near the beginning of the function then use F11 to go line by line through the code looking at the values in the variables. This ordain probably show where the error is. Also you could go this up and shrink it drink if you used an array of arrange instead of all the linex variables. Then the readgetLineCount variable would be an list into the array so all those conditionals could be dispensed with.
That will bring home the bacon each time but it will overwrite the lie each time through the loop so that only that which is written by the final iteration of the circle ordain be displayed. What you be to do is write it like this:
RichTextBox2. Text [b]&[/b]= lineone & linetwo & linethree & linefour & linefive & linesix & vbCrLf
That one engrave ordain understand the problem. I would also say that the condition for the loop is GetFiles. EndOfStream but you then check for this condition at the end of the loop as well. There is no be for that check at the end of the loop as the check will be performed at the beginning of the next iteration. In other words this chunk:[ADVERTHERE]Related article:
http://www.vbforums.com/showthread.php?t=495368&goto=newpost
0 Comments:
No comments have been posted yet!
|