Seems that there is a looping error with my code

  • Thread starter Thread starter jbrotto
  • Start date Start date
J

jbrotto

Guest
Seems that my application does not go through each row when making xml files. My counter is n for the rows. It only copies the first row.


Public Class Form1
Dim SQLString, SQLString2 As String
Dim entriesDOCNUM, dates, entriesStoreNum, entriesStorName, quantities, UPCS, description As String
Dim counters, counters2, counters3 As Integer
Dim whereclaus As String
Dim fileNumber, startFileNumber As Integer
Dim inDirectory, outDirectory As String
Dim CSVtext As String = ""
Dim browserDirectory As New FolderBrowserDialog
Dim lineData(), lineData2(), lineData3(), lineData4(), lineData5(), lineData6(), lineDate() As String
Dim biggestCount As Integer
Dim n As Integer = "0"
Dim storeNameChange As Boolean = False
Dim storeName1, storeName2 As String
Dim storeNum1, storeNum2 As String
Dim POnumber As Integer
Private Sub BrowseBtn_Click(sender As Object, e As EventArgs) Handles BrowseBtn.Click

If browserDirectory.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

Try
DirectoryTxtBox.Text = browserDirectory.SelectedPath.ToString
DirectoryTxtBox.Text = DirectoryTxtBox.Text
inDirectory = DirectoryTxtBox.Text
Catch ex As Exception

End Try
Else
Exit Sub
End If
End Sub


Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles ResetBox.Click
entriesDOCNUM = ""
dates = ""
entriesStoreNum = ""
entriesStorName = ""
quantities = ""
UPCS = ""
description = ""
POnumber = 0
DateTxtBox.Text = ""
DescriptionTxtBox.Text = ""
DirectoryTxtBox.Text = ""
FileNumberStartTxtBox.Text = ""
InvtoryTransTxtBox.Text = ""
QuantityTxtBox.Text = ""
StoreNameTxtBox.Text = ""
StoreNumTxtBox.Text = ""
POtxtBox.Text = ""
UPCtxtBox.Text = ""
n = "0"
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles AddBtn.Click
' direcory
Try
fileNumber = FileNumberStartTxtBox.Text
Catch ex As Exception
fileNumber = 5050
End Try

'get the start point to match max later on
startFileNumber = fileNumber
'entries
entriesDOCNUM = InvtoryTransTxtBox.Text
entriesStoreNum = StoreNumTxtBox.Text
entriesStorName = StoreNameTxtBox.Text
UPCS = UPCtxtBox.Text
description = DescriptionTxtBox.Text
quantities = QuantityTxtBox.Text


'takes to number of row
lineData = Split(entriesDOCNUM, vbNewLine)
'number of rows from invenotry transfer
counters = lineData.Count()

whereclaus = String.Join(" ", lineData)
'shows second item in array
'MessageBox.Show(lineData(1))

'entries


'takes to number of row
lineData2 = Split(entriesStoreNum, vbNewLine)
'number of rows from invenotry transfer
counters2 = lineData2.Count()

whereclaus = String.Join(" ", lineData)
'shows second item in array
'MessageBox.Show(lineData(1))
'entries


'takes to number of row
lineData3 = Split(entriesStorName, vbNewLine)
'number of rows from invenotry transfer
counters3 = lineData3.Count()
MsgBox(lineData3(4), MsgBoxStyle.MsgBoxHelp, "test")

'takes to number of row upcs
lineData4 = Split(UPCS, vbNewLine)
'takes to number of row quantity
lineData5 = Split(quantities, vbNewLine)
'takes to number of row description
lineData6 = Split(description, vbNewLine)
'takes the date
lineDate = Split(dates, vbNewLine)

whereclaus = String.Join(" ", lineData)
'shows second item in array
'MessageBox.Show(lineData(1))

If counters > counters2 Then
biggestCount = counters
ElseIf counters2 > counters3 Then
biggestCount = counters2
Else
biggestCount = counters3
End If

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles CloseBtn.Click
Me.Close()
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles ProcessBtn.Click
If browserDirectory.SelectedPath < "" Then
Exit Sub
End If
'redlare after
'outDirectory = inDirectory.ToString & "\0000" & fileNumber.ToString() & ".txt"
POnumber = POtxtBox.Text.ToString.Trim
If POnumber.ToString.Length <> 5 Then
MsgBox("PO needs to be a 5 digit number", MsgBoxStyle.Critical, "PO Length")
Exit Sub
End If
Do Until biggestCount + startFileNumber = fileNumber Or n = biggestCount
Dim linenum As Integer = 118
storeNameChange = False
Try
storeName1 = ""
storeName2 = ""
SQLString = "<?xml version=""1.0"" encoding="" UTF-8""?> " & vbNewLine &
"<Tran><Form_Id>SDM856LD</Form_Id><FS_VER>5, 0, 1, 256</FS_VER><FS_UNITNUM></FS_UNITNUM><FS_LANG>E</FS_LANG><FS_FSNUM>FS2001112301287</FS_FSNUM><FS_PO_UNITNUM></FS_PO_UNITNUM><FS_Viewer><FS_Title>exAct® - Shoppers Drug Mart ASN DSD - Faxinating Solutions Inc.</FS_Title><FS_STYLE>SDM856LD\SDM856LD_01.xsl</FS_STYLE></FS_Viewer><LINENUM>0000000127</LINENUM><STATUS>Y</STATUS><BSN02>" &
lineData(n) &
"</BSN02><VENDOR>54324</VENDOR><CONF>Y</CONF><CreationFlag>N</CreationFlag><Shipment><LINENUM>0000000126</LINENUM><STATUS>Y</STATUS><DTM02_067>" &
lineDate(n) & "</DTM02_067><N102_SF>163453 CANADA INC</N102_SF><N104_SF>ER7</N104_SF><N102_ST>" & lineData3(n) & "</N102_ST><N104_ST>" & lineData2(n) &
"</N104_ST><DerivedFlag>N</DerivedFlag><OrderPOSource></OrderPOSource><Order><LINENUM>0000000125</LINENUM><STATUS>Y</STATUS><PRF01>" &
POnumber.ToString() & "</PRF01>"


Do Until storeName1 <> storeName2
If storeName1 = storeName2 Then
SQLString = SQLString & "<Item><LINENUM>" & "0000000" & linenum & "</LINENUM><STATUS>Y</STATUS><LIN02>UP</LIN02><LIN03>" & lineData4(n) & "</LIN03><SN102>" & lineData5(n) & "</SN102><SN103>EA</SN103><PID05>" & lineData6(n) & "</PID05></Item>"
linenum = linenum + 1
storeName1 = lineData3(n).ToString()
If n > 0 Then
storeName2 = lineData3(n - 1).ToString()
n = n + 1
Else
n = n + 1
storeName2 = storeName1
End If
If biggestCount + startFileNumber = fileNumber Then

storeNameChange = True
Exit Try
End If
Else
storeNameChange = True
End If

Loop
SQLString = SQLString & "</Order></Shipment></Tran>"
Catch ex As Exception
n = n + 1
End Try
CSVtext = SQLString


'redlare

outDirectory = inDirectory.ToString & "\0000" & fileNumber.ToString() & ".xml"
'unquote top after the file is made
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(outDirectory, False, System.Text.Encoding.Default)

outFile.WriteLine(CSVtext.ToString())

outFile.Close()

fileNumber = fileNumber + 1
If fileNumber = startFileNumber + lineData.Length Then
Exit Do
End If
If n = lineData2.Length Then
Exit Sub
End If

Loop

End Sub
End Class

Continue reading...
 
Back
Top