MicroStation CE U11
I am trying to do a few things, create a folder if it does not exist, and then copy a folder from one location to another using variables that define the source folder and the location that the source folder is to be placed in. So far I am successful in creating the folder but for the copy folder part, it errors out. Any ideas? When I place the full path in the to and from it works, but when I try to use variables, it errors.
Below is an example of what I am thinking. The goal is to use variables available from the configuration in the event the workspace resources are different for different clients. No hard paths like "C:\folder\".
Sub BVEClashDetectionSetup() Dim LOCATIONA As String Dim LOCATIONC As String Dim strDir1 As String Dim objFSO As Object ' Define locations for resources LOCATIONA = ActiveWorkspace.ConfigurationVariableValue("LOCATIONA") 'from location USTNCE_Root = ActiveWorkspace.ConfigurationVariableValue("_USTN_HOMEROOT") 'assist to create to location ' Create directory if does not exist strDir1 = USTNCE_Root & "newfolder" 'to location If Dir(strDir1, vbDirectory) = "" Then MkDir strDir1 ' Copy resources from workspace to local Set objFSO = CreateObject("Scripting.FileSystemObject") 'objFSO.copyFolder "C:\Path\to\source\folder", "C:\Path\to\destination\folder" objFSO.CopyFolder LOCATIONA, strDir1 Else ' Error checking ShowMessage "FolderA Already Exists!!!" End If End Sub
Thanks ahead of time!!!
Mark W.
Hi,
This is not a Microstation programming question. You would better search the web for VB best practice especially the "Windows Scripting " things
Mark Winegar said:Scripting.FileSystemObject
Regards
Frank
since 1985: GIS, CAD, Engineering (Civil) Senior Consultant : [Autodesk Civil 3D , Esri ArcGIS, VertiGIS: in previous days : Bentley MS V4 - V8i, GeoGraphics, Bentley Map V8i, InRoads, HHK Geograf, IBr DAVID] : Dev: [C, C++, .NET, Java, SQL, FORTRAN, UML][direct quote by: http://en.wikipedia.org/wiki/Helmut_Schmidt]: "Wer Kritik übel nimmt, hat etwas zu verbergen"Wer Grammatik- und/oder Rechtschreibfehler findet, der darf sie behalten :-)
Hi Mark,
I'd like to ask kindly to follow best practices, especially how subject should be formatted (in this case something like [CONNECT U11 VBA]) and also Insert > Insert code tool should be used for every shared code snippet. To read unformatted code (formatted as a plain text) is really annoying.
Mark Winegar said: it errors out.
What does it mean? "Error" can be anything from "it does nothing" to "Windows BSOD".
Mark Winegar said:Any ideas?
I agree with Frank that general VBA forums are probably better places where to ask. It seems there are plenty of pages about how to copy a folder.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Mark Winegar said:Set objFSO = CreateObject("Scripting.FileSystemObject")
Prefer to create a reference to the Windows Scripting Library. Then you can use a declared Scripting.FileSystemObject object and gain the benefit of IntelliSense. Read this article about Windows Scripting Runtime.
Mark Winegar said:MkDir strDir1
Since you're using the Windows Scripting Library, dispense with relics like MkDir.
MkDir
I find your code hard to follow, partly because functionality is fragmented. Use functions to perform specific tasks and give them useful names. For example …
Dim sourceFolder As String If GetSourceFolder (sourceFolder, "LOCATIONA") Then ' Carry on copying … End If
GetSourceFolder function …
Function GetSourceFolder (ByRef folder As String, ByVal cfgVar As String) As Boolean GetSourceFolder = False If ActiveWorkspace.IsConfigurationVariableDefined (cfgVar) folder = ActiveWorkspace.ConfigurationVariableValue (cfgVar) GetSourceFolder = True EndIF End Function
Mark Winegar said: for the copy folder part, it errors out. Any ideas?
Use the VBA Err object to get more information about errors.
Err
Regards, Jon Summers LA Solutions
Mark Winegar said:I am trying to do a few things
The things you are trying to do look a lot like our File Synchroniser!