Vbscript

Joined
Jul 7, 2011
Messages
1
Reaction score
0
hello everyone my name is Eric, im having a problem with a script i am trying to write for my administrative scripting class. yes this is a school project, and no i dont want anyone to write it for me i would like to learn what i am doing wrong and how to fix it. i have done large amounts of research and cannot find a solution to my problems. so i am seeking help here.

here are the requirements for my project:

Create a script that includes the following:

  1. Header section
  2. reference section
  3. Worker Information
  4. Output Information
  5. Document every line of the script
  6. All variable names must be unique
  7. determines how long the script will run
  8. Ask the user how many folders he wants to create by using a Msg Box
  9. check to see if folders exists
  10. ask the user where he wants to store the folders by using a Msg Box. Give the user an example of how to enter the information.
  11. create the folders by using Sub or a Function
  12. Create a file in each folder that you create. Add the following lines to the file:
    • I am writing a script
    • blank line
    • For a grade in my IST321 course
    • 2 blank lines
    • I expect a good grade!
  13. Notify the user that you have created the file in the folder.
  14. use a counter and echo out each folder as it is created
  15. Use an Array.
  16. let the user know when the script is complete
and here is the script that i have created so far (it is not done and all of the requirements are not there yet but i am trying to get the counter for folder creation to work first.)


' Header information
'
'========================================================
'
' File Name: IST321_EWalker_MidTerm.vbs
' This is a VBS script to run change the extention to .vbs
'
' Author: Eric Walker
' Date: July 7, 2011
'
'========================================================

option explicit
'on error resume next

dim TimeStart 'variable for time script started
dim TimeEnd 'variable for time script ends
dim TimeRan 'variable for total time script ran
dim FolderName 'variable for foldername
dim LocalDrive 'variable for c:
'dim CreateFolder 'variable
dim foldercount 'variable for folder counting
dim FolderInput 'variable for the number of folders the user wishes to create
dim folderamount 'variable for folderinput
dim filearray 'variable for array to store information about the files created
dim FolderLocation 'variable for the location of where the folders will be created.
dim textdocument 'variable for the text document that will be created in each new folder
dim sleep 'variable for placing the computer to "sleep" or pause for a given amount of time

' Reference information

timestart = now 'starts the stopwatch timer

folderInput = InputBox("How many folder do you wich to create: ", "folder amount", "any number between 1 and 6") 'the input box feilds


folderLocation = inputbox("Folder Location", "where would you like the folders to be placed", "C:\Documents and Settings\eriwal6880\Desktop\")
if folderinput <> "" then
folderamount = folderinput
else
quit
end if




' Worker and output information

Set LocalDrive = CreateObject("Scripting.FileSystemObject")
foldercheck
createfolder
folderamount = folderinput


wscript.echo("all done")





' *** Subroutines and functions are below ***



sub FolderCheck

If LocalDrive.FolderExists("folderlocation" & createfolder) Then
WScript.Echo("folder exists and will not be created")
Else
WScript.Echo("folder does not exist and will be created")
End if

end sub

function createfolder()
do until foldercount > folderamount
foldercount = 1
set createfolder = localdrive.createfolder(folderlocation & "folder" & foldercount)
wscript.echo createfolder
foldercount = foldercount +1
loop
end function


i got the inputbox's to work correctly but when i try to create the folders using a function it will only create one folder and gives me a runtime error stating that the folder already exists i know where the problem is but do not know how to fix it.

any and all help is greatly appreciated.

Thanks in advance
Eric
 
Last edited:
Hi Eric,

You said this was a school project. Good luck.

Tips:
Spell check all user facing material.
Release variables.
Follow instructions (document every line).
Use msgbox in your code to return values to help the debug process.
CamelCaseTextAndVariableNames.

Stoneboysteve
 
Back
Top