reimplemnt功能更全球化 [英] reimplemnt Function to be more global

查看:98
本文介绍了reimplemnt功能更全球化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,它完美地工作,但我希望更加全球化,所以无论我在哪里工作。

任何人都可以帮我改进这个功能吗?



======





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



如果MsgBox(你想要将发票导出到& _WhouseToComboBox.textBox.Text&?,MsgBoxStyle.YesNo)= MsgBoxResult.Yes然后



Dim Whouse As String

For Each Dr作为DataRow在SelectedItem.Rows

Whouse = dr.Item(whouseDesc)

ProcessCopy(POSPath,dt,FolderCopyto,Whouse)

下一个博士

结束如果

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子目录为字符串



For Each子目录在子目录中

尝试



如果Path.GetFileName(子目录)= DirectoryFather那么



如果IO。 Directory.Exists(子目录& \& FolderTarget)然后



File.WriteXml(子目录&\& FolderTarget&\& File.Tables(0).Rows( 0).Item(InvoiceID)&.xml)



结束如果



结束如果



ProcessCopy(子目录,文件,FolderTarget,DirectoryFather)

Catch ex As Exception

结束尝试



下一个子目录



End Sub



i这个函数,副本(写入XML)是我希望从它中分离的函数内部

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

推荐答案

Ahmad Al Halabi写道:
Ahmad Al Halabi wrote:

我想在另一个项目中复制函数

I want to copy function in another project

你需要使用访问修饰符 public 用于函数及其声明类型,以使其可从其他程序集访问。并且您需要通过要使用它的那个引用此程序集。就是这样。



当然,你不想复制一个函数。我想你只是用错了字。但是,您还需要学习术语和编程的基础知识。在运行时期间,没有项目,只有程序集和模块。如果您有两个项目在解决方案中并将一个项目添加到另一个项目作为参考(总是一个好主意),这只是一个好方法,使一个程序集自动引用另一个程序集,即使您重命名,移动项目签名(它改变了强名称)等等。您需要学习程序集,类型与实例,静态与实例成员等等。



-SA

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


这篇关于reimplemnt功能更全球化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