Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this function and it work perfecly, but i want to be more global so where ever i put it work.
can anyone help me to improve that function ?

======


Sub ExporttoFolder(ByVal POSPath As String, ByVal dt As DataSet, ByVal FolderCopyto As String,ByVal SelectedItem As DataTable)

If MsgBox("Do you want to Export Invoice to " & _WhouseToComboBox.textBox.Text & " ? ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

Dim Whouse As String
For Each dr As DataRow In SelectedItem.Rows
Whouse = dr.Item("whouseDesc")
ProcessCopy(POSPath, dt, FolderCopyto, Whouse)
Next dr
End If
End Sub




Sub ProcessCopy(ByVal targetDirectory As String, ByVal File As DataSet, ByVal FolderTarget As String, ByVal DirectoryFather As String)


Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)
Dim Filepath As String = Nothing
Dim subdirectory As String

For Each subdirectory In subdirectoryEntries
Try

If Path.GetFileName(subdirectory) = DirectoryFather Then

If IO.Directory.Exists(subdirectory & "\" & FolderTarget) Then

File.WriteXml(subdirectory & "\" & FolderTarget & "\" & File.Tables(0).Rows(0).Item("InvoiceID") & ".xml")

End If

End If

ProcessCopy(subdirectory, File, FolderTarget, DirectoryFather)
Catch ex As Exception
End Try

Next subdirectory

End Sub

i this function, the copy (Write XML) is inside the function i want to be seperat from it
Posted
Updated 10-Nov-13 10:48am
v2
Comments
ArunRajendra 10-Nov-13 22:27pm    
I can see two dependency if you convert this to parameter to a function then I think you are ready to use in from anywhere.

Whouse = dr.Item("whouseDesc")
File.Tables(0).Rows(0).Item("InvoiceID")
Sergey Alexandrovich Kryukov 11-Nov-13 1:15am    
There are no such thing as "global function" in .NET. Globals are evil, and they are not really needed.
You may hope from some practical advice if you explain why do you need certain function, what it should do and how you want to use it...
—SA
Ahmad Al Halabi 11-Nov-13 5:18am    
I want to copy function in another project

1 solution

Ahmad Al Halabi wrote:
I want to copy function in another project
You need to use access modifier public for function and its declaring type, to make it accessible from other assemblies. And you need to reference this assembly by the one where you want to use it. That's it.

Of course, you don't want to copy a function. I think you just used wrong words. But also, you need to learn terminology and the basics of programming. During runtime, there are no projects, there are only assemblies and modules. When you have, say, two projects in on solution and add one project to another as a reference (always a good idea), this is merely a good way to make one assembly referenced another one automatically, even if you rename, move the project, sign it (it changes its strong name) and so on. You need to learn assemblies, types vs instances, static vs instance members, and a lot more.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900