|
-
Sep 16th, 2017, 06:54 PM
#1
Thread Starter
Frenzied Member
Measurment Converstions
i have an 08 project that has 50 forms and 28 modules that outputs hundreds if not thousands of metric measurements with labels showing "lm" for lineal meters or "m2" for square meters.
I am wanting to also have the project output imperial measurements as in "ft" feet and "sqft" square feet.
I know i can write hundreds of lines of code like below to do this:
Code:
if checkbox_imperial.checked
xxlbl.text = sqfeet
end if
But am hoping there will be a easier way before i begin.
What is the typical way to handle both metric and imperial measurements for different eviroments?
thx in advance...
-
Sep 16th, 2017, 08:07 PM
#2
Re: Measurment Converstions
feet = ((metres * 100) / 2.25 / 12)
You'll need to show some code for a useful answer, but i'm not sure how you're hoping to shoehorn imperial conversions in there...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 16th, 2017, 08:19 PM
#3
Re: Measurment Converstions
Do you have hundreds or thousands of output labels?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 16th, 2017, 08:21 PM
#4
Thread Starter
Frenzied Member
Re: Measurment Converstions
at minimum hundreds on the 50 odd forms.
-
Sep 16th, 2017, 08:21 PM
#5
Thread Starter
Frenzied Member
Re: Measurment Converstions
i can do the conversion was more after the correct way its usually handled.
-
Sep 16th, 2017, 08:31 PM
#6
Re: Measurment Converstions
How about this:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Label1.TextChanged, AddressOf ClassHandlers.Labels_TextChanged
End Sub
End Class
Code:
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Label1.TextChanged, AddressOf ClassHandlers.Labels_TextChanged
End Sub
End Class
Code:
Public Class ClassHandlers
'you need to set this on checkbox_imperial.checkedchanged
Public Shared convert As Boolean
Public Shared Sub Labels_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If convert Then
Dim lbl As Label = DirectCast(sender, Label)
If lbl.Text.EndsWith("lm") Then
Dim d As Decimal
If Decimal.TryParse(lbl.Text.Replace("lm", ""), d) Then
'conversion code here and output back to the same label
End If
End If
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 16th, 2017, 08:42 PM
#7
Re: Measurment Converstions
There might be a more efficient answer, but I really can't think how...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 16th, 2017, 09:17 PM
#8
Thread Starter
Frenzied Member
Re: Measurment Converstions
 Originally Posted by .paul.
There might be a more efficient answer, but I really can't think how...
thx heaps for that .paul i will check it thoroughly
-
Sep 16th, 2017, 10:18 PM
#9
Re: Measurment Converstions
As far as your form will contains such huge amount of labels, it is better to create your own Label and encapsulate required conversions.
Here is a working code you can start with
VB.NET Code:
Option Strict On
Option Explicit On
Public Class MyLabel
Inherits System.Windows.Forms.Label
Public Enum Units
Centimetre
Meter
'
Inch
Foot
End Enum
Private _Unit As Units
Public Property Unit() As Units
Get
Return _Unit
End Get
Set(ByVal value As Units)
_Unit = value
Select Case value
Case Units.Meter ' it is the default, so no conversion needed
Me.Text = CStr(Me.Value) & " m"
Case Units.Centimetre
Me.Text = CStr(Me.Value * 100) & " cm"
Case Units.Foot
Me.Text = CStr(Me.Value / 0.3048) & " ft"
Case Units.Inch
Me.Text = CStr(Me.Value / 0.0254) & " in"
End Select
End Set
End Property
Public Sub New()
Me.Unit = Units.Meter ' set default unit.
End Sub
Private _Value As Decimal
Public Property Value() As Decimal
Get
Return _Value
End Get
Set(ByVal value As Decimal)
_Value = value
Me.Text = CStr(value) & " m"
End Set
End Property
End Class
Usage
VB.NET Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MyLabel1.Value = 10 ' meters
RadioButton3.Checked = True ' convert to feet
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Meter
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Centimetre
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Foot
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Inch
End Sub
End Class
-
Sep 17th, 2017, 06:01 AM
#10
Re: Measurment Converstions
Hi,
why not in diffrent Datagridviews?
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|