0

Back to vb6 and msflexgrid, there is a weakness in pasting text to this control. If the user wanted for example to paste a 2*3 array in msflexgrid he should select 2 rows and 3 columns to paste the data, otherwise only one cell will fill in the msflexgrid (insted of 6 cells). i found if i colud split clipboard and count its rows and columns this problem should solve (select msflexgrid cells based on the array size) . I created the "editpaste"SUB:

Private Sub EditPaste()
Dim ARRAYLINES As Variant ' array with the lines
Dim ARRAYCELLS As Variant ' array with the cells of 1 line to count the cols needed
Dim ARRAYLINESidx As Integer

   '§ put clipboard in a  textbox named "cliper"
   With cliper
      .Text = Clipboard.GetText
      If .Text = "" Then
         Exit Sub
      Else
         ARRAYLINES = Split(.Text, Chr(13)) 'i also used the Chr(10) vbnewline  andvbCRLF to count the lines
      End If
   End With
   '§ put textbox in grid
   If ARRAYLINES(0) = "" Then

      Exit Sub
   Else
      ARRAYCELLS = Split(ARRAYLINES(0), vbTab) 'to count the columns
  msgbox UBound(ARRAYLINES) & UBound(ARRAYCELLS)
   End If
   '§ clear array
   ReDim ARRAYLINES(0)
   ReDim ARRAYCELLS(0)

End Sub

But my problem is that i have two types of text arrays (text matrixs). the array that came from msflixgrid to clipboard and the array that came from excell to clipboard and i can not make differencess between them in that sub. bellow is a screenshot from them into MSword:

enter image description here

The arrows n that picture are the TAb Characters i have no problem in counting them and the results are equal for all text arrays. but the paragraph signs are tricky and i knew in the second array they are "vbnewline" but in first array my code can not find them and suppose like i have only one line. Do you know a better way to get equal result in counting these columns and rows?

4

1 に答える 1

1

次のコードを使用して、クリップボード データを表示しました。

'1 form with
'  1 msflexgrid control
'  1 textbox control
'  2 command buttons

Option Explicit

Private Sub Command1_Click()
  Dim strText As String
  strText = Clipboard.GetText
  ShowAscii strText
End Sub

Private Sub Command2_Click()
  Clipboard.SetText MSFlexGrid1.Clip
End Sub

Private Sub Form_Load()
  Dim intRow As Integer, intCol As Integer
  With MSFlexGrid1
    For intRow = 0 To .Rows - 1
      For intCol = 0 To .Cols - 1
        .TextMatrix(intRow, intCol) = CStr(100 * intRow + intCol)
      Next intCol
    Next intRow
  End With 'MSFlexGrid1
End Sub

Private Sub ShowAscii(strText As String)
  Dim intChar As Integer
  Dim strShow As String
  strShow = ""
  For intChar = 1 To Len(strText)
    strShow = strShow & Right$("00" & Hex$(Asc(Mid$(strText, intChar, 1))), 2) & " "
  Next intChar
  Text1.Text = strShow
End Sub

200、201、300、301 を含むセルを選択し、command2 をクリックしてから command1 をクリックすると、テキスト ボックスに次のように表示されます。

32 30 30 09 32 30 31 0D 33 30 30 09 33 30 31 

同じデータをExcelに入れてコピーし、command1をクリックすると、テキストボックスに次のように表示されます。

32 30 30 09 32 30 31 0D 0A 33 30 30 09 33 30 31 0D 0A 

これら 2 つの違いは、Excel では vbCrLF を使用して行を区切ったのに対し、MSFlexGrid では vbCr のみを使用したことです。

処理する前にクリップボード データからすべての vbLF を削除しても問題ないと思います。

strText = Replace(strText, vbLf, "")

その後、両方の入力メソッドは行区切りとして vbCR のみを使用します

于 2013-03-12T10:01:08.133 に答える