定义硬编码值的最佳位置在哪里? [英] Where is best place to define hard coded values?

查看:79
本文介绍了定义硬编码值的最佳位置在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有许多硬编码值,例如文件路径,文件名,超时,

等,哪里是定义它们的最佳位置?意思是,例如,某些东西需要更改,而不是运行可能包含这些值的所有子函数或

函数,我想要一个地方更改它们

并将更改反映在使用那些

值的子函数或函数中。我想避免使用全局变量;保持价值仅对那些使用它们的人来说是私有的。


谢谢,

Brett

解决方案




我会创建一个对类或表单私有的变量。

这样所有子例程和函数都可以使用它。它不会在表格或类别之外可以访问。




---------- -

" Brett" < no@spam.net>在留言中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

如果我有许多硬编码值,如文件路径,文件名,超时,

等,哪里是定义它们的最佳位置?意思是,例如,某些东西需要更改,而不是运行可能包含这些值的所有子函数或

函数,我想要一个地方更改它们

并将更改反映在使用那些

值的子函数或函数中。我想避免使用全局变量;保持价值仅对那些使用它们的人来说是私有的。


谢谢,

Brett


尼斯。谢谢。


Brett

" Ken Tucker [MVP]" < VB *** @ bellsouth.net>在留言中写道

新闻:Op *************** @ TK2MSFTNGP15.phx.gbl ...



我会创建一个对类或表单私有的变量。
这样所有子例程和函数都可以使用它。它不会在表格或类别之外进行访问。

Ken
-----------
Brett < no@spam.net>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
如果我有很多硬编码值,如文件路径,文件名,超时,
等,哪里是定义它们的最佳位置?意思是,在某些事情需要改变的情况下,而不是运行可能包含这些值的所有子函数或函数,我想要一个地方来改变它们。 />并将更改反映在使用这些值的子函数或函数中。我想避免使用全局变量;保持这些价值仅限于使用它们的那些潜水员。

谢谢,
Brett



将混合使用一些共享变量。意思是,我将在一个类中定义

变量,这些变量也将在其他类或表单中使用。 />
对于那些共享变量,我应该创建一个只包含

的类吗?这提供了一个更改它们的位置,并通过使用它们的表单/类将这些更改级联为




Brett

" Ken Tucker [MVP]" < VB *** @ bellsouth.net>在留言中写道

新闻:Op *************** @ TK2MSFTNGP15.phx.gbl ...



我会创建一个对类或表单私有的变量。
这样所有子例程和函数都可以使用它。它不会在表格或类别之外进行访问。

Ken
-----------
Brett < no@spam.net>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
如果我有很多硬编码值,如文件路径,文件名,超时,
等,哪里是定义它们的最佳位置?意思是,在某些事情需要改变的情况下,而不是运行可能包含这些值的所有子函数或函数,我想要一个地方来改变它们。 />并将更改反映在使用这些值的子函数或函数中。我想避免使用全局变量;保持这些价值仅限于使用它们的那些潜水员。

谢谢,
Brett



If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I''d like one place to change them
and have that changed reflected in the subs or functions that use those
values. I''d like to avoid globals; keeping the values private to only those
subs or functions using them.

Thanks,
Brett

解决方案

Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I''d like one place to change them
and have that changed reflected in the subs or functions that use those
values. I''d like to avoid globals; keeping the values private to only those
subs or functions using them.

Thanks,
Brett


Nice. Thanks.

Brett
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Op***************@TK2MSFTNGP15.phx.gbl...

Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case
something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I''d like one place to change them
and have that changed reflected in the subs or functions that use those
values. I''d like to avoid globals; keeping the values private to only
those
subs or functions using them.

Thanks,
Brett



There will be some shared variables mixed in. Meaning, I''ll define
variables in one class that will also be used in other classes or forms.
For those shared variables, should I just create a class that only houses
them? This provides one place to change them and have those changes cascade
through out forms/classes that are using them.

Brett

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Op***************@TK2MSFTNGP15.phx.gbl...

Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case
something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I''d like one place to change them
and have that changed reflected in the subs or functions that use those
values. I''d like to avoid globals; keeping the values private to only
those
subs or functions using them.

Thanks,
Brett



这篇关于定义硬编码值的最佳位置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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