1

I have been asked by my colleagues to write a program that allows us to enter a job number and it will take us to the proper folder within our database (SolidWorks EPDM). The structure of the folders is as follows: C:\Litania EPDM\Orders\XXXX\XX\number with the first set of Xs representing the year and the second set the month. Example job number being 112113-444121-1X, so that 11 would be the month, 12 the day, 13 the year (2013), the middle six are the unique job number and the 1X is just a suffix which changed to 2X and so on if there are multiple orders under the same number.

What I need to accomplish is setting up variables (strings) that can hold the year with a "20" in front of it, the month, the number and the suffix then I need to combine those into a folder path. Here is what I have:

Public Class ProjectLookup

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim day As String = CStr(DateText.Text)
        Dim string1 As String = Microsoft.VisualBasic.Right(day, 4)
        Dim month As String = Microsoft.VisualBasic.Left(string1, 2)
        Dim year As String = "20" + Microsoft.VisualBasic.Right(string1, 2)
        Dim num As String = CStr(NumberText.Text)
        Dim suff As String = CStr(SuffixText.Text)

        Process.Start("explorer.exe", "C:\Litania EPDM\Orders\" + year + " \ " + month + " \ " + num + suff)
    End Sub
End Class

Any help would be greatly appreciated. Currently it runs and opens windows explorer, but does not go to the intended path. Thank you.

3
  • Can you tell us where it is taking you hence give us an idea of what is being generated incorrectly? At a glance this all looks fine Commented Mar 6, 2014 at 18:32
  • Note that the CStr()s are pointless - .Text is already a string. You're also using very old syntax - it's VB6-esque. instead of Microsoft.VisualBasic.Left(string1, 2) do string1.Left(2) Commented Mar 6, 2014 at 18:44
  • Try to assign the path to a string variable first and check its contents to see if the path is correct. In one of my apps I open the path in explorer by simply using Process.Start(StringVariableWithPathInIt) Commented Mar 6, 2014 at 18:46

2 Answers 2

3

The integrity of your code is wrong since you are concatenating strings with the "+" character, using VB6 methods (programming techniques of a decade ago), casting strings when is not needed (string properties), etc...

Also, an argument should be enclosed with double quotes to avoid problems, for example, in this case, a directory that contains spaces which is taken as more than 1 argument 'cause is not enclosed, then you just need to enclose it and it should work:

Process.Start("Explorer.exe", String.Format("""C:\Litania EPDM\Orders\{0}\{1}\{2}""", 
                                            year, month, num & suff ))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I have taken your suggestions and will try tomorrow at work. Also, does it matter that the desired path (Litania EPDM) is a password protected vault? All users are automatically logged into the vault when they log in to Windows.
1

I prefer to concatenate the file path like this:

Dim _path As String = IO.Path.Combine("C:\Litania EPDM\Orders", year, month, num & stuff)
If IO.File.Exists(_path) Then
 'proceed
End If

1 Comment

Path.Combine with up to four components was only introduced in .NET 4.0, in case anyone wants to try that with, say .NET 3.5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.