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: - Private Sub cmd_Save_Click()
-
Dim strGameName As String
-
Dim strGenre As String
-
Dim strAge_Rating As String
-
Dim strStock As String
-
Dim strFormat As String
-
Dim strTextout_1 As String
-
Dim strTextout_2 As String
-
Dim strTextout_3 As String
-
Dim srrTextout_4 As String
-
Dim strTextout_5 As String
-
-
With CommonDialog1
-
' Sets the default directory/folder
-
.InitDir = "N:\Unit 29"
-
' Sets the Dialog Title to Open File
-
.DialogTitle = "Please Save File"
-
' Sets the File List box to Word and Excel documents
-
'make sure the following is all on one line
-
.Filter = "CSV (*.CSV)|*.CSV"
-
' Set the default files type to Word Documents
-
.FilterIndex = 1
-
' Sets the flags - File must exist and Hide Read only
-
.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
-
' Set dialog box so an error occurs if the dialog box is cancelled
-
.CancelError = True
-
-
End With
-
-
' Enables error handling to catch cancel error
-
On Error Resume Next
-
' display the dialog box
-
CommonDialog1.ShowSave
-
If Err Then
-
' This code runs if the dialog was cancelled
-
MsgBox "Dialog Cancelled"
-
Exit Sub
-
End If
-
-
Open CommonDialog1.FileName For Output As #1
-
Write #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
-
MsgBox "You selected " & CommonDialog1.FileName
-
strTextout_1 = strGameName
-
strTextout_2 = strGenre
-
strTextout_3 = strAge_Rating
-
srrTextout_4 = strStock
-
strTextout_5 = strFormat
-
-
'Write #1, strTextout_1, strTextout_2, strTextout_3
-
Close #1
-
-
End Sub
and this is what I currently have for loading from CSV file to flexgrid: - Private Sub Form_Load()
-
-
Dim strGameName As String
-
Dim strGenre As String
-
Dim strAge_Rating As String
-
Dim strStock As String
-
Dim strFormat As String
-
-
Open "Game Rent" For Output As #1
-
strTextout_1 = strGameName
-
strTextout_2 = strGenre
-
strTextout_3 = strAge_Rating
-
srrTextout_4 = strStock
-
strTextout_5 = strFormat
-
Write #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
-
Close #1
-
-
'With CommonDialog1
-
' ' Sets the default directory/folder
-
' .InitDir = "C:\"
-
' ' Sets the Dialog Title to Open File
-
' .DialogTitle = "This is my Open File dialog"
-
'
-
' ' Sets the File List box to Word and Excel documents
-
''make sure the following is all on one line
-
' .Filter = "Notepad (*.txt)|*.txt"
-
'
-
' ' Set the default files type to Word Documents
-
' .FilterIndex = 1
-
' ' Sets the flags - File must exist and Hide Read only
-
' .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
-
' ' Set dialog box so an error occurs if the dialog box is cancelled
-
' .CancelError = True
-
'End With
-
'
-
'' Enables error handling to catch cancel error
-
'On Error Resume Next
-
'' display the dialog box
-
'CommonDialog1.ShowOpen
-
'If Err Then
-
' ' This code runs if the dialog was cancelled
-
' MsgBox "Dialog Cancelled"
-
' Exit Sub
-
'End If
-
'' Displays a message box.
-
-
Open "Game Rent" For Input As #1
-
Input #1, strGameName, strGenre, strAge_Rating, str_Stock, strFormat
-
'Print strTextout_1, strTextout_2, strTextout_3, strTextout_4, strTextout_5
-
MSFlexGrid1.TextMatrix(intRowNumber, 0) = strGameName
-
MSFlexGrid1.TextMatrix(intRowNumber, 1) = strGenre
-
MSFlexGrid1.TextMatrix(intRowNumber, 2) = str_Age_Rating
-
MSFlexGrid1.TextMatrix(intRowNumber, 3) = str_Stock
-
MSFlexGrid1.TextMatrix(intRowNumber, 4) = strFormat
-
-
Close #1
-
-
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: - Private Sub saveCSV(ByVal strFilename As String, ByRef msFlex As MSFlexGrid)
-
Const SEPARATOR_CHAR As String = ","
-
-
Dim intFreeFile As Integer
-
Dim strLine As String
-
Dim r As Integer
-
Dim c As Integer
-
-
intFreeFile = FreeFile
-
-
Open strFilename For Output As #intFreeFile
-
-
With msFlex
-
' Every row
-
For r = 0 To .Rows - 1
-
strLine = ""
-
-
' Every column
-
For c = 0 To .Cols - 1
-
strLine = strLine & IIf(c = 0, "", _
-
SEPARATOR_CHAR) & .TextMatrix(r, c)
-
Next c
-
-
Print #intFreeFile, strLine
-
Next r
-
End With
-
-
Close #intFreeFile
-
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.
3 5778
'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
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
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
(...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |