472,368 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

getting data from CSV file into a Flexgrid

I'm trying to make an application that will allow the user to enter data into a flexgrid (that's done) and then save the data from that flexgrid into a CSV file but even though the file is made none of the data from the flexgrid goes into the CSV file and so I have a couple of questions.

1, How do I make the application load the data from a specific CSV file?
2, How do I make it so that the user is able to add information to the data and then save that information and overwrite the current CSV file?
3, How do I make it so that I can delete data from the flexgrid and make all the information below move up (so there is no space where the information used to be)?

This is the code I currently have for saving the data from the flexgrid into a CSV file:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_Save_Click()
  2. Dim strGameName As String
  3. Dim strGenre As String
  4. Dim strAge_Rating As String
  5. Dim strStock As String
  6. Dim strFormat As String
  7. Dim strTextout_1 As String
  8. Dim strTextout_2 As String
  9. Dim strTextout_3 As String
  10. Dim srrTextout_4 As String
  11. Dim strTextout_5 As String
  12.  
  13. With CommonDialog1
  14.     ' Sets the default directory/folder
  15.   .InitDir = "N:\Unit 29"
  16.     ' Sets the Dialog Title to Open File
  17.     .DialogTitle = "Please Save File"
  18.         ' Sets the File List box to Word and Excel documents
  19. 'make sure the following is all on one line
  20.     .Filter = "CSV (*.CSV)|*.CSV"
  21.             ' Set the default files type to Word Documents
  22.     .FilterIndex = 1
  23.         ' Sets the flags - File must exist and Hide Read only
  24.     .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  25.       ' Set dialog box so an error occurs if the dialog box is cancelled
  26.     .CancelError = True
  27.  
  28. End With
  29.  
  30. ' Enables error handling to catch cancel error
  31. On Error Resume Next
  32. ' display the dialog box
  33. CommonDialog1.ShowSave
  34. If Err Then
  35.     ' This code runs if the dialog was cancelled
  36.     MsgBox "Dialog Cancelled"
  37.     Exit Sub
  38. End If
  39.  
  40. Open CommonDialog1.FileName For Output As #1
  41. Write #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
  42. MsgBox "You selected " & CommonDialog1.FileName
  43. strTextout_1 = strGameName
  44. strTextout_2 = strGenre
  45. strTextout_3 = strAge_Rating
  46. srrTextout_4 = strStock
  47. strTextout_5 = strFormat
  48.  
  49. 'Write #1, strTextout_1, strTextout_2, strTextout_3
  50. Close #1
  51.  
  52. End Sub
and this is what I currently have for loading from CSV file to flexgrid:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim strGameName As String
  4. Dim strGenre As String
  5. Dim strAge_Rating As String
  6. Dim strStock As String
  7. Dim strFormat As String
  8.  
  9. Open "Game Rent" For Output As #1
  10. strTextout_1 = strGameName
  11. strTextout_2 = strGenre
  12. strTextout_3 = strAge_Rating
  13. srrTextout_4 = strStock
  14. strTextout_5 = strFormat
  15. Write #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
  16. Close #1
  17.  
  18. 'With CommonDialog1
  19. '    ' Sets the default directory/folder
  20. ' .InitDir = "C:\"
  21. '    ' Sets the Dialog Title to Open File
  22. '    .DialogTitle = "This is my Open File dialog"
  23. '
  24. '    ' Sets the File List box to Word and Excel documents
  25. ''make sure the following is all on one line
  26. '    .Filter = "Notepad (*.txt)|*.txt"
  27. '
  28. '        ' Set the default files type to Word Documents
  29. '    .FilterIndex = 1
  30. '        ' Sets the flags - File must exist and Hide Read only
  31. '    .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  32. '      ' Set dialog box so an error occurs if the dialog box is cancelled
  33. '    .CancelError = True
  34. 'End With
  35. '
  36. '' Enables error handling to catch cancel error
  37. 'On Error Resume Next
  38. '' display the dialog box
  39. 'CommonDialog1.ShowOpen
  40. 'If Err Then
  41. '    ' This code runs if the dialog was cancelled
  42. '    MsgBox "Dialog Cancelled"
  43. '    Exit Sub
  44. 'End If
  45. '' Displays a message box.
  46.  
  47. Open "Game Rent" For Input As #1
  48. Input #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
  49. 'Print strTextout_1, strTextout_2, strTextout_3, strTextout_4, strTextout_5
  50. MSFlexGrid1.TextMatrix(intRowNumber, 0) = strGameName
  51. MSFlexGrid1.TextMatrix(intRowNumber, 1) = strGenre
  52. MSFlexGrid1.TextMatrix(intRowNumber, 2) = str_Age_Rating
  53. MSFlexGrid1.TextMatrix(intRowNumber, 3) = str_Stock
  54. MSFlexGrid1.TextMatrix(intRowNumber, 4) = strFormat
  55.  
  56. Close #1
  57.  
  58. End Sub
