V8i 359 - VB - Help needed in redirecting a variable path

I’m trying to redefine a line in an existing custom vb programme and I have only just started to understand vb.net but have written in vba previously (some years ago).

This is the line I want to edit:

StartProjectNumber = MSApp.ActiveWorkspace.ExpandConfigurationVariable("$(first(_USTN_PROJECTNAME))")

 

The history… I’m trying to tidy up a messy workspace and part of that is the project list, we have four and five digit project numbers but due to the numeric nature of the list our 10000 numbers appear at the head of the list when they should follow behind 9999. This is easy enough to fix which I did by adding a preceding ‘0’ to the four digit numbers to make them all five digits but I didn’t anticipate the effect on some custom programming, which verifies the correct project is open against the open file.

 

The result is the programme now fails because it interprets 09999 from the pcf as not matching the directory which is actually 9999.

 

So I need to find a way of either redefining "StartProjectNumber" so that the expanded variable $(_USTN_PROJECTNAME) loses the preceding zero or look at replacing it with a shortened path from $(_DGNDIR) i.e. $(_DGNDIR)=S:\9999\ to drop the ‘S:\’ and end ‘\’  to get ‘9999’

Any suggestions will be gratefully received.

Thanks.

Parents
  • Unknown said:
    Any suggestions will be gratefully received

    I used LINQPad to write some code to analyse your path using VB.NET methods and Regular Expressions...

    Here's the code...

    Debug.WriteLine("Parsing folder path using VB.NET methods")
     
    Dim path as String
    path="S:\9999\"
    Debug.WriteLine ("Path=" & path)

    Dim drive as String = Microsoft.VisualBasic.left(path,3)
    Debug.WriteLine ("Drive=" & drive)

    Dim last As String=Microsoft.VisualBasic.Right(path,1)
    Debug.WriteLine ("Last=" & Last)

    Dim folder As String=Microsoft.VisualBasic.Mid(path, 4, Microsoft.VisualBasic.Len(path)-4)

    Debug.WriteLine ("Folder=" & folder)

    Debug.WriteLine ("Parsing folder path using Regular Expressions")

    Dim regex As System.Text.RegularExpressions.Regex = _
        New System.Text.RegularExpressions.Regex("\d+")
    Dim match As System.Text.RegularExpressions.Match = regex.Match(path)
    If match.Success Then
        Debug.WriteLine("Folder=" & match.Value)
    End If

     
    Regards, Jon Summers
    LA Solutions

  • Really appreciate the example Jon, on interrogating the existing code I identified an example of a Mstn variable being stripped down, in this instance it was MS_DEF, so I took a punt and tried the exact same settings for _DGNDIR here it is:

    StartProjectNumber = Replace(Mid(MakeFile.CleanPathText(MSApp.ActiveWorkspace.ExpandConfigurationVariable("$(first_DGNDIR))")), 4, 5), "\", "")

    I'm not entirely sure how it is working other than using the "\" to identify but it appears to be generating just the project number part of the file path and because the directories have not been changed to add a preceding '0' the rest of the programme works correctly.

    In my example:

    _DGNDIR = S:\2393\PlanChest\0200-(GA's-Full)\

    and after the definition is made:

    StartProjectNumber = 2393

    If you can explain how the capture is working from the example above it would make it easier to utilise these settings in future code?

    Your example is very helpful though, I have just jumped straight into VB and didn't even know how to generate a debug.

    Cheers

    Answer Verified By: CAD-wiz 

  • Hi,

    debug your code by setting a red marker at the very beginning of a line. if the line is hit by the code the debug window will pop up.

    Your example works because of the MID- Function. See : msdn.microsoft.com/.../05e63829(v=vs.90).aspx

    Regards, Stefan.

  • Yep I'm used to the debug in Mstn VBA interface but Visual Studio is somewhat different, thanks for the link.

  • Ok, I misunderstood it. If you are writing managed code in vb.net I would suggest using Visual Studio. Debugging is almost the same as in VBA but you have to connect to the application.

Reply Children
No Data