Results 1 to 7 of 7

Thread: [RESOLVED] Help! I can not copy the content of Text1.Text

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Resolved [RESOLVED] Help! I can not copy the content of Text1.Text

    Dear experts,
    I got the souce code below from the the forum & it work for me but I can not copy the content/outcome of Text1.Text I want....or canthe code produce the content/outcome of Text1.Text to text1.txt?
    Appreciate your help...Thank You


    Option Explicit
    Const LB_FINDSTRING = &H18F
    Const LB_FINDSTRINGEXACT = &H1A2

    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
    Dim wow() As String

    Private Sub Command1_Click()
    AddToListBox Text1.Text
    End Sub

    Private Sub Command2_Click()
    Dim i As Integer
    wow() = Split(Text1.Text, vbCrLf)
    For i = LBound(wow) To UBound(wow)
    AddToListBox wow(i)
    Next i

    End Sub

    Public Sub AddToListBox(AddMe As String)
    Dim wow As Long
    wow = SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, 0, ByVal AddMe)
    If wow = -1 Then
    List1.AddItem AddMe
    Else
    List1.ListIndex = wow
    Debug.Print List1.Text
    End If

    End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Help! I can not copy the content of Text1.Text

    No need to use API to export text from textbox. use this simle code...

    vb Code:
    1. Dim outputstring as string
    2. outputstring = Text1.Text
    3. Open "C:/MyTextFile.txt" For Output As #1
    4. Print #1, outputstring
    5. Close #1
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Help! I can not copy the content of Text1.Text

    pls ensure to INDENT the codes and post them with CODE tags
    Code:
    Option Explicit
    Const LB_FINDSTRING = &H18F
    Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Declare Function SendMessage Lib "user32" _
                  Alias "SendMessageA" _
                  (ByVal hWnd As Long, _
                  ByVal wMsg As Long, _
                  ByVal wParam As Long, _
                  lParam As Any) As Long
    Dim wow() As String
    
    
    Private Sub Command1_Click()
      AddToListBox Text1.Text
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
      wow() = Split(Text1.Text, vbCrLf)
      For i = LBound(wow) To UBound(wow)
        AddToListBox wow(i)
      Next i
    End Sub
    
    Public Sub AddToListBox(AddMe As String)
    Dim wow As Long
      wow = SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, 0, ByVal AddMe)
      If wow = -1 Then
        List1.AddItem AddMe
      Else
        List1.ListIndex = wow
        Debug.Print List1.Text
      End If
    End Sub
    what's not working.
    what are you trying to do?

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Help! I can not copy the content of Text1.Text

    Quote Originally Posted by koolsid
    No need to use API to export text from textbox. use this simle code...

    vb Code:
    1. Dim outputstring as string
    2. outputstring = Text1.Text
    3. Open "C:/MyTextFile.txt" For Output As #1
    4. Print #1, outputstring
    5. Close #1

    thank you koolsid, it work
    but I think I have posted the wrong output file
    what I need in fact is the output List1 file not the text1.tex
    can u guide me ? Thank You!

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Help! I can not copy the content of Text1.Text

    Quote Originally Posted by VBFnewcomer
    pls ensure to INDENT the codes and post them with CODE tags
    Code:
    Option Explicit
    Const LB_FINDSTRING = &H18F
    Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Declare Function SendMessage Lib "user32" _
                  Alias "SendMessageA" _
                  (ByVal hWnd As Long, _
                  ByVal wMsg As Long, _
                  ByVal wParam As Long, _
                  lParam As Any) As Long
    Dim wow() As String
    
    
    Private Sub Command1_Click()
      AddToListBox Text1.Text
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
      wow() = Split(Text1.Text, vbCrLf)
      For i = LBound(wow) To UBound(wow)
        AddToListBox wow(i)
      Next i
    End Sub
    
    Public Sub AddToListBox(AddMe As String)
    Dim wow As Long
      wow = SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, 0, ByVal AddMe)
      If wow = -1 Then
        List1.AddItem AddMe
      Else
        List1.ListIndex = wow
        Debug.Print List1.Text
      End If
    End Sub
    what's not working.
    what are you trying to do?
    Dear, VBFnewcomer,

    Can u help?

    Code:
    Option Explicit
    Const LB_FINDSTRING = &H18F
    Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Declare Function SendMessage Lib "user32" _
            Alias "SendMessageA" _
            (ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            lParam As Any) As Long
    Dim wow() As String
    
    Private Sub Command1_Click()
        AddToListBox Text1.Text
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
        wow() = Split(Text1.Text, vbCrLf)
        For i = LBound(wow) To UBound(wow)
            AddToListBox wow(i)
        Next i
    
    End Sub
    
    Public Sub AddToListBox(AddMe As String)
        Dim wow As Long
        wow = SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, 0, ByVal AddMe)
        If wow = -1 Then
            List1.AddItem AddMe
        Else
            List1.ListIndex = wow
            Debug.Print List1.Text
        End If
            
        Dim outputstring As String
        outputstring = List1.Text
        Open "C:/MyTextFile.txt" For Output As #1
        Print #1, outputstring
        Close #1
    
    End Sub
    I need the output txt file in the List1 Listbox but the above code can not work

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Help! I can not copy the content of Text1.Text

    finally, it works....thank you!

    Code:
    Option Explicit
    Const LB_FINDSTRING = &H18F
    Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Declare Function SendMessage Lib "user32" _
            Alias "SendMessageA" _
            (ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            lParam As Any) As Long
    Dim wow() As String
    
    Private Sub Command1_Click()
        AddToListBox Text1.Text
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
        wow() = Split(Text1.Text, vbCrLf)
        For i = LBound(wow) To UBound(wow)
            AddToListBox wow(i)
        Next i
    
    End Sub
    
    Public Sub AddToListBox(AddMe As String)
        Dim wow As Long
        wow = SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, 0, ByVal AddMe)
        If wow = -1 Then
            List1.AddItem AddMe
        Else
            List1.ListIndex = wow
            Debug.Print List1.Text
        End If
            
          End Sub
       
     Private Sub Command3_Click()
     
    
    Dim N As Integer
    
    Open "C:\List.txt" For Output As #1
    For N = 0 To List1.ListCount - 1
        Print #1, List1.List(N)
    Next
    Close #1
    
    
     End Sub

  7. #7
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: [RESOLVED] Help! I can not copy the content of Text1.Text

    glad you have solved it yourself
    by the way donot use #1.
    instead use
    Code:
    Dim iFreeFile As Integer
      iFreeFile = FreeFile
    reason you never know which file is free

    IMP:also have some error handler when you open & close files.

    pls mark the thread as resolved if your problem is solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width