Both sets of code have commented out sections as I was trying to find out why it wouldn't work.

I found the following code but I'm not sure how it works as I don't know where to put : SaveCSV("N:\Unit 29\Assignment 1", MSFlexGrid1) <------the file name of the CSV file the code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub saveCSV(ByVal strFilename As String, ByRef msFlex As MSFlexGrid)
  2.     Const SEPARATOR_CHAR As String = ","
  3.  
  4.     Dim intFreeFile As Integer
  5.     Dim strLine As String
  6.     Dim r As Integer
  7.     Dim c As Integer
  8.  
  9.     intFreeFile = FreeFile
  10.  
  11.     Open strFilename For Output As #intFreeFile
  12.  
  13.     With msFlex
  14.         ' Every row
  15.         For r = 0 To .Rows - 1
  16.             strLine = ""
  17.  
  18.             ' Every column
  19.             For c = 0 To .Cols - 1
  20.                 strLine = strLine & IIf(c = 0, "", _
  21.                     SEPARATOR_CHAR) & .TextMatrix(r, c)
  22.             Next c
  23.  
  24.             Print #intFreeFile, strLine
  25.         Next r
  26.     End With
  27.  
  28.     Close #intFreeFile
  29. End Sub
Any help towards making the CSV data to be loaded into the Flexgrid or saving the data from the flexgrid to the CSV file would be very grateful.
Feb 13 '08 #1
3 5557
Bum
19
'herer's an example of getting the data from a csv and putting in a flexgrid:
'keep in mind this was mad for MY csv file, you must customize it for yours.

Public Sub Initial_Read_CSV()
Dim strMiddleInitial, strLastName, objUser
Combo1.Clear
On Error GoTo errhandler 'Resume Next

strExcelPath = "\Review.csv"'put your path here


' Iterate through the rows of the spreadsheet after the first, until the
' first blank entry in the first column. For each row, bind to the user
' specified in the first column and set attributes.

FG.Clear
FG.FormatString = " |<Item No |<Officer |<Issue |<Suspense |<Notes |<Status|" '<Category |"

Dim intcount
intcount = 0

'reset flexgrid
FG.Cols = 7
FG.Rows = 1


'cycle through the appropriate sheets
Combo1.AddItem "TOGETHER"
ReDim AllMatrix(7, 100000)

intRow = 2

Open strExcelPath For Input As #1

''remove headings
Input #1, stritemno
Input #1, strofficer '= objSheet.Cells(intRow, 2).Value
Input #1, strIssue '= objSheet.Cells(intRow, 3).Value
Input #1, strSuspense '= objSheet.Cells(intRow, 4).Value
Input #1, strStatus '= objSheet.Cells(intRow, 5).Value
Input #1, strOCT '= objSheet.Cells(intRow, 6).Value

Do Until EOF(1)
Input #1, stritemno
Input #1, strofficer '= objSheet.Cells(intRow, 2).Value
Input #1, strIssue '= objSheet.Cells(intRow, 3).Value
Input #1, strSuspense '= objSheet.Cells(intRow, 4).Value
Input #1, strStatus '= objSheet.Cells(intRow, 5).Value
Input #1, strOCT '= objSheet.Cells(intRow, 6).Value
strsheet = "ALL"
'Input #1, tstr

intcount = intcount + 1
AllMatrix(1, intcount) = stritemno
AllMatrix(2, intcount) = strofficer
AllMatrix(3, intcount) = strIssue
AllMatrix(4, intcount) = strSuspense
AllMatrix(5, intcount) = strStatus
AllMatrix(6, intcount) = strsheet
AllMatrix(7, intcount) = strOCT

