Extra Line Created Import File - vb.net

An extra line is being created in my import file which is fed in from another CSV and is going to break my import file. How can I remove the extra line that was created? Thanks!
the code I use to create the file is follows
Friend Function ImportFile(ByVal filename As String) As infoEDIProduct()
Dim retVal() As infoEDIProduct
Try
Dim actualFileName As String = IO.Path.GetFileName(filename)
Catch e1 As IO.IOException
MsgBox("File is already open please check file.")
End Try
Dim streamReader As New IO.StreamReader(filename)
Dim streamWriter As New IO.StreamWriter(filename & ".csv")
streamWriter.AutoFlush = True
streamWriter.WriteLine(TabDeliminatedHeaders)
Dim lineIn As String = ""
Do While Not streamReader.EndOfStream
retVal = Resize(retVal)
retVal(retVal.Length - 1) = TransformToEDIProduct(streamReader)
streamWriter.Write(TransformEDIproductIntoTabDeliminated(retVal(retVal.Length - 1)))
Loop
streamWriter.Close()
streamWriter.Dispose()
streamReader.Close()
streamReader.Dispose()
Return retVal
Private Function TransformEDIproductIntoTabDeliminated(ByVal EDIproduct As infoEDIProduct) As String
Dim retVal As String = ""
With EDIproduct
retVal = .lineNumber & vbTab
retVal &= .UPCcode & vbTab
retVal &= .sketchersStyleNumber & vbTab
retVal &= .colourDescription & vbTab
retVal &= .size & vbTab
retVal &= .sketchersDivisionDescription & vbTab
retVal &= .sketchersColourCode & vbTab
retVal &= .sketchersDivisionCode & vbTab
retVal &= .department & vbTab
retVal &= .subDepartment & vbTab
retVal &= .gender & vbTab
retVal &= .productShortDescription & vbTab
retVal &= .productDescription & vbTab
retVal &= .costPrice & vbTab
retVal &= .retailPrice & vbTab
retVal &= .DiscountPrice & vbTab
retVal &= .GeminiDepartmentId
End With
Return retVal
End Function
Private Function TransformProductToEdi(ByVal EDIproduct As infoEDIProduct) As String
Dim retVal As String = ""
With EDIproduct
retVal = .lineNumber & vbCrLf
retVal &= .UPCcode & vbCrLf
retVal &= .sketchersStyleNumber & vbCrLf
retVal &= .colourDescription & vbCrLf
retVal &= .size & vbCrLf
retVal &= .sketchersDivisionDescription & vbCrLf
retVal &= .sketchersColourCode & vbCrLf
retVal &= .sketchersDivisionCode & vbCrLf
retVal &= .department & vbCrLf
retVal &= .subDepartment & vbCrLf
retVal &= .gender & vbCrLf
retVal &= .productShortDescription & vbCrLf
retVal &= .productDescription & vbCrLf
retVal &= .costPrice & vbCrLf
retVal &= .retailPrice & vbCrLf
retVal &= .DiscountPrice & vbCrLf
retVal &= .GeminiDepartmentId & vbCrLf
End With
Return retVal
End Function

the issue is you have to remove the last vbCrLf produced by TransformProductToEdi for the last entry of the array retval
the last line that produce the vbCrLf in TransformProductToEdi is
retVal &= .GeminiDepartmentId & vbCrLf

Related

Cannot get email category color on outlook

