Results 1 to 3 of 3

Thread: 2 Q's

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg , Denmark
    Posts
    1,544

    Post

    Hi all!
    I have 2 questions...

    1. How can i create a file via an InputBox, and display and error if the file already exists?

    2. How can i delete a selected folder in a DirListBox??


    ------------------
    Yours sincierly
    CyberCarsten http://home18.inet.tele.dk/cyber/
    carsten.h.thomsen@mail.tele.dk


    [This message has been edited by CyberCarsten (edited 01-21-2000).]

  2. #2
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Post

    I'm sending you this project:

    Option Explicit
    '
    'WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!
    '
    ' THE FOLDER THAT YOU WANT DELETE MUST BE SELECTED WITH DOUBLE CLICK!
    '
    'WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!

    Private Sub cmdDelete_Click()

    If Dir1.Path = "C:\" Then
    MsgBox "You can't delete C:\", vbCritical, "Warming!"
    Exit Sub
    End If

    If MsgBox("Do you really want delete: " & Dir1.Path, vbYesNo) = vbNo Then Exit Sub

    Dim cUp As String
    Dim nPos As Long

    For nPos = Len(Dir1.Path) To 1 Step -1
    If Mid$(Dir1.Path, nPos, 1) = "\" Then
    Exit For
    End If
    Next

    cUp = Mid$(Dir1.Path, 1, nPos - 1)

    'Shell "DELTREE /Y " & Chr(34) & Dir1.Path & Chr(34), vbHide
    On Error Resume Next

    'This 'll not kill sub folders!
    'If your folder has sub folders you'll need add extra code.

    VBA.FileSystem.Kill Dir1.Path & "\*.*"
    VBA.FileSystem.RmDir Dir1.Path

    DoEvents
    DoEvents
    Dir1.Path = cUp
    Dir1.Refresh
    End Sub

    Private Sub Command1_Click()

    Dim cFile As String
    Dim lUserCanceled As Boolean

    cFile = "C:\New.txt"

    TrapBegin:

    cFile = InputBox("Type a valid file name:", "Creating files", cFile)

    If cFile = "" Then
    If lUserCanceled Then Exit Sub
    MsgBox "File name invalid!", vbExclamation
    lUserCanceled = True
    GoTo TrapBegin
    Else

    lUserCanceled = False

    'If the user can't type the path
    'you 'll nedd verify "\" and "/" and ":" to avoid errors!

    If InStr(1, cFile, "*") <> 0 Or _
    InStr(1, cFile, "?") <> 0 Or _
    InStr(1, cFile, "|") <> 0 Or _
    InStr(1, cFile, ">") <> 0 Or _
    InStr(1, cFile, "<") <> 0 Or _
    InStr(1, cFile, Chr(34)) Then

    MsgBox "The file name can't have: * ? | < > "" : ", vbInformation
    Exit Sub
    End If

    If Not FileExist(cFile) Then
    Dim nFreeFile As Long
    nFreeFile = FreeFile
    Open cFile For Append As nFreeFile
    Print nFreeFile, "By Jefferson"
    Close nFreeFile
    Else
    'File Not Exist
    MsgBox "This file already exist!", vbInformation
    lUserCanceled = True 'If you do this it 'll not show me message "File name invalid!", when you cancel!
    GoTo TrapBegin
    End If
    End If

    End Sub

    Private Function FileExist(ByVal cPathFile As String) As Boolean
    On Error Resume Next
    If Len(cPathFile) Then FileExist = Len(Dir(cPathFile, vbNormal + vbHidden)) > 0
    End Function

    Private Sub Command2_Click()
    Unload Me
    End Sub

    Boa sorte!
    Jefferson

  3. #3
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Do you mean "WARNING"?

    ------------------
    I wish I was patient... RIGHT NOW!

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