Results 1 to 3 of 3

Thread: De-Select (VB6)

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    De-Select (VB6)

    I need a little help with an Imaging facility I'm trying to update.
    I've attached a screenshot to show what I'm trying to accomplish.
    The left hand list fills with *.JPG from a selected folder, and the user selects from this to put in the right hand list.
    From there, the "Move files now" button runs code to save the images in a specified location.
    The problem I have is with the , "Remove from list" button.
    What code do I need to remove selected images from the right hand list.??

    Private Sub Command1_Click()
    For n = 0 To File1.ListCount - 1
    If File1.Selected(n) = True Then
    fn = Dir1
    If Right$(Dir1, 1) <> "" Then fn = fn + ""
    fn = fn + File1.List(n)
    ' 1st check to see if item is already in list
    For n2 = 0 To List1.ListCount
    If fn = List1.List(n2) Then GoTo skip
    Next n2
    List1.AddItem fn
    List2.AddItem File1.List(n)
    skip:
    End If
    Next n
    End Sub

    Private Sub Command3_Click()

    End Sub

    Private Sub Command4_Click()
    If List1.ListCount = 0 Then MsgBox "No Images Selected": Exit Sub
    On Error Resume Next

    If Right$(TXFileTo, 1) <> "" Then TXFileTo = TXFileTo + ""
    direxists = GetAttr(TXFileTo) And vbDirectory

    If IsNull(direxists) = True Or Err = 76 Or direxists = "" Then
    MkDir (TXFileTo)
    End If
    jobno = InputBox("Enter Job Number.", "!!")
    rega = InputBox("Enter Registration No.", "!!")
    If rega = "" Or jobno = "" Then MsgBox "You Have Missed An Entry Job Number or Registration No": Exit Sub
    For n = 0 To List1.ListCount - 1
    fn = UCase$(jobno) + "-" + rega + "_" + List2.List(n)
    FileCopy List1.List(n), TXFileTo + fn
    Next n
    MsgBox "Images Imported", vbOKOnly, "Image Importer"
    End Sub

    Private Sub Dir1_Change()
    File1 = Dir1
    End Sub

    Private Sub Drive1_Change()
    Dir1 = Drive1
    End Sub

    Private Sub File1_Click()
    fn = ""
    fn = Dir1
    If Right$(fn, a) <> "" Then fn = fn + ""
    IMGpreview.Picture = LoadPicture(fn + File1)
    End Sub

    Private Sub Form_Load()
    Me.Label1.Visible = False

    End Sub

    Private Sub List1_Click()
    IMGpreview.Picture = LoadPicture(fn + List1)
    Me.Label1.Visible = True

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: De-Select (VB6)

    Hi Dave,

    There are two lists on the right hand side, List1 and List2. I assume that if items selected in List1 are removed, the corresponding items in List2 must be removed too. Code could look like this:

    Private Sub cmdRemove_Click()
    Dim i As Integer
    ' Step backwards through list
    For i = List1.ListCount - 1 To 0 Step -1
    If List1.Selected(i) Then
    ' If selected in List1, remove from both
    List1.RemoveItem i
    List2.RemoveItem i
    End If
    Next i
    End Sub

    where cmdRemove is the name of the command button with caption "Remove from list". The code steps backwords through the list items, because if you step forward, it would get confused when an item is removed. Note that the index loops from ListCount -1 to 0, for the list index is zero-based: if ListCount is 6, the items are numbered 0, 1, 2, 3, 4 and 5.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: De-Select (VB6)

    Thankyou Hans.
    Your code is fine and all works ok.

    p.s
    Quite nice to be in here isn't it, I feel like I'm with the big boys !! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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