有没有人有为VBA写的最喜欢的单位转换函数? [英] Does anyone have a favorite Units Conversion Function written for VBA?

查看:59
本文介绍了有没有人有为VBA写的最喜欢的单位转换函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想在Access Query期间执行度量单位的转换。这是我想要如何使用该函数的一些SQL的示例:

展开 | 选择 | Wrap | 行号

解决方案

我不确定你的问题有一个简单的答案,但这是我提出的问题。我不是说它是最有效的解决方案,但它仍然是一种解决方案。这里是:

  1. 创建一个包含独特计量单位类型的表格,例如:

    UOM_ID单位

    1码

    2英尺

    3英寸

    4 Fahrenheit

    5摄氏度
  2. 创建链接{1 ==>在tblUOMTypes中的[UOM_ID]和[ExchangerType]之间以及tblHeatExchangeSizingData中的[CapacityUnitOfMeasure]之间很多。前两个字段将存储指示特定计量单位类型的LONG值。
  3. 创建一个将接受三个参数的公共函数(ConvertToCurrentUnits):[Capacity],[CapacityUnitOfMeasure]和[ExchangerType]。
  4. 在此函数中创建逻辑,用于分析这些参数并生成相应的结果。同样,这解决了使用批量代码方法的问题,可能不是最有效的方法。该代码需要扩展以允许将来进行转换。
  5. 现在我已经完全困惑了您,请下载附件以获得有关如何完成此操作的第一手资料。

附加文件
UOM.zip (27.3 KB,93 views )


谢谢ADezii,


你提出的几乎是一个与我使用的方法完全相同,这让我感觉非常好。我知道它不会特别快,对于这个应用程序来说很好。


我发布我的测试版本,或者其他任何人想看看是什么我想出来了。这只是我希望拥有的原型,但它看起来很相似:

展开 | 选择 | Wrap | 行号


存储如何:< ol style =list-style-type:upper-alpha>
  • UoM的名称。
  • 此UoM与X ^ 1相关的单位数。
  • UoM的类型^ 2(可选)。
  • ^ 1 X是相同类型的UoM,由设计者任意分配,允许相同类型的UoM之间的相关性。它通常是表格所涵盖的UoM之一,但不一定是这种情况。

    ^ 2如果使用,这只是允许例程返回调用错误的类型通过的两个UoM不一样。

    同一个UoM的多个名称可以通过使用多个(或其他重复的)记录来处理。


    例行程序会有一个调用格式:

    展开 | 选择 | Wrap | 行号


    I have an application where I want to perform a conversion on a unit of measure during an Access Query. This is an example of some SQL of how I would like to use the function:

    Expand|Select|Wrap|Line Numbers

    解决方案

    I am not sure that there is a simple answer to your question but here is something that I came up with. I''m not saying that it is the most efficient solution, but it is a solution nonetheless. Here goes:

    1. Create a Table consisting of Unique Unit of Measure Types such as:
      UOM_ID Unit
      1 Yards
      2 Feet
      3 Inches
      4 Fahrenheit
      5 Celsius
    2. Create a Link {1 ==> MANY} between [UOM_ID] in tblUOMTypes and [ExchangerType] and [CapacityUnitOfMeasure] in tblHeatExchangeSizingData. The prior two Fields will store LONG Values indicating specific Unit of Measure Types.
    3. Create a Public Function (ConvertToCurrentUnits) that will accept three arguments: [Capacity], [CapacityUnitOfMeasure], and [ExchangerType].
    4. Create Logic within this Function that will analyze these Arguments and generate the appropriate Results. Again, this resolves the problem using a Bulk Code approach and probably not the most efficient approach. The Code will need to be expanded to allow for future conversions.
    5. Now that I have totally confused you, download the Attachment to get a first hand view on how this can be done.

    Attached Files
    UOM.zip (27.3 KB, 93 views)


    Thanks ADezii,

    You came up with pretty much an identical approach as the one I was using, which makes me feel really a good about it. I know it''s not going to be particularly fast and for this application that is fine.

    I''m posting my test version incase you or anyone else would like to see what I came up with. This is just the prototype for what I hope to have, but it''s neat seeing the similarities:

    Expand|Select|Wrap|Line Numbers


    How about storing :

    1. The name of the UoM.
    2. The number of units of X^1 this UoM relates to.
    3. Type of UoM^2 (Optional).

    ^1 X is a UoM of the same type, assigned arbitrarily by the designer, which allows correlations between UoMs of the same type. It will typically be one of the UoMs covered by the table but this need not necessarily be the case.
    ^2 If used, this is only necessary to allow the routine to return a calling error if the types of the two UoMs passed are not the same.
    Multiple names for the same UoM can be handled by using multiple, otherwise duplicate, records.

    The routine would have a call format of :

    Expand|Select|Wrap|Line Numbers


    这篇关于有没有人有为VBA写的最喜欢的单位转换函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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