单位转换为类还是模块? [英] Unit conversion as class or module?

查看:105
本文介绍了单位转换为类还是模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个适用于绘图包的应用程序.此工程包包含数据库单位中的几种单位类型

I made a application that works with a drawing package. This drawing package holds several unit types that are in database units

  • 千克质量
  • 厘米长度
  • 弧度角度
  • 以秒为单位的时间

当前,我的应用程序已在维度获取"页面上实现了单位转换.就像下面的

Currently my application has unit conversion implemented on the "dimension Get" like the following

' Get the value and convert it to millimeters
Dim oValue as double
oValue = parameter.value * 10

 但是我想创建一个更专业"的网站和可读格式.像下面的

 But I would like to create a more "professional" and read-able format. Like the following

' Get the value and convert it to millimeters
Dim oValue as double
oValue = UnitConversion(parameter.value, BaseLengthUnitType, MillimeterUnitType)

创建此转换器的最佳实践是什么?使用类对象或模块?我想在需要时在许多不同的类中使用这些转换.

What is the best practice for this creating this converter? Using a class object or module? I would like to use these conversions in alot of different classes when required.

推荐答案

您好,

感谢您的快速反应.我是一个自我学习"的人程序员想(好吧,我是他们的任务,使他们自己编写一些内部应用程序而没有任何相关知识),而且我总是渴望从示例中学习更多.你能证明 您将如何开始这样的课程并从Sub调用它?

Thanks for the rapid response. I'm a "self learning" programmer wannabe ( well i'm the person they gave the task to make some in house application without any education about it ) and I am always eager to learn more from examples. Could you show how you would start such a class and call it from a Sub?

Public Class UnitConvert

Public LengthUnitType as LengthUnitTypeEnum
Public Enum LengthUnitTypeEnum

    Millimeter
    Centimer
    Meter

End Enum

Public Function ConvertLengthBaseUnit(Byval ToUnitType as LengthUnitTypeEnum) as double

    ' Some cool stuff here

End Function

End Class


这篇关于单位转换为类还是模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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