I am not able to output the color category of my email on Outlook. Basically, I tried to use the VB code provided by Microsoft Docs to output the name of the color. See image below for reference:
As input, I am giving a Entry_ID which is extracted from the email. This will be basically used in Blue Prism as a code stage
Dim item = _nameSpace.GetItemFromID(Entry_ID)
Dim objCategory As Category
Dim strOutput As String
strOutput = ""
' Check if the Categories collection for the Namespace
' contains one or more Category objects.
If item.Categories.Count > 0 Then
' Enumerate the Categories collection, checking
' the value of the Color property for
' each Category object.
For Each objCategory In item.Categories
' Add the name of the Category object to
' the output string.
strOutput = strOutput & objCategory.Name
' Add information about the assigned color
' to the output string.
Select Case objCategory.Color
Case OlCategoryColor.olCategoryColorNone
strOutput = strOutput & ": No color" & vbCrLf
Case OlCategoryColor.olCategoryColorBlack
strOutput = strOutput & ": Black " & vbCrLf
Case OlCategoryColor.olCategoryColorBlue
strOutput = strOutput & ": Blue" & vbCrLf
Case OlCategoryColor.olCategoryColorGray
strOutput = strOutput & ": Gray" & vbCrLf
Case OlCategoryColor.olCategoryColorGreen
strOutput = strOutput & ": Green" & vbCrLf
Case OlCategoryColor.olCategoryColorMaroon
strOutput = strOutput & ": Maroon" & vbCrLf
Case OlCategoryColor.olCategoryColorOlive
strOutput = strOutput & ": Olive" & vbCrLf
Case OlCategoryColor.olCategoryColorOrange
strOutput = strOutput & ": Orange" & vbCrLf
Case OlCategoryColor.olCategoryColorPeach
strOutput = strOutput & ": Peach" & vbCrLf
Case OlCategoryColor.olCategoryColorPurple
strOutput = strOutput & ": Purple" & vbCrLf
Case OlCategoryColor.olCategoryColorRed
strOutput = strOutput & ": Red" & vbCrLf
Case OlCategoryColor.olCategoryColorSteel
strOutput = strOutput & ": Steel" & vbCrLf
Case OlCategoryColor.olCategoryColorTeal
strOutput = strOutput & ": Teal" & vbCrLf
Case OlCategoryColor.olCategoryColorYellow
strOutput = strOutput & ": Yellow" & vbCrLf
Case Else
strOutput = strOutput & ": Unknown" & vbCrLf
End Select
Next
End If
categoryColor = strOutput
' Display the output string.
'MsgBox strOutput
' Clean up.
'Set objCategory = Nothing
'Set objNameSpaceitem = Nothing
'End Sub
'categoryColor = objCategory

How to get default value of a row?

Actually i'm formatting data to insert in my MySQL DB and i'm at the point where i'm managing the NULL values.
So for manage it i've set a try catch inside the if where i look for datatype and now i have to put in the Catch exception the default value of certain type.
But how can i do it in VB.NET?
Here is my code, any suggestion for code improvment will be grateful
For Each row As DataRow In ds.Tables(0).Rows
righe = ""
For Each column As DataColumn In ds.Tables(0).Columns
If column.DataType = Type.GetType("System.DateTime") Then
Try
righe &= "'" & Format(row.Item(column.ColumnName), "yyyy-MM-dd") & "', "
Catch ex As Exception
End Try
ElseIf column.DataType = Type.GetType("System.TimeSpan") Then
righe &= "'" & Format(row.Item(column.ColumnName).ToString, "HH\:mm\:ss") & "', "
ElseIf column.DataType = Type.GetType("System.Int32") Then
righe &= row.Item(column.ColumnName) & ", "
ElseIf column.DataType = Type.GetType("System.Single") Then
righe &= Replace(row.Item(column.ColumnName), ",", ".") & ", "
ElseIf column.DataType = Type.GetType("System.Byte") Then
righe &= row.Item(column.ColumnName) & ", "
ElseIf column.DataType = Type.GetType("System.Double") Then
righe &= Replace(row.Item(column.ColumnName), ",", ".") & ", "
ElseIf column.DataType = Type.GetType("System.String") Then
righe &= "'" & APICI(row.Item(column.ColumnName)) & "', "
End If
Next
righe = Mid(righe, 1, Len(righe) - 2)
Next

Writeline String.format not compleating last value. vb.net