''have to add the space so vb doesn't treat it like a number for the sorting
FG.AddItem " " & intcount & vbTab & stritemno & vbTab & strofficer & vbTab & strIssue & vbTab & strSuspense & vbTab & strStatus & vbTab & strOCT
intRow = intRow + 1

''now let's see if we need to add somehting to the combo
j = 0
i = InStr(j + 1, strofficer, "/")
If i = 0 Then
tstr = strofficer
GoTo 11:
End If

i = 1
mthano = 0
Do Until i = 0
k = 0
j = i
i = InStr(j + 1, strofficer, "/")
mthano = mthano + 1
If mthano > 1 Then k = 1
If i <> 0 Then tstr = Mid(strofficer, j + k, i - j - k)
If i = 0 Then tstr = Mid(strofficer, j + k, Len(strofficer) - j)

'''check to see if our tstr is in our combo list
11:
For ccount = 1 To Combo1.ListCount - 1
If UCase(Trim(tstr)) = UCase(Trim(Combo1.List(ccount))) Then
GoTo 54
End If
Next
Combo1.AddItem UCase(Trim(tstr))
54:
Loop
Loop

Close (1)


ReDim Preserve AllMatrix(7, intcount)
MatCount = intcount
CurFlexCount = MatCount
Combo1.ListIndex = 0
Exit Sub

errhandler:
Close (1)
MsgBox ("Problem, tell Brad")

End Sub
Feb 14 '08 #2
Bum
19
I also have code to put a textbox in front of the grid being used and then it replaces the data. If you post your email, I will email you the whole project.

Hope it helps,

B
Feb 14 '08 #3
Killer42
8,435 Expert 8TB
I also have code to put a textbox in front of the grid being used and then it replaces the data. If you post your email, I will email you the whole project.
If you want to exchange e-mail addresses, do it via Private Message. The site Posting Guidelines prohibit posting your e-mail address in the forum. This is to protect you from scammers and spammers.

If anyone is interested, I am working on a VB function which will accept a line of CSV formatted data and return the fields as a string array. Not quite finished, but should be working in a few days. (Not that there's much to it, I just don't have time to work on it right now).
Feb 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Deva | last post by:
Hello All, Is it possible to export data directly from MSH Flexgrid to MS Excel? There is some problem in exporting data from HFlex grid populated with Hierarchical recordset.This recordset is...
7
by: tombsy | last post by:
Hi gang... I want to have a form that can display data from a datasource that is not fixed. lets say a crosstab query that can change the number of colums and field headings depending on the...
4
by: VR | last post by:
I am trying to embed a check box into a FlexGrid's cell, but having a problem when I start scrolling the grid. Here is my MyCheckBox class... class MyCheckBox : CheckBox { void Init (...
0
by: ali mootab | last post by:
Hi all, In my database project I use the 'Data' & 'Microsoft FlexGrid Control 6.0' objects to link to my database file. In installation time I place the 'MSFLXGRD.OCX' in application and in...
5
by: schapopa | last post by:
I have a flex grid and I am loading data to this flex grid in this way While sqldr.Read j = j + 1 MSFlexGrid1PLSummary.set_TextMatrix(MSFlexGrid1PLSummary.Row, MSFlexGrid1PLSummary.Col,...
0
by: alexh1000 | last post by:
When I insert the FlexGrid control in a dialog (using controls toolbar) the dialog fails to open on program execution(DoModal returns a -1). If I remove the FlexGrid from the dialog, the dialog...
1
by: Bails | last post by:
Hi, apologies first up - im a newby and am teaching myself. I need to take data from a flexgrid and display it on a label (on another form). so I have 2 questions 1) how do I get the data off...
5
by: brendanmcdonagh | last post by:
Hi, I have today completed my first ever program for a friend which displays total hours worked for each day then adds them up. Now I want to transfer this data to store in access. I did do a...
3
by: sweevil | last post by:
I'm converting a VB6 project to .Net2005. One of the items encountered was setting the cellpicture onto a flexgrid from an imagelist. The image background doesn't appear to render correctly. I...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.