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.:eek:
Printable View
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.:eek:
The codes posted in your previous thread can do just that. You only have to modify them a bit.
can u help dear:(
Just modify the code Bonnie gave you in the other thread so it includes
vb Code:
Dim FF As Integer Public Sub Drag_n_Drop(ByVal hDrop As Long) Dim i As Long, sngLongestText As Single, TW As Single, sBuffer As String, text As String With List1 i = DragQueryFileW(hDrop, &HFFFFFFFF) If i Then .Visible = False .Clear For i = 0& To i - 1& SysReAllocStringLen VarPtr(sBuffer), , DragQueryFileW(hDrop, i) DragQueryFileW hDrop, i, StrPtr(sBuffer), Len(sBuffer) + 1& Open sBuffer For Input As #FF Input #FF, sBuffer .AddItem sBuffer Close #FF TW = TextWidth(sBuffer) If sngLongestText < TW Then sngLongestText = TW Next .Visible = True SendMessageW .hWnd, LB_SETHORIZONTALEXTENT, RIGHT_MARGIN + sngLongestText, 0& End If DragFinish hDrop End With End Sub Private Sub Form_Load() FF = FreeFile ScaleMode = vbPixels DragAcceptFiles hWnd, 1& 'fAccept:=TRUE Subclass Me End Sub
@ 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
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
thanks bonnie