Can anyone teach me how to calculate a mouse click? I need to do a data insertion into MSFlexGrid.

The flow is like this:

1:the data will read a text file and input all the data into column 0
2: when user wants to input again, it will be put into column 1

so....it will be like this

first data insertion

|Column 0|Column 1|Column 2|
|DATA | | |
|DATA | | |
|DATA | | |
|DATA | | |

second click

|Column 0|Column 1|Column 2|
|DATA |DATA | |
|DATA |DATA | |
|DATA |DATA | |
|DATA |DATA | |

third click

|Column 0|Column 1|Column 2|
|DATA |DATA |DATA |
|DATA |DATA |DATA |
|DATA |DATA |DATA |
|DATA |DATA |DATA |

and so on....thank you in advance....your help is much appreciated.....thank you

Dani AI

Generated

For : a simple pattern is to keep a numeric column counter and write the file lines into that column on each button click. Preload the text file once (into an array) so clicks only copy the array into the next grid column. pointed to an external snippet; the example below shows an in-place approach you can adapt.

Option Explicit

Dim nextCol As Long
Dim fileLines() As String
Dim fileCount As Long

Private Sub Form_Load()
    Dim f As Integer, s As String, i As Long
    f = FreeFile
    Open "C:\path\to\file.txt" For Input As #f
    i = 0
    Do While Not EOF(f)
        Line Input #f, s
        ReDim Preserve fileLines(i)
        fileLines(i) = s
        i = i + 1
    Loop
    Close #f
    fileCount = i

    MSFlexGrid1.Rows = fileCount + 1   ' row 0 for header, data start at row 1
    nextCol = 0
End Sub

Private Sub cmdInsert_Click()
    Dim r As Long
    If fileCount = 0 Then Exit Sub

    If MSFlexGrid1.Cols < nextCol + 1 Then MSFlexGrid1.Cols = nextCol + 1

    For r = 1 To fileCount
        MSFlexGrid1.TextMatrix(r, nextCol) = fileLines(r - 1)
    Next r
    MSFlexGrid1.TextMatrix(0, nextCol) = "Column " & nextCol
    nextCol = nextCol + 1
End Sub

Notes and troubleshooting: TextMatrix is 0-based (row 0 often used as header). If files vary in length, set Rows to the maximum expected and write empty strings for missing lines. Persist nextCol with SaveSetting/GetSetting if the app must resume where it left off. Guard against runaway column growth by enforcing a max columns limit. If you really need raw mouse clicks (not button presses), use the grid or form MouseDown event and increment the same counter only for left-button clicks. Use Option Explicit and basic error handling for robustness.

Maybe it doesn't have to be mouse presses. Maybe it could be how many times the command button has been pressed.

Allow me to rephrase my first post.

The user will click the command button to input the data into the MSFlexgrid.
Then the user will click again for the data to be inserted but it will be inserted into the column next to it and the process repeats itself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.