I am trying to write an xml file ussing a little less conventional method, Just for those wondering there's a long story too why I am doing this. The real point is though that I cant seem to get the Tag named to write its value to the resulting XML file and I cant fuigureout why... could somebody help me with this...
The code as follows...
Private Sub SaveToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem2.Click
'define a save dialog
Dim save_file As New SaveFileDialog
'give its extension...
save_file.RestoreDirectory = True
save_file.InitialDirectory = My.Application.Info.DirectoryPath & " \ LIBRARY"
save_file.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
save_file.FilterIndex = 1
''create a datatable
'Dim my_datatable As New DataTable
'if ok click
If save_file.ShowDialog() = DialogResult.OK Then
Using writer As New IO.StreamWriter(save_file.FileName)
writer.WriteLine("<COMPELATION>")
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If Not row.IsNewRow Then
writer.WriteLine(String.Format(vbCrLf & vbTab & "<Data>" & vbCrLf & vbTab & vbTab & "<DEF>{0}</DEF>" & vbCrLf & vbTab & vbTab & "<HGT>{1}</HGT>" & vbCrLf & vbTab & vbTab & "<LEN>{2}</LEN>" & vbCrLf & vbTab & vbTab & "<WDT>{3}</WDT>" & vbCrLf & vbTab & vbTab & "<THK>{4}</THK>" & vbCrLf & vbTab & vbTab & "<AN1>{5}</AN1>" & vbCrLf & vbTab & vbTab & "<AN2>{6}</AN2>" & vbCrLf & vbTab & vbTab & "<MAT>{7}</MAT>" & vbCrLf & vbTab & "</Data>",
row.Cells(0).Value,
row.Cells(1).Value,
row.Cells(2).Value,
row.Cells(3).Value,
row.Cells(4).Value,
row.Cells(5).Value,
row.Cells(6).Value,
row.Cells(7).Value))
End If
Next
writer.WriteLine("</COMPELATION>")
writer.Close()
End Using
Dim result1 As DialogResult = MessageBox.Show("Would you like to use this file as the default library?", "Information", MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
'Set the new file as the default XML...
My.Settings.DEFAULTXML = save_file.FileName
'Reload and bind the data source...
Me.Refresh()
Else
End If
End If
End Sub

how to check if the data being entered exists already

here is my code to submit data to my csv file. How do I check to see if the data already exists before saving it.
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, True)
'If My.Computer.FileSystem.FileExists(csvFile) Then
'outFile.WriteLine("job number, sales order number, date, requested by, serial number, hose type, hose size, fitting 1, fitting 2, qty, oal, cut off, offset, crimp 1, crimp 2, cleaned, pigged", False)
'End If
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text)
MessageBox.Show("INPUT WAS SAVED")
Dim butt As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)
butt.Enabled = False
'butt.Visible = False
outFile.Close()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
Is this what you're looking for?
Dim fn As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim fileText As String
Dim outString As String = TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text
Using reader As StreamReader = File.OpenText(fn)
fileText = reader.ReadToEnd
End Using
Using outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(fn, True)
If fileText.Contains(outString) Then
'do stuff when the string is already present, e.g.:
MessageBox.Show("You've already entered that one.")
Else
'do stuff when it isn't, e.g.:
outFile.WriteLine(outString)
End If
End Using

Get Network adapter information using WMI

I am trying to retrieve the network adapter configuration details from a remote server. I came up with the below code in VB.NET using WMI.
When the code is executed (button click), I get an error
"An error occurred while querying for WMI data: Not found".
Please help in any suggestions or corrections on where I am going wrong with this piece of code?
Try
Dim path As ManagementPath = Nothing
Dim options As ConnectionOptions = Nothing
Dim scope As ManagementScope = Nothing
path = New ManagementPath("\\" & ServerName & "\root\cimv2")
options = New ConnectionOptions
options.Username = usernamebox.Text
options.Password = passwordbox.Text
scope = New ManagementScope(path, options)
scope.Connect()
Try
If scope.IsConnected = True Then
Dim nwquery As ObjectQuery = Nothing
nwquery = New ObjectQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(scope, nwquery)
Dim nwquerycol As ManagementObjectCollection
nwquerycol = searcher.Get
For Each nwobject As ManagementObject In nwquerycol
DataView_TextBox.Text &= "Name: " + nwobject("Name") & Newline
DataView_TextBox.Text &= "Name: " + nwobject("Description") & Newline
DataView_TextBox.Text &= "DHCPEnabled: " + (nwobject("DHCPEnabled").ToString) & ControlChars.NewLine
DataView_TextBox.Text &= "DHCPServer: " + nwobject("DHCPServer") & ControlChars.NewLine
DataView_TextBox.Text &= "DNSDomain: " + nwobject("DNSDomain") & ControlChars.NewLine
DataView_TextBox.Text &= "DNSHostName: " + nwobject("DNSHostName") & ControlChars.NewLine
If nwobject("IPAddress") Is Nothing Then
DataView_TextBox.Text &= "IPAddress:" + nwobject("IPAddress") & ControlChars.NewLine
Else
Dim arrIPAddress As String
arrIPAddress = nwobject("IPAddress")
For Each arrValue As String In arrIPAddress
DataView_TextBox.Text &= "IPAddress: {0}" + arrValue & ControlChars.NewLine
Next
End If
If nwobject("IPSubnet") Is Nothing Then
DataView_TextBox.Text &= "IPSubnet: " + nwobject("IPSubnet") & ControlChars.NewLine
Else
Dim arrIPSubnet As String
arrIPSubnet = nwobject("IPSubnet")
For Each arrValue As String In arrIPSubnet
DataView_TextBox.Text &= "IPSubnet: {0}" + arrValue & ControlChars.NewLine
Next
End If
DataView_TextBox.Text &= "MACAddress: {0}" + nwobject("MACAddress") & ControlChars.NewLine
DataView_TextBox.Text &= "======================================" & ControlChars.NewLine
Next
End If
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & ex.Message)
End Try
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & ex.Message)
End Try