VB.Net Correct code doesn't work? - vb.net

I do not get any syntax errors in the code below, but when I compile the code I get the Msgbox("cant post status") instead of the output from main.p(x).status(0). The x and 0 can be any number and I always get the cant post status box. What bugs me most is that I have a debug form with a richtextbox that I load all the data from all seven occurrences of the array: p into when the program starts, and it works just fine. I've included that code as well at the very bottom. Before I run the logging sub, I run an initialization sub that puts a default value into every variable. When I don't have the try/catch in the main_loop, I do not get an error, but all execution stops. My computer doesn't freeze, but actions that should take place after that sub do not. Does anyone know why I can't make a call to main.p(x).status(0) inside this sub?
'Main Class'
Public p(6) as structs.player
Public Shared Sub main_loop()
For x As Integer = 0 To (Main.p.Count - 1) Step 1
If Main.check_act(x) = False Then
MsgBox("past check act")
If Main.p(x).pos >= 1 And Main.p(x).pos <= 3 Then
MsgBox("past pos; pre death")
Try
MsgBox(Main.p(x).status(0))
Catch ex As Exception
MsgBox("cant post status")
End
End Try
End If
End If
Next
End Sub
'Structs Class'
Public Structure player
Dim name As String
Dim type As String
Dim pos As Integer
Dim wait As Integer
Dim mhp As Integer
Dim chp As Integer
Dim mmp As Integer
Dim cmp As Integer
Dim map As Integer
Dim cap As Integer
Dim atk As Integer
Dim def As Integer
Dim mak As Integer
Dim mdf As Integer
Dim spd As Integer
Dim acc As Integer
Dim eva As Integer
Dim crt As Integer
Dim status() As Integer
Dim stats() As Integer
Dim statr() As Integer
Dim elems() As Integer
Dim elemr() As Integer
Dim abl() As Boolean
End Structure
'Debug Class'
Public Shared Sub log(p As player)
'Stats'
Debug.log.Text += ">>> " & p.name.ToString & " <<<" & Chr(10)
Debug.log.Text += "Type: " & p.type.ToString & Chr(10)
Debug.log.Text += "Pos: " & p.pos.ToString & Chr(10)
Debug.log.Text += "Wait: " & p.wait.ToString & Chr(10) & Chr(10)
Debug.log.Text += "HP: " & p.mhp.ToString & _
"/" & p.chp.ToString & Chr(10)
Debug.log.Text += "MP: " & p.mmp.ToString & _
"/" & p.cmp.ToString & Chr(10)
Debug.log.Text += "AP: " & p.map.ToString & _
"/" & p.cap.ToString & Chr(10) & Chr(10)
Debug.log.Text += "ATK: " & p.atk.ToString & Chr(10)
Debug.log.Text += "DEF: " & p.def.ToString & Chr(10)
Debug.log.Text += "MAK: " & p.mak.ToString & Chr(10)
Debug.log.Text += "MDF: " & p.mdf.ToString & Chr(10)
Debug.log.Text += "SPD: " & p.spd.ToString & Chr(10)
Debug.log.Text += "ACC: " & p.acc.ToString & Chr(10)
Debug.log.Text += "EVA: " & p.eva.ToString & Chr(10)
Debug.log.Text += "CRT: " & p.crt.ToString & Chr(10) & Chr(10)
'Status And Elements'
For x As Integer = 0 To (p.status.Count - 1) Step 1
Debug.log.Text += p.status(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
For x As Integer = 0 To (p.stats.Count - 1) Step 1
Debug.log.Text += p.stats(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
For x As Integer = 0 To (p.statr.Count - 1) Step 1
Debug.log.Text += p.statr(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
For x As Integer = 0 To (p.elems.Count - 1) Step 1
Debug.log.Text += p.elems(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
For x As Integer = 0 To (p.elemr.Count - 1) Step 1
Debug.log.Text += p.elemr(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
'Abilities'
For x As Integer = 0 To (p.abl.Count - 1) Step 1
Debug.log.Text += p.abl(x).ToString & Chr(10)
Next
Debug.log.Text += Chr(10)
End Sub

I quickly debugged the code an determined that status(0) is the issue.
The following screen image shows the error ...

Related

Access report cannot be closed or refreshed from VB with updated parameter set

A form's button click opens an access report that comes up with data. The parameters are used with a pass-through query to an SQL stored procedure which returns records. The report does not come up Modal and I would like it to remain that way. However, if the user does not close the report before going back to the form and tries to set new parameters, the report remains open in the background and upon the button click the report is brought to the fore with old parameters and data and not refreshed with new parameters/data.
One option is to go Modal with the report but that makes for rough transitions with the user having to actively close the report. The other option is to close the report during retries which is what I have been trying. I have tried:
If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo
in several different locations: _MousedDown, as the first If in the _Click, and _BeforeInsert. Each time CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded comes up false during the second pass when the report is sitting in the background and the form is being reworked with the next tries new parameters. Also during the second attempt the .OpenReport line fails with an SQL error because strSQLP1 is incomplete. Here's the _Click event:
Private Sub btnPreviewP1_Click()
If (Me.txtToDateP1 < Me.txtFromDateP1) Then
MsgBox ("The From Date must occurr before the To Date!")
End If
Dim strFromDateHMS As String
Dim strToDateHMS As String
Dim strSQLP1 As String
Dim strOpenArgs As String
strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1
strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1
strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1
' This line is all that's needed to modify the PT query
CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1
DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs
End Sub
And the _MouseDown where the .AllReports is currently:
Private Sub btnPreviewP1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo
End If
End Sub
This is the Report_Open:
Private Sub Report_Open(Cancel As Integer)
Dim SplitOpenArgs() As String
SplitOpenArgs = Split(Me.OpenArgs, "|")
Me.lblFromDate.Caption = SplitOpenArgs(1)
Me.lblToDate.Caption = SplitOpenArgs(2)
Me.lblWC.Caption = SplitOpenArgs(3)
Me.lblShift.Caption = SplitOpenArgs(4)
End Sub
Why not just close report before OpenReport? I modified your code:
Private Sub btnPreviewP1_Click()
If (Me.txtToDateP1 < Me.txtFromDateP1) Then
MsgBox ("The From Date must occurr before the To Date!")
End If
Dim strFromDateHMS As String
Dim strToDateHMS As String
Dim strSQLP1 As String
Dim strOpenArgs As String
Dim R
strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1
strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1
strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1
' This line is all that's needed to modify the PT query
CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1
' Check if report is open and close it without saving:
For Each R In Reports
If R.Name = "rpt_ptq_uspWorkCentreReport" Then
DoCmd.Close acReport, "rpt_ptq_uspWorkCentreReport", acSaveNo
Exit For
End If
Next R
DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs
End Sub

If array is empty error

The array is a 9 position array declared as a string, I have 9 text boxes that a user can input data into, each writes to one variable in the array.
I am trying to stop filling the array, and move to print it when the user either fills in all 9 text box's, or stops filling them in when he presses the "write to file" button. From my debugging points, it looks like I get down to the "for" loop, but the program crashes with no errors that I can make heads or tails out of (not syntax or variable)... can anyone see what i'm missing?
Thanks
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FILE_NAME As String = "C:\Users\foo\test2.txt"
Dim i As Integer
Dim j As Integer
Dim aryText(9) As String
MessageBox.Show(j)
aryText(0) = "[" & TextBox1.Text & "]"
j = 0
MessageBox.Show(j)
If String.IsNullOrWhiteSpace(TextBox2.Text) Then
End
Else
aryText(1) = "*" & TextBox2.Text & "{label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
'If TextBox3.Text IsNot Nothing Then
If String.IsNullOrWhiteSpace(TextBox3.Text) Then
End
Else
aryText(2) = TextBox3.Text & " {label: " & "varchar, null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox4.Text) Then
End
Else
aryText(3) = TextBox4.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox5.Text) Then
End
Else
aryText(4) = TextBox5.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox6.Text) Then
End
Else
aryText(5) = TextBox6.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox7.Text) Then
End
Else
aryText(6) = TextBox7.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox8.Text) Then
End
Else
aryText(7) = TextBox8.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
If String.IsNullOrWhiteSpace(TextBox9.Text) Then
End
Else
aryText(8) = TextBox9.Text & " {label: " & "varchar, not null" & "}"
j = j + 1
MessageBox.Show(j)
End If
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
MessageBox.Show(j)
For i = 0 To j
objWriter.WriteLine(aryText(j))
i = i + 1
Next
objWriter.Close()
MessageBox.Show("Text written to file")
End Sub
Please don't debug with MessageBoxes. Visual Studio has a lovely debugger.
VB.net arrays are declared Dim myArray(UpperBound) As String. So with your 9 text boxes you have an upper bound of 8, indexes 0 to 8
You want Exit Sub not End.
A For x = 0 to y...Next works by automatically incrementing x (that is what the Next means, Next x) the default is by one but you can change that by adding a Step. If you attempt to change y you will make a mess. Your For...Next will just write the last value in the array 9 times (aryText(j)) because j doesn't change. Don't increment x in the loop; it increments automatically when Next is called.
No need to mess with i and j; just use a For Each
Using code block for your stream writer ensures all resources are released.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim FILE_NAME As String = "C:\Users\foo\test2.txt"
Dim aryText(8) As String
Dim msg As String = "Please fill in all the boxes,"
If String.IsNullOrWhiteSpace(TextBox1.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(0) = "[" & TextBox1.Text & "]"
End If
If String.IsNullOrWhiteSpace(TextBox2.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(1) = "*" & TextBox2.Text & "{label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox3.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(2) = TextBox3.Text & " {label: " & "varchar, null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox4.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(3) = TextBox4.Text & " {label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox5.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(4) = TextBox5.Text & " {label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox6.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(5) = TextBox6.Text & " {label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox7.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(6) = TextBox7.Text & " {label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox8.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(7) = TextBox8.Text & " {label: " & "varchar, not null" & "}"
End If
If String.IsNullOrWhiteSpace(TextBox9.Text) Then
MessageBox.Show(msg)
Exit Sub
Else
aryText(8) = TextBox9.Text & " {label: " & "varchar, not null" & "}"
End If
Using objWriter As New System.IO.StreamWriter(FILE_NAME, True)
For Each s As String In aryText
objWriter.WriteLine(s)
Next
End Using
MessageBox.Show("Text written to file")
End Sub

Displaying all but the last line in a text file

I've created this 2 player game called Go and I've made it so that the statistics from the game is recorded in a text file. If the same 2 players play each other more than once, their game will be recorded in the same text file on the next line.
I have done all of that, but now I want the previous games to be displayed on screen so that the players can see the scores from previous matches. I don't want the final line to be displayed as that is the score from the game that has just finished. Here's my code so far:
Dim file As System.IO.StreamWriter
'Imports the data from previous forms to form 3
handikomi = Form1.handi_komi
prisonerB = Form2.prisonerB
prisonerW = Form2.prisonerW
bpass = Form2.bpass
wpass = Form2.wpass
bstones = Form2.bstones
wstones = Form2.wstones
btotalscore = prisonerB + handikomi(0, 2)
wtotalscore = prisonerW + handikomi(1, 2)
If btotalscore > wtotalscore Then
winnerlbl.Text = (handikomi(0, 0) & " IS THE WINNER!")
ElseIf wtotalscore > btotalscore Then
winnerlbl.Text = (handikomi(1, 0) & " IS THE WINNER!")
End If
file = My.Computer.FileSystem.OpenTextFileWriter("F:\My Go project flood fill2\Text files\" & handikomi(0, 0) & " VS " & handikomi(1, 0) & ".txt", True)
'Displays statistics from current match
file.WriteLine("BLACK" & "," & "WHITE" & "," & "Total Score" & "," & btotalscore & "," & wtotalscore & "," & "Prisoners" & "," & prisonerB & "," & prisonerW & "," & "Passes" & "," & bpass & "," & wpass & "," & "Stones" & "," & bstones & "," & wstones)
file.Close()
breakdwnlbl.Text = " BLACK WHITE"
breakdwnlbl.Text = (breakdwnlbl.Text & vbNewLine & "Total Score" & " " & btotalscore & " " & wtotalscore)
breakdwnlbl.Text = (breakdwnlbl.Text & vbNewLine & "Prisoners" & " " & prisonerB & " " & prisonerW)
breakdwnlbl.Text = (breakdwnlbl.Text & vbNewLine & "Passes" & " " & bpass & " " & wpass)
breakdwnlbl.Text = (breakdwnlbl.Text & vbNewLine & "Stones" & " " & bstones & " " & wstones)
Dim data As String 'to hold value of file line
Dim filename As String 'declare file
filename = "F:\My Go project flood fill2\Text files\" & handikomi(0, 0) & " VS " & handikomi(1, 0) & ".txt" 'path to file on system
FileOpen(1, filename, OpenMode.Input) 'open file for reading
'try amend
Do While Not EOF(1)
data = LineInput(1)
MsgBox(data)
Loop
I think that I shouldn't be using EOF for this case, but I don't know what else to use as I'm still a beginner. I appreciate any help!
Wouldn't it be easier to read all lines and just skip the last one:
Dim allLines() As String = File.ReadAllLines(filename)
Dim allButLast = allLines.Take(allLines.Length - 1)
The variable allButLast is an IEnumerable(Of String) containing all the lines of the file, except for the last one.
Update:
Here's an example to show each line in a MessageBox:
For Each line As String In allButLast
MessageBox.Show(line)
Next

Invalid qualifier Error Message in vba code

This code is designed to detect the columns of start and finish of a shape which is used and displayed onto the caption of the shape itself. The following code is the problematic code:
Sub Take_Baseline()
Dim forcast_weeksStart() As String
Dim forcast_weeksEnd() As String
Dim forcastDate As String
Dim shp As Shape
Dim split_text() As String
'cycle through all the shapes in the worsheet and enter the forcast date for all the projects into their respective boxes
For Each shp In ActiveSheet.Shapes
'initialize forcast date by parsing
forcast_weeksStart = Split(shp.TopLeftCell.Column.Text, " ")
forcast_weeksEnd = Split(shp.BottomRightCell.Column.Text, " ")
forcastDate = forcast_weeksStart(1) & "-" & forcast_weeksEnd(1)
temp = shp.OLEFormat.Object.Object.Caption
If InStr(temp, "/-/") > 0 & InStr(temp, "In Prog") Then
split_text = Split(shp.OLEFormat.Object.Caption, " ")
For i = 0 To (i = 3)
shp.TextFrame.Characters.Caption = split_text(i) & vbNewLine
Next i
ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption = ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption & vbNewLine & ActiveSheet.Cells(4, AShape.TopLeftCell.Column).Text & " - " & ActiveSheet.Cells(4, AShape.BottomRightCell.Column).Text & vbNewLine & "dates: " & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & "/" & "actualDate"
' ElseIf InStr(temp, "/-/") > 0 & InStr(temp, "In Prog") = 0 Then
'split_text = Split(shp.OLEFormat.Object.Object.Caption, " ")
' For i = 0 To (i = 2)
' shp.OLEFormat.Object.Caption = split_text(i) & vbNewLine
' Next i
'ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption = ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption & vbNewLine & "In Prog" & vbNewLine & ActiveSheet.Cells(4, AShape.TopLeftCell.Column).Text & " - " & ActiveSheet.Cells(4, AShape.BottomRightCell.Column).Text & vbNewLine & "dates: " & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & "actualDate"
End If
Next shp
'For testing purposes
Sheet4.Range("A20").Value = forcast_weeksStart(1)
Sheet4.Range("A21").Value = forcast_weeksEnd(1) End Sub
The error is an
"invalid qualifier"
message which occurs on line
forcast_weeksStart = Split(shp.TopLeftCell.Column.Text, " ")
Right on the "column" word. I don't get why this is happening since the actual drop down menu has the column operation which i can select. I have tried everything from changing it to the OLEformat.Object.Caption etc etc. But nothing has worked. I am still relatively new to vba so any help will be appreciated. Thanks

Treenode not appearing when program restarts

the below code is run from a double click event on a listbox that copies the selected file to the selected node directory on a treeview then adds the selected text as a child node.
It appears to work fine however when the program is closed and then re-opened its not showing the child node.
Any pointers........
Dim Copy2 = aMailbox & tvProgress.SelectedNode.Text & "\" & lstRequired.Text
Dim Copy1 = rPath & "\" & lstRequired.Text
If File.Exists(Copy2) Then
MsgBox("File already added. Please edit from the view above", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
If File.Exists(Copy1) Then
File.Copy(Copy1, Copy2)
tvProgress.SelectedNode.Nodes.Add(lstRequired.Text)
tvProgress.ExpandAll()
Else
MsgBox("This file no longer exists in your Lynx Repository. Please select another", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
The below code is taken entirely from a doubleclick event of the 1st listbox
Dim n As Integer
Dim i As Integer = lstPlanned.SelectedIndex
If lstPlanned.SelectedItems.Count = 0 Then Exit Sub
For n = 0 To UBound(AllDetails)
If AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps = lstPlanned.SelectedItem Then
If Not My.Computer.FileSystem.DirectoryExists(zMailbox & AllDetails(n).uFile) Then
MsgBox("No files located for " & vbNewLine & (AllDetails(n).uName & " (" & AllDetails(n).uCode) & ")" & vbNewLine & " " & vbNewLine & "Please try another...", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
System.IO.Directory.CreateDirectory(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps)
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.dbf")
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.ini", SearchOption.AllDirectories)
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.txt", SearchOption.AllDirectories)
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
tvProgress.Nodes.Remove(rN)
tvProgress.Nodes.Insert(0, rN)
tvProgress.Nodes.Add(New TreeNode(AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps))
If i >= 0 And i < lstPlanned.Items.Count Then
lstPlanned.Items.RemoveAt(i)
End If
Exit Sub
End If
Next
Think that's want you want..maybe ;)
...
System.IO.Directory.CreateDirectory(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps)
' After the Dir is created Node is added to the TreeView
tvProgress.Nodes.Remove(rN)
tvProgress.Nodes.Insert(0, rN)
tvProgress.Nodes.Add(New TreeNode(AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps))
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.dbf")
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
'As ParentNode already exists as Pos 0 you can add child nodes to it
tvProgress.Nodes(0).Nodes.Add(Path.GetFileName(f))
End If
Next
...