Excel sheets or MsflexGrid
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Excel sheets or MsflexGrid

  1. #1
    Join Date
    Jul 2010
    Posts
    3

    Excel sheets or MsflexGrid

    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

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Excel sheets or MsflexGrid

    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.

  3. #3
    Join Date
    Jul 2010
    Posts
    3

    Re: Excel sheets or MsflexGrid

    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?

  4. #4
    Join Date
    Jul 2010
    Posts
    3

    Re: Excel sheets or MsflexGrid

    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.

    Any ideas how I can get around this

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,958

    Re: Excel sheets or MsflexGrid

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Excel sheets or MsflexGrid

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center