Im trying to write a code, at the moment I have numbers being generated into 6 labels I then have a "save to history" cmd button with the idea that the captions of the labels are added onto a spreadsheet on the form. (either excell, msflexgrid or anyother it doesn't matter)
so I need to;
1. have a spread sheet ideally with 0 rows and 6 colums
2. when the "save to history" button is clicked....
----------- add a new row.
----------- display Lblnumber(1).caption in cell A1,Lblnumber(2).caption in cell b1,ect.
----------- save the sheet.
Idealy the spread sheet will be an object on the form rather than a seperate file.
Ive tried msflexgrid and found it easier to add rows change collum size, ect. but I cannot work out how to get the label captions onto it correctly (i managed to get 1 cell to display 1 label.caption but then couldn't add the others).
I havent got a clue with the excell sheet!
So please Help Im sure this is really easy stuff to anyone used to VB 6.0
To use an Excel sheet means to be restricted to computers which have Excel installed. Excel libraries are not redistributable.
The MSHFlexGrid, however, is. A program using FlexGrid can be installed on any other computer.
The cell's texts of a flexgrid are organized as a matrix in the TextMatrix property.
You must have at least one row to access this property.
Assumed your control is named 'flex' then you can do
Code:
Dim c%, r%
r = TheRowYouWanttoFill
For c=0 To 5 'having 6 columns
flex.TextMatrix(r, c) = LabelNumber(c).Caption
Next
To add a row to the grid you simply increment the .Rows property.
thank you, my idea with the 0 rows was to make it so when "save to history" was clicked it would add a row.
ie.
Private Sub CmdSave_Click()
GridHistory.Rows = GridHistory.Rows + 1
Are the rows/columns named the same as excel (rows=numbers and columns=letters, first cell=A1)
If I add a row each time the button is clicked is that row always added above the previous row ? so it will be row 1,and the previous row 1 will become row 2?
Ok I've answered my last question, No it adds another row below the existing one.
Private Sub saveCmd_Click()
GridHistory.Rows = GridHistory.Rows + 1
Dim col, r
r = 0
For col = 0 To 5
GridHistory.TextMatrix(r, col) = lblNumber(col).Caption
Next
End Sub
(I had to change the C Dim to Col as I already have C defined elsewhere in the code)
So it works fine the first time but then if you click it again it adds another row below the existing info and then re-writes the existing info.
If you add a row, you don't need to re-add the column names.
Code:
Private Sub saveCmd_Click()
GridHistory.Rows = GridHistory.Rows + 1
'Dim col, r
'r = 0
'For col = 0 To 5
'GridHistory.TextMatrix(r, col) = lblNumber(col).Caption
'Next
End Sub
You have not specified another data source except the lblNumber() array.
I supposed the information in that labels would change before you add them to a new row.
Bookmarks