Q: Need a little help;
Suppose I copy a data from the excel to the clipboard, which is as
follows:
Allen 12
Anderson 13
Douglas 12
Ohio 49
How can I read the county name and the data in an array or in a grid box?
the Clipboard.GetText(vbCFText) reads the whole data, i want to read one
by one.
Tarik tarik@falcon.cc.ukans.edu
A:
Hello Tarik what about the next solution?
It's just to give you an idea how to work. In the command_click code
is also the code to put the data into an array. BUT the data MUST be
separated by a space. In the function GetPartofString you search for
a space as a seperator. So if that's not the case then you have to
change the code to search for (space = chr(32))
Make a new project with a form, two labels and a command button
Private Sub Command1_Click()
Dim vTekst$
vTekst$ = "Allen 12 "
vTekst$ = vTekst$ & "Anderson 13 "
vTekst$ = vTekst$ & "Bernard 14 "
vTekst$ = vTekst$ & "Constance 15 "
Label1.Caption = vTekst$
Select Case Command1.Caption
Case "Copy Clipboard"
Clipboard.Clear
Clipboard.SetText Label1.Caption
Command1.Caption = "Put into Label"
Case "Put into Label"
Label2.Caption = GetPartofString(Clipboard.GetText, 1)
Command1.Caption = "Copy Clipboard"
End Select
Exit Sub
'read in array
Dim vText(7) As String
Dim c%
For c% = 0 To 7
vText(c%) = GetPartofString(Clipboard.GetText, c% + 1)
Next c%
'show result
For c% = 0 To 7
MsgBox vText(c%)
Next c%
End Sub
Private Function GetPartofString(source$, part%) As String
Dim p%, c%, tmp$
tmp$ = source$
c% = 0
Do
p% = InStr(tmp, Chr(32))
If p% <> 0 Then
GetPartofString = Left(tmp, p% - 1)
c% = c% + 1
tmp = Right(tmp, Len(tmp) - p%)
End If
Loop While c% <> part%
End Function
Return