Function not returning a value

Function not returning a value

daltonNYAW9
Advocate Advocate
378 Views
2 Replies
Message 1 of 3

Function not returning a value

daltonNYAW9
Advocate
Advocate

Hello,

 

I'm trying a make an ilogic rule that converts our vault file structure to our company's file structure.
The issue I'm having is the function creates the correct string value, but when I try to return it shows up blank.

Rule below. Highlighted the areas giving me trouble. 

Sub Main

	Dim filepath As String = ThisDoc.Path
	filepath = "C:\_Vault\Designs\Customers\Koppers\Galesburg, IL\22-7008M Sorter Upgrade Equipment\29-Upper Drag Chain\01-Catwalk\22-321127.ipt"
	filepath = filepath.Replace("C:\_IPI_Vault\Designs", "T:")
	
	Dim index As Integer
'	Dim folderpath As String
'	If filepath.Contains("A Level 2 customers")
'		index = GetNthIndex(filepath & "\", "\", 6)
'		folderpath = CreateFolderPath(filepath.Split("\"), Left(filepath, index), 6)
		
'	Else
'		index = GetNthIndex(filepath & "\", "\",5)
'		folderpath1 = CreateFolderPath(filepath.Split("\"), Left(filepath, index), 5)
'		MessageBox.Show(folderpath1)
'	End If
	
	index = GetNthIndex(filepath & "\", "\", 5)
	Dim folderpath As String
	folderpath = CreateFolderPath(filepath.Split("\"), Left(filepath, index), 5)
	MessageBox.Show(folderpath)


	
End Sub

Public Function GetNthIndex(searchString As String , charToFind As Char, n As Integer) As Integer
	Dim charIndexPair = searchString.Select(Function(c, i) New With {.Character = c, .Index = i }) _
	.Where(Function(x) x.Character = charToFind).ElementAtOrDefault(n - 1)

	Return If (charIndexPair IsNot Nothing, charIndexPair.Index, -1)
End Function

Public Function CreateFolderPath(folders As String(), folderpath As String, i As Integer)

'	MessageBox.Show(folderpath)
'	MessageBox.Show(folderpath)

	If IO.Directory.Exists(folderpath & "\Sub Jobs\" & folders(i))
		CreateFolderPath(folders, folderpath & "\Sub Jobs\" & folders(i), i + 1)
	Else
		MessageBox.Show(folderpath)
		Return folderpath
	End If
End Function

 

0 Likes
Accepted solutions (1)
379 Views
2 Replies
Replies (2)
Message 2 of 3

FINET_Laurent
Advisor
Advisor
Accepted solution

Hello @daltonNYAW9,

 

The function return object type is not specified :

Public Function CreateFolderPath(folders As String(), folderpath As String, i As Integer) as String

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 3

daltonNYAW9
Advocate
Advocate

Thanks for the quick reply! Yep it was a formatting error. I made the following changes in red.

Public Function CreateFolderPath(ByRef folders As String(), ByRef folderpath As String, ByRef i As Integer) As String

'	MessageBox.Show(folderpath)
'	MessageBox.Show(folderpath)

	If IO.Directory.Exists(folderpath & "\Sub Jobs\" & folders(i))
		folderpath = CreateFolderPath(folders, folderpath & "\Sub Jobs\" & folders(i), i + 1)
'		Exit Function
	Else
		MessageBox.Show(folderpath)
		
	End If
	Return folderpath
	
End Function