Thread: vb to vbscript

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    7
    Rep Power
    0

    vb to vbscript


    Hey all,

    I'm trying to convert a visual basic app I wrote into vbscript. The application is pretty simple. It gets the system time, converts all bad characters to dashes and makes a folder of the date and time.

    Below is the vbscript code that I have wrote. When I run the file from the command prompt (with cscript) I get a "type mismatch 'mid' " error.

    ANy help/advice is appreciated!

    Function CreateFolderDemo

    Dim fso, f, timeStamp, stringLength, count, newTimeStamp, colonLoc, dashLoc, colonChar, dashChar

    count = 1
    timeStamp = Now
    newTimeStamp = timeStamp
    stringLength = Len(timeStamp)
    colonChar = ":"
    dashChar = "/"

    Do While count < stringLength

    'Returns the character locations
    colonLoc = InStr(count, timeStamp, colonChar, 0)
    dashLoc = InStr(count, timeStamp, dashChar, 0)

    'Modifies the characters in the string
    If Not colonLoc = 0 Then
    Mid(newTimeStamp, colonLoc) = "-"
    End If

    If Not dashLoc = 0 Then
    Mid(newTimeStamp, dashLoc) = "-"
    End If

    count = count + 1

    Loop

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.CreateFolder("c:\" + newTimeStamp)
    CreateFolderDemo = f.Path

    End Function

    call createfolderdemo()



    Thanks,

    Mark
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Ok, this is what I came up with. It is a little bit different that what you are attempting to do, and a little more direct.
    Code:
    Function CreateFolderDemo
    
    	Dim fso, f, timeStamp, stringLength, newTimeStamp, colonChar, dashChar, spaceChar, replaceChar
    
    	timeStamp = Now
    	newTimeStamp = timeStamp
    	colonChar = ":"
    	dashChar = "/"
    	spaceChar = " "
    	replaceChar = "-"
    
    	newTimeStamp = Replace(newTimeStamp, colonChar, replaceChar)
    	newTimeStamp = Replace(newTimeStamp, dashChar, replaceChar)
    	newTimeStamp = Replace(newTimeStamp, spaceChar, replaceChar)
    	
    
    	Set fso = CreateObject("Scripting.FileSystemObject")
    	newTimeStamp = "c:/" & newTimeStamp
    	Set f = fso.CreateFolder(newTimeStamp)
    	CreateFolderDemo = f.Path
    
    End Function
    
    call createfolderdemo()
    The reason for the error you are getting is because the Mid() function returns a value, you can't set a value in this manner.
  4. #3
  5. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Another good bit of advice I could offer possibly is two things...
    1) I would see if I could find the VBScript, Introduction to Windows Script Components, and Windows Script Host Reference help manuals. They are in compiled help format. These came on my computer in the directory:
    C:\VALUEADD\MSFT\XTRADOCS\SCRIPT

    2) A quick little tip on how to echo out content you can use WScript.echo "what ever you want to echo goes here"

IMN logo majestic logo threadwatch logo seochat tools logo