Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: mariana_87 en 23 Mayo 2009, 15:53 pm



Título: ayuda con textbox
Publicado por: mariana_87 en 23 Mayo 2009, 15:53 pm
hola como estan? resulta que yo tengo un textbox multiline con varias lineas y las lineas siempre son diferentes cantidades y dicen distintas cosas

linea 1
linea 2
linea 3
linea 4

entonces yo quiero obtener la linea que dice linea 3 y pasarla a otro textbox alguien sabria? gracias


Título: Re: ayuda con textbox
Publicado por: cassiani en 23 Mayo 2009, 17:15 pm
Usas la función split

Citar
Private Sub Command1_Click()
Dim sArray() As String
    sArray = Split(Text1.Text, vbCrLf)
    MsgBox sArray(2)
End Sub


Título: Re: ayuda con textbox
Publicado por: xkiz ™ en 23 Mayo 2009, 23:42 pm
Código
  1. 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
  2. Private Const EM_GETLINE As Long = &HC4
  3. Private Const EM_LINELENGTH As Long = &HC1
  4.  
  5. Function GetLineText(TextBox As TextBox, Optional LineNumer As Long = 1) As String
  6. Dim lc As Long, Ret As Long, Str As String
  7. lc = SendMessage(TextBox.hwnd, EM_GETLINECOUNT, 0&, 0&)
  8.    Ret = SendMessage(TextBox.hwnd, EM_LINELENGTH, (LineNumer - 1), 0&)
  9.    Str = Space(Ret)
  10.  
  11.    SendMessage TextBox.hwnd, EM_GETLINE, (LineNumer - 1), Str
  12.    GetLineText = Str
  13. End Function
  14.  
  15. Private Sub Command1_Click()
  16. MsgBox GetLineText(Text1, 3)
  17. End Sub