Results 1 to 7 of 7

Thread: Grid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    I was able to retrieve data into Grid1 on form1. However, the data is displayed in one column, whereas, where there are spaces should be indicate a new column. Any ideas how to separate data and put them in columns on the Grid. A sample of many lines of data is below. Where there are commas, I managed to make them spaces. Thanks!

    LFDIV,FY_PREMIUM.STAT_INP,924205,2475381,4092521,5810393

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Try this:
    Code:
        Dim sData As String
        Dim nPos As Integer
        Const COL_WIDTH = 700
        
        sData = "LFDIV,FY_PREMIUM.STAT_INP,924205,2475381,4092521,5810393"
        
        Grid1.Cols = 1
        nPos = 999
        Do Until nPos = 0
            nPos = InStr(1, sData, ",")
            If nPos > 0 Then
                Grid1.Col = Grid1.Cols - 1
                Grid1.Text = Left$(sData, nPos - 1)
                Grid1.ColWidth(Grid1.Col) = COL_WIDTH
                Grid1.Width = Grid1.Width + COL_WIDTH
                Grid1.Cols = Grid1.Cols + 1
                sData = Right$(sData, Len(sData) - nPos)
            Else
                Grid1.Col = Grid1.Cols - 1
                Grid1.Text = sData
                Grid1.ColWidth(Grid1.Col) = COL_WIDTH
            End If
        Loop
    If your data has a fixed number of values in each line (6 in your example), then a lot of the above can be eliminated. You could also just as well look for spaces instead of commas.

    ------------------
    Marty
    COGITO EGGO SUM
    I think; therefore I am a waffle.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    Thanks Martin! Almost there, but not quite. I made a couple of minor changes to code. The grid looks okay with the data. However, only one line is being displayed. The string sdata = szname because szname returns the multiple lines of data from the source, which is okay if the other lines populate the grid. Also, the numbers are flushed to the left of the column. I think my problem centers around the fact that I was able to use the .additem property w/the listbox versus using the .text property with the Grid. If change text to additem the Grid will list everything going down in column 1. Any suggestions. Thanks again!

    Dim sData As String
    Dim nPos As Integer
    Const COL_WIDTH = 1200

    sData = sztemp

    Form1.Grid1.Cols = 1
    nPos = 999
    Do Until nPos = 0
    nPos = InStr(1, sData, " ")
    If nPos > 0 Then
    Form1.Grid1.Col = Form1.Grid1.Cols - 1
    Form1.Grid1.Text = Left$(sData, nPos - 1)
    Form1.Grid1.ColWidth(Form1.Grid1.Col) = COL_WIDTH
    Form1.Grid1.Width = Form1.Grid1.Width + COL_WIDTH
    Form1.Grid1.Cols = Form1.Grid1.Cols + 1
    sData = Right$(sData, Len(sData) - nPos)
    Else
    Form1.Grid1.Col = Form1.Grid1.Cols - 1
    Form1.Grid1.Text = sData
    Form1.Grid1.ColWidth(Form1.Grid1.Col) = COL_WIDTH
    End If
    Loop

    [This message has been edited by Hutty (edited 01-28-2000).]

    [This message has been edited by Hutty (edited 01-28-2000).]

    [This message has been edited by Hutty (edited 01-28-2000).]

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Each time you want to start a new row, first set the Grid.Col back to 0 and then add 1 to Grid1.Rows (which is the total number of rows in the grid) and add 1 to Grid1.Row (which is the current row).

    ------------------
    Marty
    COGITO EGGO SUM
    I think; therefore I am a waffle.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    I modified the application to include the grid1.rows property. I'm not sure whether it's inserted in the right spot or correct. Below is the current code. When running the app the grid displays the columns result in a step fashion on separate rows.
    FY_Premium
    11111111
    22222222
    3333333
    In addition, the grid values equals the last row in the query. "Additem" returns everything, except in a vertical format. Any ideas where I'm going wrong?

    sData = sztemp

    Form1.Grid1.Cols = 1
    nPos = 999
    Do Until nPos = 0
    nPos = InStr(1, sData, " ")
    If nPos > 0 Then
    Form1.Grid1.Col = Form1.Grid1.Cols - 1
    Form1.Grid1.Text = Left$(sData, nPos - 1)
    Form1.Grid1.ColWidth(Form1.Grid1.Col) = COL_WIDTH
    Form1.Grid1.Width = Form1.Grid1.Width + COL_WIDTH
    Form1.Grid1.Cols = Form1.Grid1.Cols + 1
    sData = Right$(sData, Len(sData) - nPos)
    Else
    Form1.Grid1.Col = Form1.Grid1.Cols - 1
    Form1.Grid1.Text = sData
    Form1.Grid1.ColWidth(Form1.Grid1.Col) = COL_WIDTH
    End If
    Form1.Grid1.Col = 0
    Form1.Grid1.Rows = Form1.Grid1.Row + 1
    Loop



    Form1.List1.AddItem sztemp

    ------------------


    [This message has been edited by Hutty (edited 01-31-2000).]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    The numbers 1111111,2222222,3333333 are not displayed as above. They are in separate columns and separate rows.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    Is there a book or tutorial on Microsoft Grid? I tried going to the apexsc website. Support couldn't help me the current problem.

Posting Permissions

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



Click Here to Expand Forum to Full Width