dcsimg
Results 1 to 6 of 6

Thread: Vb script debug function keep appearing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    20

    Vb script debug function keep appearing

    Hi

    I have the following script which works but im trying to stop it from continually stop it from making the message box pop up regarding the debug.

    I know it somewhere in the script where it says debug but aint got a clue what to put in to stop it.

    Any ideas.

    Thanks
    HTML Code:
    Option Explicit
    
    ' Global variables
    Dim strBaseDir, strDestDir
    Dim objFSO, objFile
    Dim arrFiles(), i
    Dim lngFolderSize, intFolderNumber, strNextDir, intMoveFile
    
    ' Define paths to work with
    strBaseDir = "B:\EE\EE29124343\base"
    strDestDir = "B:\EE\EE29124343\dest"
    
    ' Set maximum size of new folders
    Const cMaxFolderSize = 500000000
    
    ' Define class that will hold file information
    Class File
        Public lngSize
        Public strPath
    End Class 
    
    ' Create file system object
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    
    ' Fully resolve paths
    strBaseDir = objFSO.GetAbsolutePathname(strBaseDir)
    strDestDir = objFSO.GetAbsolutePathname(strDestDir)
    
    ' Make sure the folders exists, exit if not
    If Not objFSO.FolderExists(strBaseDir) Then
        WScript.Echo "*ERROR* Folder does not exist: """ & strBaseDir & """."
        WScript.Quit
    End If
    If Not objFSO.FolderExists(strDestDir) Then
        WScript.Echo "*ERROR* Folder does not exist: """ & strDestDir & """."
        WScript.Quit
     End If
     
    ' Initialize array index variable
    i = -1
    
    ' Load info for each file into array (using File class)
    For Each objFile In objFSO.GetFolder(strBaseDir).Files
        ' Don't include any files with size greater than max allowed in a folder
        If objFile.Size > cMaxFolderSize Then
            WScript.Echo "*WARNING* Skipping file: """ & objFile.Path & """, size:""" & objFile.Size & """ exceeds maximum folder size:""" & cMaxFolderSize & """."
        Else
            ' Add another element to the array of type File class
            i = i + 1
            ReDim Preserve arrFiles(i)
            Set arrFiles(i) = New File
    
            ' Store the size and full path to the file
            arrFiles(i).strPath = objFile.Path
            arrFiles(i).lngSize = objFile.Size
        End If
    Next
    
    ' If no files found then exit
    If i = -1 Then
        WScript.Echo "*WARNING* No files found to process."
        WScript.Quit
    End If
    
    ' Sort the files arrary by size in descending order
    SortArray arrFiles
    
    ' Process all files moving to new subfolders until done
    intFolderNumber = 0
    Do
        ' Start a new destination folder and create it (MUST NOT ALREADY EXIST)
        lngFolderSize = cMaxFolderSize
        intFolderNumber = intFolderNumber + 1
        strNextDir = strDestDir & "\" & intFolderNumber & "\"
        objFSO.CreateFolder strNextDir
    
        ' Move files to dest folder until full
        Do
            ' Look for the largest file left that will fit in remaining space
            intMoveFile = GetFileToMove(arrFiles, lngFolderSize)
    
            ' If we found another file to move then move it
            If intMoveFile <> -1 Then
                Wscript.Echo "*DEBUG* Dest:[" & intFolderNumber & "], Available:[" & lngFolderSize & "], File:[" & arrFiles(intMoveFile).strPath & "], Size:[" & arrFiles(intMoveFile).lngSize & "]."
                objFSO.MoveFile arrFiles(intMoveFile).strPath, strNextDir
                lngFolderSize = lngFolderSize - arrFiles(intMoveFile).lngSize
                arrFiles(intMoveFile).lngSize = -1
            End If
        Loop Until intMoveFile = -1
    
    Loop Until AllFilesMoved(arrFiles)
    
    Function GetFileToMove(ByRef arrArray(), lngSize)
        ' Find next largest file to move that fits, -1 if none found
        Dim i
        GetFileToMove = -1
        For i = LBound(arrArray) To UBound(arrArray)
            If arrArray(i).lngSize <> -1 Then
                If arrArray(i).lngSize <= lngSize Then
                    GetFileToMove = i
                End If
                Exit Function
            End If
        Next
    End Function
    
    Function AllFilesMoved(ByRef arrArray())
        ' See if all files have been moved
        Dim i
        AllFilesMoved = True
        For i = LBound(arrArray) To UBound(arrArray)
            If arrArray(i).lngSize <> -1 Then
                AllFilesMoved = False
                Exit Function
            End If
        Next
    End Function
    
    Sub SortArray(ByRef arrArray())
        ' Sort array of files by size, descending order (simple bubble sort)
        Dim i, j, intTemp
        For i = LBound(arrArray) to UBound(arrArray)
            For j = LBound(arrArray) to UBound(arrArray) - 1
    '            If arrArray(j).lngSize < arrArray(j + 1).lngSize Then
                If LCase(arrArray(j).strPath) > LCase(arrArray(j + 1).strPath) Then
                    Set intTemp = arrArray(j + 1)
                    Set arrArray(j + 1) = arrArray(j)
                    Set arrArray(j) = intTemp
                    Set intTemp = Nothing
                End If
            Next
        Next
    End Sub

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,895

    Re: Vb script debug function keep appearing

    1) There's no messagebox in that code... anywhere.
    2) There's only one line in there with the work Debug... and it's an echo command which writes it to the console window... so if you simply want to stop printing that... just comment it out...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    20

    Re: Vb script debug function keep appearing

    Thanks but I can I be an absolute pain and could you just copy and paste or highlight the bit I need to delete as I will be completely honest I had it written for me by a work colleague who is now on holiday for 3 weeks and I've tried deleting things and it not working or anything.

    I was told to save as a .VBS file is that correct.

    Sorry
    .

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    20

    Re: Vb script debug function keep appearing

    Quote Originally Posted by tweacle View Post
    Thanks but I can I be an absolute pain and could you just copy and paste or highlight the bit I need to delete as I will be completely honest I had it written for me by a work colleague who is now on holiday for 3 weeks and I've tried deleting things and it not working or anything.

    I was told to save as a .VBS file is that correct.

    Sorry
    .

    APOLOGIES sorted misread original reply.

  5. #5
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    443

    Re: Vb script debug function keep appearing

    Quote Originally Posted by techgnome View Post
    1) There's no messagebox in that code... anywhere.
    For the record, I'm pretty sure that if a .vbs file is executed with wscript.exe rather than cscript.exe the .echo commands are displayed as messagebox style pop-up dialogs.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    20

    Re: Vb script debug function keep appearing

    Apologies Ladies and Gents

    I had originally worked out how to get rid of the debug message but i didnt save the script and now forgot (DOH)

    Is anyone able to advise me on what I had to do again.

    Apologies

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width