Originariamente inviato da seifter
ma quando arriva a contare 1000 si blocca tutto
Prova così:
codice:
Private Sub Numera()
Const EM_LINEFROMCHAR = &HC9
Const EM_GETLINECOUNT = &HBA
Const EM_LINELENGTH = &HC1
Dim LineeTotali As Long
Dim LunghezzaLinea As Long
'-
Const Mlt = 100
Const Formato = "0000#"
Dim Cont1 As Long
Dim Cont2 As Long
Dim Str1 As String
Static LineeTotaliP As Long
Dim Start As Long
'-
Start = Text1.SelStart
For Cont1 = 1 To LineeTotaliP
Str1 = "N" & CStr(Format((Cont1 * Mlt), Formato)) & " "
Text1.Text = Replace(Text1.Text, Str1, "")
Next Cont1
LineeTotali = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
For Cont1 = 1 To LineeTotali
Str1 = "N" & CStr(Format((Cont1 * Mlt), Formato)) & " "
Text1.Text = Mid(Text1.Text, 1, Cont2) & Str1 & Mid(Text1.Text, Cont2 + 1)
LunghezzaLinea = SendMessage(Text1.hwnd, EM_LINELENGTH, Cont2, 0&)
Cont2 = Cont2 + LunghezzaLinea + 2 'CrLf
Next Cont1
Cont2 = Cont2 - 2 'Ultimo CrLf
LineeTotaliP = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
LunghezzaLinea = SendMessage(Text1.hwnd, EM_LINELENGTH, Cont2, 0&)
Text1.SelStart = Start + LunghezzaLinea
End Sub
La numerazione viene mantenuta di lunghezza fissa:
codice:
10 --> 00010
200 --> 00200
Se invece non vuoi questo "tipo" di numerazione, ti basta cancellare l'uso della Format.
Anche così però, qualche problema credo rimanga ugualmente.
Per il secondo problema, prova così:
codice:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As _
Integer, ByVal lParam As Any) As Long
Private Sub Command1_Click()
Const WM_PASTE = &H302
Clipboard.SetText (Text1.Text) 'Valore da copiare
SendMessage Text2.hwnd, WM_PASTE, 0&, 0& 'TextBox
SendMessage RT.hwnd, WM_PASTE, 0&, 0& 'RichTextBox
End Sub