Click here to Skip to main content
12,999,157 members (42,795 online)
Rate this:
Please Sign up or sign in to 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

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 10-Nov-13 10:44am
Updated 10-Nov-13 10:48am
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")
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...
Ahmad Al Halabi 11-Nov-13 5:18am
I want to copy function in another project

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 11 Nov 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100