Results 1 to 9 of 9

Thread: drag drop to list , re question / help

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    drag drop to list , re question / help

    seen other example most staff shown before , how ever i have a text file with these strings inside

    james
    billy
    tony
    montana


    i want to drag txt file to list and then have it populated is it possible.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: drag drop to list , re question / help

    Quote Originally Posted by ladoo View Post
    i want to drag txt file to list and then have it populated is it possible.
    The codes posted in your previous thread can do just that. You only have to modify them a bit.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: drag drop to list , re question / help

    can u help dear

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: drag drop to list , re question / help

    Just modify the code Bonnie gave you in the other thread so it includes

    vb Code:
    1. Dim FF As Integer
    2. Public Sub Drag_n_Drop(ByVal hDrop As Long)
    3.     Dim i As Long, sngLongestText As Single, TW As Single, sBuffer As String, text As String
    4.  
    5.     With List1
    6.         i = DragQueryFileW(hDrop, &HFFFFFFFF)
    7.  
    8.         If i Then
    9.            .Visible = False
    10.            .Clear
    11.  
    12.             For i = 0& To i - 1&
    13.                 SysReAllocStringLen VarPtr(sBuffer), , DragQueryFileW(hDrop, i)
    14.                 DragQueryFileW hDrop, i, StrPtr(sBuffer), Len(sBuffer) + 1&
    15.                 Open sBuffer For Input As #FF
    16.                 Input #FF, sBuffer
    17.                .AddItem sBuffer
    18.                 Close #FF
    19.                 TW = TextWidth(sBuffer)
    20.                 If sngLongestText < TW Then sngLongestText = TW
    21.             Next
    22.  
    23.            .Visible = True
    24.             SendMessageW .hWnd, LB_SETHORIZONTALEXTENT, RIGHT_MARGIN + sngLongestText, 0&
    25.         End If
    26.  
    27.         DragFinish hDrop
    28.     End With
    29. End Sub
    30. Private Sub Form_Load()
    31.     FF = FreeFile
    32.     ScaleMode = vbPixels
    33.     DragAcceptFiles hWnd, 1& 'fAccept:=TRUE
    34.     Subclass Me
    35. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: drag drop to list , re question / help

    @ Nightwalker

    I think ladoo wants to list all the contents of a single dragged text file. If so, then the following are the modifications required:

    Code:
    Public Sub Drag_n_Drop(ByVal hDrop As Long)
        Const RIGHT_MARGIN = 5& 'Right margin for List1's longest item (in pixels)
        Dim FN As Integer, sngLongestText As Single, TW As Single, sText As String
    
        With List1
            If DragQueryFileW(hDrop, &HFFFFFFFF) Then
               .Visible = False
               .Clear
    
                SysReAllocStringLen VarPtr(sText), , DragQueryFileW(hDrop, 0&)
                DragQueryFileW hDrop, 0&, StrPtr(sText), Len(sText) + 1&
    
                FN = FreeFile
                On Error GoTo 1
                Open sText For Input Access Read As FN
                    On Error GoTo 0
    
                    Do Until EOF(FN)
                        Line Input #FN, sText
                        If LenB(sText) Then
                           .AddItem sText
                            TW = TextWidth(sText)
                            If sngLongestText < TW Then sngLongestText = TW
                        End If
                    Loop
    1           Close FN
    
               .Visible = True
                SendMessageW .hWnd, LB_SETHORIZONTALEXTENT, RIGHT_MARGIN + sngLongestText, 0&
            End If
    
            DragFinish hDrop
        End With
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: drag drop to list , re question / help

    Code:
    Const RIGHT_MARGIN = 5& 'Right margin for List1's longest item (in pixels)
        Dim FN As Integer, sngLongestText As Single, TW As Single, sText As String
    
        With List1
            If DragQueryFileW(hDrop, &HFFFFFFFF) Then
               .Visible = False
               .Clear
    
                SysReAllocStringLen VarPtr(sText), , DragQueryFileW(hDrop, 0&)
                DragQueryFileW hDrop, 0&, StrPtr(sText), Len(sText) + 1&
    
                FN = FreeFile
                On Error GoTo 1
                Open sText For Input Access Read As FN
                    On Error GoTo 0
    
                    Do Until EOF(FN)
                        Line Input #FN, sText
                        If LenB(sText) Then
                           .AddItem sText
                            TW = TextWidth(sText)
                            If sngLongestText < TW Then sngLongestText = TW
                        End If
                    Loop
    1           Close FN
    
               .Visible = True
                SendMessageW .hWnd, LB_SETHORIZONTALEXTENT, RIGHT_MARGIN + sngLongestText, 0&
            End If
    
            DragFinish hDrop
        End With

    stext variable not defind
    fn variable not defind

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: drag drop to list , re question / help

    Quote Originally Posted by ladoo View Post
    stext variable not defind
    fn variable not defind
    Code:
    Dim FN As Integer, sngLongestText As Single, TW As Single, sText As String
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: drag drop to list , re question / help

    Quote Originally Posted by Bonnie West View Post
    @ Nightwalker

    I think ladoo wants to list all the contents of a single dragged text file. If so, then the following are the modifications required:
    I should have realized that! I always stop after the first line, etc rather than doing the whole thing when I suppose ought to.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: drag drop to list , re question / help

    thanks bonnie

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