16,004,969 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by ATeDe (Top 10 by date)
ATeDe
18-Mar-18 17:33pm
View
Hey Maciej, Instead asking funny questions help, dear man, to improve solution ...Can't you see that is far from perfect?
Module Module1
' emulate the TextBox/ Label array as in the version VB6
Public txtBox() As TextBox = {Form1.TextBox1, Form1.TextBox2, Form1.TextBox3, Form1.TextBox4, Form1.TextBox5, Form1.TextBox6, Form1.TextBox7}
Public myLabel() As Label = {Form1.Label1, Form1.Label2, Form1.Label3, Form1.Label4, Form1.Label5, Form1.Label6, Form1.Label7}
Public Phones As String() = {"1234567xx", "123456xxx", "", "123456789", "987654321", "0", "PhoneNumber"}
End Module
Then....
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i As Integer
For Each lbl In myLabel
myLabel(i).Text = "Customer" & String.Format(i + 1)
i += 1
Next
End Sub
ATeDe
18-Mar-18 17:32pm
View
Deleted
Hey Maciej, Instead asking fanny questions help, dear man, to improve solution ...Can't you see that is far from perfect?
Module Module1
' emulate the TextBox/ Label array as in the version VB6
Public txtBox() As TextBox = {Form1.TextBox1, Form1.TextBox2, Form1.TextBox3, Form1.TextBox4, Form1.TextBox5, Form1.TextBox6, Form1.TextBox7}
Public myLabel() As Label = {Form1.Label1, Form1.Label2, Form1.Label3, Form1.Label4, Form1.Label5, Form1.Label6, Form1.Label7}
Public Phones As String() = {"1234567xx", "123456xxx", "", "123456789", "987654321", "0", "PhoneNumber"}
End Module
Then....
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i As Integer
For Each lbl In myLabel
myLabel(i).Text = "Customer" & String.Format(i + 1)
i += 1
Next
End Sub
ATeDe
18-Mar-18 17:28pm
View
Deleted
Hey Maciej, Instead asking fanny questions help, dear man, to improve solution ...Can't you see that is far from perfect?
Module Module1
' emulate the TextBox/ Label array as in the version VB6
Public txtBox() As TextBox = {Form1.TextBox1, Form1.TextBox2, Form1.TextBox3, Form1.TextBox4, Form1.TextBox5, Form1.TextBox6, Form1.TextBox7}
Public myLabel() As Label = {Form1.Label1, Form1.Label2, Form1.Label3, Form1.Label4, Form1.Label5, Form1.Label6, Form1.Label7}
Public Phones As String() = {"1234567xx", "123456xxx", "", "123456789", "987654321", "0", "PhoneNumber"}
End Module
Than....
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i As Integer
For Each lbl In myLabel
myLabel(i).Text = "Customer" & String.Format(i + 1)
i += 1
Next
End Sub
ATeDe
14-Mar-18 20:17pm
View
Thanks Maciej for your solution, which obviously works well, despite small 'hiccup' in the beginning, as my VB.NET compiler (VS2017) does not like 1st line of code:
Dim lines() As String = File.ReadAllLines(CSVfile).ToList() complaining
Error BC30311 Value of type 'List(Of String)' cannot be converted to 'String()'
After changing to
Dim lines() As String = File.ReadAllLines(CSVfile) the code executes smoothly
Another think to notice is that, it takes approx 10% longer to convert my CSV file (10 columns, 131745 records)
Thank you!
Original code elapsed time: 3490.86 Milliseconds
->Unformatted table: Count= 131745
A,B,C,D,E,F,G,H,I,J
2014,26,00001,1,01,900001,150,150,0,1412
2014,26,00001,1,01,905111,3500,3500,0,1412
2014,26,00001,1,01,907213,60,0,60,1412
2014,26,00002,1,01,900001,250,250,0,1827
..................
New routine elapsed time: 3763.66 Milliseconds
->Unformatted table: Count= 131745
A,B,C,D,E,F,G,H,I,J
2014,26,00001,1,01,900001,150,150,0,1412
2014,26,00001,1,01,905111,3500,3500,0,1412
2014,26,00001,1,01,907213,60,0,60,1412
2014,26,00002,1,01,900001,250,250,0,1827
..................
ATeDe
8-Feb-18 17:39pm
View
Yeah, and instead of using Dim A As String(), listA might be created directly, and then we got very neat statement:
Dim C = listA.Where(Function(x) B.Contains(x.Key))
For Each item In C
Console.WriteLine("{0} {1}", item.Key, item.Value)
Next
ATeDe
8-Feb-18 15:59pm
View
Great stuff, Richard! Thanks a lot!
ATeDe
8-Feb-18 15:55pm
View
Thanks Graeme, nice example of LINQ application. Actually you've given me indication that KeyValuePair can be used to convert array A to listA following way:
Dim listA As List(Of KeyValuePair(Of String, Integer)) = A.Select(Function(x, i) New KeyValuePair(Of String, Integer)(x, i)).ToList()
ATeDe
28-Dec-17 16:41pm
View
Hi Dave!
...the code using XDocument and LINQ query looks as follow:
Dim listTableA = XDocument.Load("details.XML").Root.Elements("tableA")
Dim tableAList As List(Of TableA)
tableAList = (From e In listTableA
Select New TableA With {
.Field1 = CInt(e.<field1>.Value),
.Field2 = CStr(e.<field2>.Value),
.Field3 = CStr(e.<field3>.Value),
.Field4 = (
From o In e...<field4>...<tableb>
Select New TableB With {
.Fld1 = CInt(o.<fld1>.Value),
.Fld2 = CInt(o.<fld2>.Value),
.Fld3 = CDec(o.<fld3>.Value)
}).ToArray()
}).ToList()
Dim tableA = New DataTable("tableA")
tableA.Columns.Add("Field1", GetType(Integer))
tableA.Columns.Add("Field2", GetType(String))
tableA.Columns.Add("Field3", GetType(String))
Dim tableB = New DataTable("tableB")
tableB.Columns.Add("Fld1", GetType(Integer))
tableB.Columns.Add("Fld2", GetType(Integer))
tableB.Columns.Add("Fld3", GetType(Decimal))
For Each a In tableAList
Dim rowA As New List(Of Object) From {a.Field1, a.Field2, a.Field3}
tableA.Rows.Add(rowA.ToArray())
For Each b In a.Field4
Dim rowB As New List(Of Object) From {b.Fld1, b.Fld2, b.Fld3}
tableB.Rows.Add(rowB.ToArray())
Next
Next
_ShowTable(tableA)
_ShowTable(tableB)
...and results as below:
->Unformatted table: tableA
Field1,Field2,Field3
11,12,13
21,22,23
31,32,33
->Unformatted table: tableB
Fld1,Fld2,Fld3
1,1,1.3
1,2,1.6
2,2,2.3
2,2,2.6
3,3,3.3
3,4,3.6
4,4,3.9
...Re: What is the end result supposed to be? What is this being used for?
Actually, I hope to develop some sort of most simplistic way, perhaps maybe even generating code to read automatically my legacy scientific data. At the moment, I can't see any chances to simplify the code. The next step would be to use a Dictionary as it is easy to use and effective. It has many functions (like ContainsKey and TryGetValue) that do lookups. And I hope that way my code will recognise the structure and get correct type of T for my data records
ATeDe
27-Dec-17 15:35pm
View
Hi Dave!
...after this piece of code:
Dim dataSet As DataSet = New DataSet
dataSet.ReadXml("details.XML")
Dim dataTable As New DataTable
For Each dataTable In dataSet.Tables
_ShowTable(dataTable)
Next
_NewLine(Message:="Reading using ReadXml finished, OK! ")
... the printout looks like this:
->Unformatted table: tableA
Field1,Field2,Field3,tableA_Id
11,12,13,0
21,22,23,1
31,32,33,2
->Unformatted table: detail
detail_Id,tableA_Id
0,0
1,1
2,2
->Unformatted table: tableB
Fld1,Fld2,Fld3,detail_Id
1.1,1.2,1.3,0
1.4,1.5,1.6,0
2.1,2.2,2.3,1
2.4,2.5,2.6,1
3.1,3.2,3.3,2
3.4,3.5,3.6,2
3.7,3.8,3.9,2
->Reading using ReadXml finished, OK! Press any key to continue...
...as you see everything is going right way, except fact tableA & tableB are apart instead of look like that or similar:
11,12,13,1.1,1.2,1.3
1.4,1.5,1.6
21,22,23,2.1,2.2,2.3
2.4,2.5,2.6
31,32,33,3.1,3.2,3.3
3.4,3.5,3.6
3.7,3.8,3.9
...do you see what's the problem now?
ATeDe
27-Dec-17 14:06pm
View
Hi Dave! Thanks for reply, but I should have mentioned in 1st post, that the source of data is in form of XML file, which looks like one attached below. I don't have problem reading XML file using
dataSet.ReadXml(fileXML)
or
XDocument.Load(fileXML).Root.Elements("Details")
and creating <tablea>, but can't create composite DataTable including <tableb> detail data!!!
Show More