Mikelgiles Active Member Licensed User Longtime User Apr 7, 2017 #1 Can someone advise me what I am doing wrong or tell me how to fix this code? This is code that I copied from the web site so I assume it works and that I am doing something wrong. Instead of ending up with a csv file with one record per TabelView row I end up with 22 records per TableView. 22 happens to be the number of columns of the TableView. <code> exportTableViewToCSV(tvMaster,"CashFlow.csv") Sub exportTableViewToCSV(tv As TableView, filename As String) Dim su As StringUtils Dim l As List l.Initialize For y = 0 To tv.Items.Size - 1 tv.SelectedRow = y Dim Row() As Object = tv.SelectedRowValues Dim NRow(Row.Length) As String For x = 0 To Row.Length - 1 NRow(x) = Row(x) l.Add(NRow) Next Next Try su.SaveCSV(dirData, filename, ",", l) Catch Log(LastException.Message) End Try End Sub </code>
Can someone advise me what I am doing wrong or tell me how to fix this code? This is code that I copied from the web site so I assume it works and that I am doing something wrong. Instead of ending up with a csv file with one record per TabelView row I end up with 22 records per TableView. 22 happens to be the number of columns of the TableView. <code> exportTableViewToCSV(tvMaster,"CashFlow.csv") Sub exportTableViewToCSV(tv As TableView, filename As String) Dim su As StringUtils Dim l As List l.Initialize For y = 0 To tv.Items.Size - 1 tv.SelectedRow = y Dim Row() As Object = tv.SelectedRowValues Dim NRow(Row.Length) As String For x = 0 To Row.Length - 1 NRow(x) = Row(x) l.Add(NRow) Next Next Try su.SaveCSV(dirData, filename, ",", l) Catch Log(LastException.Message) End Try End Sub </code>
Mikelgiles Active Member Licensed User Longtime User Apr 7, 2017 #2 Nevermind. I think I have figured it out. l.Add(NRow) was inside the loop instead of after it. I wonder if I screwed the code up> it seems that I would have found other questions about it. Upvote 0
Nevermind. I think I have figured it out. l.Add(NRow) was inside the loop instead of after it. I wonder if I screwed the code up> it seems that I would have found other questions about it.
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #3 I belive that, that code could be better. Code: Dim Su as stringutils. su.SaveCSV(dirData, filename, ",", tv.items) That's all you need to save the tableview into an csv without the loop. Upvote 0
I belive that, that code could be better. Code: Dim Su as stringutils. su.SaveCSV(dirData, filename, ",", tv.items) That's all you need to save the tableview into an csv without the loop.
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #4 Enrique Gonzalez R said: I belive that, that code could be better. Code: Dim Su as stringutils. su.SaveCSV(dirData, filename, ",", tv.items) That's all you need to save the tableview into an csv without the loop. Click to expand... Upvote 0
Enrique Gonzalez R said: I belive that, that code could be better. Code: Dim Su as stringutils. su.SaveCSV(dirData, filename, ",", tv.items) That's all you need to save the tableview into an csv without the loop. Click to expand...
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #5 That looks super but I am doing something wrong. I get this error https://www.screencast.com/t/f17eaNcG using this code <Code> Sub btnSaveMaster_Action Dim Su As StringUtils Su.SaveCSV(dirData, "CashFlow.csv", ";", tvMaster.items) 'exportTableViewToCSV(tvMaster,"CashFlow.csv") End Sub </Code> Using this code does still work so I am pretty sure my paths are OK <Code> Sub btnSaveMaster_Action 'Dim Su As StringUtils 'Su.SaveCSV(dirData, "CashFlow.csv", ";", tvMaster.items) exportTableViewToCSV(tvMaster,"CashFlow.csv") End Sub </Code> Two more questions: 1) Can LoadCSV be used to load the saved TableView? 2) SortType is only for List or can it be used on a TableView. I could not find any docs for using it on TableView. Your help is GREATLY appreciated. Upvote 0
That looks super but I am doing something wrong. I get this error https://www.screencast.com/t/f17eaNcG using this code <Code> Sub btnSaveMaster_Action Dim Su As StringUtils Su.SaveCSV(dirData, "CashFlow.csv", ";", tvMaster.items) 'exportTableViewToCSV(tvMaster,"CashFlow.csv") End Sub </Code> Using this code does still work so I am pretty sure my paths are OK <Code> Sub btnSaveMaster_Action 'Dim Su As StringUtils 'Su.SaveCSV(dirData, "CashFlow.csv", ";", tvMaster.items) exportTableViewToCSV(tvMaster,"CashFlow.csv") End Sub </Code> Two more questions: 1) Can LoadCSV be used to load the saved TableView? 2) SortType is only for List or can it be used on a TableView. I could not find any docs for using it on TableView. Your help is GREATLY appreciated.
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #6 Hi Mikel could you show me this sub exportTableViewToCSV This line is actually exporting the tableview to CSV Su.SaveCSV(dirData, "CashFlow.csv", ";",tvMaster.items) And the for the questions: 1. Yes, loadcsv is the best way to load the tableview. 2. Technically no. SortType is meant to be used with a list of Types and not with a list of arrays (what a tableview is) Yet it's easy to convert an array into a type, store the list into a file and load that file into a tableview, Upvote 0
Hi Mikel could you show me this sub exportTableViewToCSV This line is actually exporting the tableview to CSV Su.SaveCSV(dirData, "CashFlow.csv", ";",tvMaster.items) And the for the questions: 1. Yes, loadcsv is the best way to load the tableview. 2. Technically no. SortType is meant to be used with a list of Types and not with a list of arrays (what a tableview is) Yet it's easy to convert an array into a type, store the list into a file and load that file into a tableview,
stevel05 Expert Licensed User Longtime User Apr 8, 2017 #7 tvMaster.items is returning a List of Arrays of Objects, Su.SaveCSV requires a List of Arrays of Strings. Upvote 0
tvMaster.items is returning a List of Arrays of Objects, Su.SaveCSV requires a List of Arrays of Strings.
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #8 If that is true then you will need the loop, (how sad) I am very sorry for the false lead Upvote 0
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #9 <Code> Sub exportTableViewToCSV(tv As TableView, filename As String) Dim su As StringUtils Dim l As List l.Initialize For y = 0 To tv.Items.Size - 1 tv.SelectedRow = y Dim Row() As Object = tv.SelectedRowValues Dim NRow(Row.Length) As String For x = 0 To Row.Length - 1 NRow(x) = Row(x) Next l.Add(NRow) Next Try su.SaveCSV(dirData, filename, ";", l) Catch Log(LastException.Message) End Try End Sub </Code> Don't worry about false leads. To me that is just a part of programming. And the older I get the more of them I have LOL I really need some advice on whether to use a list or a tableview as my working object. The app I am working on is a table of 50 to 100 rows of 22 columns with about a third of the columns hidden. A very big part of the processing entails sorting a date column and running a tally on numbers from several columns and putting the result in another column. Some of the data in several columns may need to be changed and those changes have to be saved for the next process. If I have to load, save, and sort based on a list I am thinking that I should just use the list as the base for processing and use the table for display only. I switched to using a list for processing but then switched back because I liked the idea of seeing what I was working on. But I am thinking that was a mistake after figuring out that I have to move table data to a list for sorting and moving it back for viewing. And I have found that displaying a list via tableview is very simple and very quick. At this point I am thinking it best to use a list but I sure would like your thoughts. Upvote 0
<Code> Sub exportTableViewToCSV(tv As TableView, filename As String) Dim su As StringUtils Dim l As List l.Initialize For y = 0 To tv.Items.Size - 1 tv.SelectedRow = y Dim Row() As Object = tv.SelectedRowValues Dim NRow(Row.Length) As String For x = 0 To Row.Length - 1 NRow(x) = Row(x) Next l.Add(NRow) Next Try su.SaveCSV(dirData, filename, ";", l) Catch Log(LastException.Message) End Try End Sub </Code> Don't worry about false leads. To me that is just a part of programming. And the older I get the more of them I have LOL I really need some advice on whether to use a list or a tableview as my working object. The app I am working on is a table of 50 to 100 rows of 22 columns with about a third of the columns hidden. A very big part of the processing entails sorting a date column and running a tally on numbers from several columns and putting the result in another column. Some of the data in several columns may need to be changed and those changes have to be saved for the next process. If I have to load, save, and sort based on a list I am thinking that I should just use the list as the base for processing and use the table for display only. I switched to using a list for processing but then switched back because I liked the idea of seeing what I was working on. But I am thinking that was a mistake after figuring out that I have to move table data to a list for sorting and moving it back for viewing. And I have found that displaying a list via tableview is very simple and very quick. At this point I am thinking it best to use a list but I sure would like your thoughts.
stevel05 Expert Licensed User Longtime User Apr 8, 2017 #10 Where is the data coming from? Are you storing it? It sounds like you may be better using a SQLite database. Using DBUtils, you can display directly from the DB into a tableview and CSV. Upvote 0
Where is the data coming from? Are you storing it? It sounds like you may be better using a SQLite database. Using DBUtils, you can display directly from the DB into a tableview and CSV.
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #11 Ey Mikel! I understand your question, wheter to use a list or to use a tableview, and for me the answer would be to use the best of the 2 worlds. Attached you will find an example of this solution, use the tableview to see the information and use the list to sortTypes. Hope this example is useful to you! Attachments GilesExample.zip GilesExample.zip 23.8 KB · Views: 442 Upvote 0
Ey Mikel! I understand your question, wheter to use a list or to use a tableview, and for me the answer would be to use the best of the 2 worlds. Attached you will find an example of this solution, use the tableview to see the information and use the list to sortTypes. Hope this example is useful to you!
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #12 stevel05 said: Where is the data coming from? Are you storing it? It sounds like you may be better using a SQLite database. Using DBUtils, you can display directly from the DB into a tableview and CSV. Click to expand... I looked at dbUtils but decided against it because it didnt solve the sorting. Almost all of the processing is after the load so I would need to go through a process of saving back to disk and reloading unless there was a way to sort in the tableview. I could have overlooked something though so I will take another look. Thanks again for your help. Upvote 0
stevel05 said: Where is the data coming from? Are you storing it? It sounds like you may be better using a SQLite database. Using DBUtils, you can display directly from the DB into a tableview and CSV. Click to expand... I looked at dbUtils but decided against it because it didnt solve the sorting. Almost all of the processing is after the load so I would need to go through a process of saving back to disk and reloading unless there was a way to sort in the tableview. I could have overlooked something though so I will take another look. Thanks again for your help.
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #13 Mikel, i further improved a bit the code, to solve the issue of loadCSV and saveCSV. I believe that steve05 was correct pointing the issue on the list of Objects and strings, but for my particular test, i could save the the list of tableview Directly. Attached an example Attachments GilesExample.zip GilesExample.zip 27 KB · Views: 444 Upvote 0
Mikel, i further improved a bit the code, to solve the issue of loadCSV and saveCSV. I believe that steve05 was correct pointing the issue on the list of Objects and strings, but for my particular test, i could save the the list of tableview Directly. Attached an example
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #14 Enrique, I am going to try and incorporate the code you sent into my program. I am still pretty new at this so it may take me a little time LOL. One question, can I load the TableView with this or do I have to do it with the Type vars? <Code> Sub RefreshTvMaster For i = 0 To lstMaster.Size - 1 tvMaster.Items.Add(lstMaster.Get(i)) Next End Sub </Code> Upvote 0
Enrique, I am going to try and incorporate the code you sent into my program. I am still pretty new at this so it may take me a little time LOL. One question, can I load the TableView with this or do I have to do it with the Type vars? <Code> Sub RefreshTvMaster For i = 0 To lstMaster.Size - 1 tvMaster.Items.Add(lstMaster.Get(i)) Next End Sub </Code>
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #15 EY mikel, the tags for code are with [] and not with <> Code: Sub RefreshTvMaster For i = 0 To lstMaster.Size - 1 tvMaster.Items.Add(lstMaster.Get(i)) Next End Sub Your code seems right, but it would depend on what are you storing in the lstMaster, if it is an array then its okey, if it is a type then it is better to create first the array, like in the example Code: private Sub loadLOfTypesInTw TableView1.Items.Clear For i = 0 To l.Size -1 Dim twC As twContent = l.Get(i) Dim arr(4) As String arr(0) = twC.id arr(1) = twC.Date arr(2) = twC.rString arr(3) = twC.date2 TableView1.Items.Add(arr) Next End Sub Feel free to ask if you stumble upon something. Upvote 0
EY mikel, the tags for code are with [] and not with <> Code: Sub RefreshTvMaster For i = 0 To lstMaster.Size - 1 tvMaster.Items.Add(lstMaster.Get(i)) Next End Sub Your code seems right, but it would depend on what are you storing in the lstMaster, if it is an array then its okey, if it is a type then it is better to create first the array, like in the example Code: private Sub loadLOfTypesInTw TableView1.Items.Clear For i = 0 To l.Size -1 Dim twC As twContent = l.Get(i) Dim arr(4) As String arr(0) = twC.id arr(1) = twC.Date arr(2) = twC.rString arr(3) = twC.date2 TableView1.Items.Add(arr) Next End Sub Feel free to ask if you stumble upon something.
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #16 The original data is coming from a financial web download so I have no control over how it is formated. The data that I am working with is about 8000 tecords but only a small percent (less than 1000) is what I am using. From that 1000 I create the Master file and about 50/60 detail files. The detail files are simply for history and only to be viewed. Several times a week new data will be processed and added to the files. The Master file is what will get all the processing and that processing includes editing numbers, sorting and tallying results. Kinda like a "what if" scenario. I have it in VB6, msAccess, and SharpGrid using SQL at the moment but the msAccess and SQL is a overkill and the SharpGrid ( high powered grid) has long been discontinued. I am pretty fed up with Microsoft and I want to be able to use B4A and B4i also so I am attempting to learn. I am not very up to date on objects so this is pretty new to me. I come from a DOS background and it was a real learning experience getting into Windows and VB6. I expect hiis to be a learning experience also LOL Upvote 0
The original data is coming from a financial web download so I have no control over how it is formated. The data that I am working with is about 8000 tecords but only a small percent (less than 1000) is what I am using. From that 1000 I create the Master file and about 50/60 detail files. The detail files are simply for history and only to be viewed. Several times a week new data will be processed and added to the files. The Master file is what will get all the processing and that processing includes editing numbers, sorting and tallying results. Kinda like a "what if" scenario. I have it in VB6, msAccess, and SharpGrid using SQL at the moment but the msAccess and SQL is a overkill and the SharpGrid ( high powered grid) has long been discontinued. I am pretty fed up with Microsoft and I want to be able to use B4A and B4i also so I am attempting to learn. I am not very up to date on objects so this is pretty new to me. I come from a DOS background and it was a real learning experience getting into Windows and VB6. I expect hiis to be a learning experience also LOL
EnriqueGonzalez Expert Licensed User Longtime User Apr 8, 2017 #17 Ey Mikel I never really used VB6 (for what i understood, it is not object-oriented?), my experience comes from Macros (excel, VBA) and with less experience Vb.net, i grew on Microsoft, but at the end i finished like you... fed up. For me working in B4J is such a breeze, i barely call it work when i am playing with it. Upvote 0
Ey Mikel I never really used VB6 (for what i understood, it is not object-oriented?), my experience comes from Macros (excel, VBA) and with less experience Vb.net, i grew on Microsoft, but at the end i finished like you... fed up. For me working in B4J is such a breeze, i barely call it work when i am playing with it.
Mikelgiles Active Member Licensed User Longtime User Apr 8, 2017 #18 I am not sure about how much object-orientated VB6 might have had available. I think it may have attempted some but not really sure I never used any of it and managed to write a lot of apps Upvote 0
I am not sure about how much object-orientated VB6 might have had available. I think it may have attempted some but not really sure I never used any of it and managed to write a lot of apps
Mikelgiles Active Member Licensed User Longtime User Apr 9, 2017 #19 After hours of trying I still could not get the sorting to work. It does not actually error until it exits the StartApp sub. The line that is causing the problem is where I use the List.Add(TypeVar). I have included a stripped down version of the program to just show the error. I am just not understanding how to use the List.SortType() command. Weird that it does not error off on the line that is causing the problem. I have documented the source to show where the problem is. I hope someone can let me know what I need to change. Attachments TestCsvLst.zip TestCsvLst.zip 2.7 KB · Views: 434 Upvote 0
After hours of trying I still could not get the sorting to work. It does not actually error until it exits the StartApp sub. The line that is causing the problem is where I use the List.Add(TypeVar). I have included a stripped down version of the program to just show the error. I am just not understanding how to use the List.SortType() command. Weird that it does not error off on the line that is causing the problem. I have documented the source to show where the problem is. I hope someone can let me know what I need to change.
EnriqueGonzalez Expert Licensed User Longtime User Apr 10, 2017 #20 Ey Mikel! The CashFlow.csv is missing! edit: Anyway i was able to find the problem (i hope) find attached the file with the paysort and an extra saveButton Attachments testCsvLst.zip testCsvLst.zip 25.8 KB · Views: 445 Last edited: Apr 10, 2017 Upvote 0
Ey Mikel! The CashFlow.csv is missing! edit: Anyway i was able to find the problem (i hope) find attached the file with the paysort and an extra saveButton