I have a Named Expression the will look to the name of the active file and and report true or false if the file name contains the characters defined in the expression
So a file name of xXX_RoadDesign will report True with this expression System.String.Compare(System.String.SubString(System.Path.GetFileNameWithoutExtension(ActiveFile.FileName),0,3),"xXX").
Is it possible to create a similar expression that will look a the active file name and look at the first 3 characters of the active file name and report what those characters are?
Ex, if the active file name is aAA_RoadDesign the named expression will look at the file name and return "aAA". If I switch to a file named bBB_RoadDesign the expression would return "bBB"?
I'm looking to create a vba that will obtain the first 3 characters of a file name, which determines the discipline, to change a configuration variable to True/False based on those first three file name characters.
Hi,
mwlong said:Is it possible to create a similar expression that will look a the active file name and look at the first 3 characters of the active file name and report what those characters are?
It would be simpler than your original expression:
System.String.Substring(System.Path.GetFileName(ActiveFile.FileName), 0, 3)
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: mwlong
Jan Šlegr said:It would be simpler than your original expression:
I copied that original expression from another forum post.
Your expression works. I knew it wasn't to complicated but I am new to named expressions. Thanks for the help, I knew you would be the one to answer the question.
Microstation CONNECT - 10.17.2.61
ORD - 2021 R1 10.10.1.3
ORD 2022 R1.1 - 10.11.3.2
ORD 2022 R3 - 10.12.2.4
Microstation v8i SS 10 - 08.11.09.919
Power InRoads v8i - 08.11.09.615
ProjectWise - 10.0.3.453
mwlong said:I'm looking to create a vba that will obtain the first 3 characters of a file name, which determines the discipline, to change a configuration variable to True/False based on those first three file name characters.
Why not just do the entire process in VBA then, it’s probably the easiest approach of all?
Barry Lothian said:Why not just do the entire process in VBA then
That's what I am looking to do, as I stated in my original question.
Hi mwlong,
you may want to start with VBA code similar to this code snippet:
Dim s As String If Len(ActiveDesignFile.name) >= 3 Then s = Left(ActiveDesignFile.name, 3) Debug.Print s If s = "xxx" Then ActiveWorkspace.AddConfigurationVariable "NewVariable", "newValue", True End If End If
Best regards,
Artur
mwlong said:I'm looking to create a vba that will obtain the first 3 characters of a file name
That looks like a generic VBA question, not specific to MicroStation. Search VBA Forums for VBA hints: for example, Stack Overflow. The Microsoft Scripting Runtime DLL is particularly useful when dealing with files and folders.
Regards, Jon Summers LA Solutions
Jon Summers said:Search VBA Forums for VBA hints:
I did. Not much help with what I was looking for specifically. My original question is only about the named expression and not how to write a vba for what I need to accomplish. I don't believe named expressions are programming items. I know you can use them to write a vba but you can also use them in just plain Microstation. I did not feel the original question should go into the programming forum as I was not asking a programming question. I can also use that named expression as a keyin for a custom tool.
If we are fortunate enough to get new funding from our client I will start looking at the vba & post additional questions in the programming forum.
Thanks for the information.
mwlong said:I don't believe named expressions are programming items.
They are both, because Named Expressions represent the functionality, useful for users and admins (can be created manually, used at many places), but they also have their "programming side": They can be called from code in the same way as from MicroStation, and at "programming level", how to add own symbol provider and new NE functionality can be discussed too.
Regards,
Jan Šlegr said:They are both
I agree. I plan to use the named expression in a programming format....eventually.
At the time I was asking the question it was to obtain the correct format of the named expression to return a truncated file name. I was not looking for programming advice at that point but thought it was valuable information to state that it would eventually be used for vba.