Need to create a ilogic rule based on a VBA rule that searches for a folder

Need to create a ilogic rule based on a VBA rule that searches for a folder

TechInventor20
Advocate Advocate
479 Views
4 Replies
Message 1 of 5

Need to create a ilogic rule based on a VBA rule that searches for a folder

TechInventor20
Advocate
Advocate

Hello, we have a vba code (Code is attached in the Excel sheet). 

 

The idea is this: The rule looks for a subfolder that contains the first 6 numbers of the name.

 

this is the rule behind the excel sheet. 

The excel file doesn't contains the VBA rule because the forum doesn't support that kind of file.

 

Sub Zoek_directory_via_FSO()

Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder

Dim h1%
Dim schijfadres$
Dim zoek_naar_directory$

schijfadres$ = Blad1.Cells(3, 2)
zoek_naar_directory$ = UCase$(Blad1.Cells(4, 2)) 'ucase maakt er hoofdletters van; Uppercase

'staat er a\ een \ op de laatste positie van het schijfadres ?
h1% = Len(schijfadres$)
If h1% >= 2 And Mid$(schijfadres$, h1%, 1) <> "\" Then schijfadres$ = schijfadres$ + "\"

Blad1.Cells(5, 2) = " .. niets gevonden .."

Set myFolder = FSO.GetFolder(schijfadres$)

For Each mySubFolder In myFolder.SubFolders
'(A) alleerst wordt alles in hoofdletters vergeleken
'(B) de functie instr geeft de positie aan waar een zoekfragment in een string begint
'(C) InStr("THOMAS","A") geeft 5 als resultaat. De A is het 5e karakter
'(D) InStr("K19245 SCHUDBED ARLA FOODS","K19245") geeft 1 als resultaat. De K19245 begint op het 1e karakter
'onderstaand is dit als volgt toegepast:
If InStr(UCase(mySubFolder.Name), zoek_naar_directory$) >= 1 Then 'gelijk aan voorbeeldregel (D)
'Debug.Print mySubFolder.Name
Blad1.Cells(5, 2) = mySubFolder.Name
Exit For
End If 'InStr(UCase(mySubFolder.Name), zoek_naar_directory$) >= 1 Then
Next 'Each mySubFolder

End Sub

 

 

I need this rule translated to ILogic. I hope someone can help me.

 

Met vriendelijke groet, Thomas de Vries

Kind Regards, Thomas de Vries

0 Likes
Accepted solutions (2)
480 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

you could try something like this:

Dim schijfadres As String = "c:\temp\"
Dim zoek_naar_directory As String = InputBox("Enter directoy to search for.", "iLogic", "")
Dim gevonde_directory = " .. niets gevonden .."

Dim searchDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo(schijfadres)
For Each subDir As IO.DirectoryInfo In searchDirInfo.GetDirectories
    If (subDir.Name.Equals(zoek_naar_directory, StringComparison.InvariantCultureIgnoreCase)) Then
        gevonde_directory = subDir.FullName
    End If
Next

MsgBox("Do stuff with path: " & gevonde_directory)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

TechInventor20
Advocate
Advocate
If I do it like this I don't get te path for "K20996 TEST"
Dim schijfadres As String = "C:\Workspace\Documents\Kuipers\04 - Afdeling\Test\Thomas de Vries"
Dim zoek_naar_directory As String = InputBox("Enter directoy to search for.", "iLogic", "")
Dim gevonde_directory = " .. niets gevonden .."

Dim searchDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo(schijfadres)
For Each subDir As IO.DirectoryInfo In searchDirInfo.GetDirectories
    If (subDir.Name.Equals(zoek_naar_directory, StringComparison.InvariantCultureIgnoreCase)) Then
        gevonde_directory = subDir.FullName
    End If
Next

MsgBox("Do stuff with path: " & gevonde_directory)

 

With only filling in "K20996" you need to get the name of folder "K20996 TEST"

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

You can try this. I did not test it so let me know if it does not work. then i will have a look at it when i'm at home.

 

Dim schijfadres As String = "C:\Workspace\Documents\Kuipers\04 - Afdeling\Test\Thomas de Vries"
Dim zoek_naar_directory As String = InputBox("Enter directoy to search for.", "iLogic", "")
Dim gevonde_directory = " .. niets gevonden .."

Dim searchDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo(schijfadres)
For Each subDir As IO.DirectoryInfo In searchDirInfo.GetDirectories
    If (subDir.Name.ToUpper().Contains(zoek_naar_directory.ToUpper())) Then
        gevonde_directory = subDir.FullName
    End If
Next

MsgBox("Do stuff with path: " & gevonde_directory)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 5

TechInventor20
Advocate
Advocate
Accepted solution

I fixed the problem!

 

 

Dim schijfadres As String = "C:\Workspace\Documents\Kuipers\04 - Afdeling\Test\Thomas de Vries"
Dim zoek_naar_directory As String = InputBox("Enter directoy to search for.", "iLogic", "")
Dim gevonde_directory = " .. niets gevonden .."

Dim
searchDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo(schijfadres)
For Each subDir As IO.DirectoryInfo In searchDirInfo.GetDirectories
If (subDir.Name.Contains(zoek_naar_directory)) Then
gevonde_directory = subDir.FullName
End If
Next

MessageBox.Show("Gevonden path:......" & gevonde_directory)

 Thanks jelte de jong for  getting me on the right track!

0 Likes