Saving Code and saving time.
-
Hello, What practice is best if you are trying to save coping and pasting thousands of lines of reusable code. Currently I have all the code in a module. I have included an example. The problem I'm having is; I cannot retrieve any information from a calling sub in a form. I'm trying to have a combo box with the size listing and I want to retrieve a specific piece of information when selecting a size. Like the "HEIGHT". I have to use Class Library's for my projects to create dll files that will work with my 3D modeling program. I've read some about creating class objects but not sure about how to accomplish that or if it's really what I need to do. If someone could shed some light on my dilemma, I would really appreciate it. Module Module1 Public Function RMT(ByVal RMTSize As String, Optional ByRef WIDTH As Double = 0, Optional ByRef HEIGHT As Double = 0, Optional ByRef WALLTH As Double = 0, Optional ByRef OUTRAD As Double = 0) As Double Select Case RMTSize Case "3 x 2 x 3/16" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.1875 OUTRAD = 0.375 Case "3 x 2 x 1/4" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.25 OUTRAD = 0.5
-
Hello, What practice is best if you are trying to save coping and pasting thousands of lines of reusable code. Currently I have all the code in a module. I have included an example. The problem I'm having is; I cannot retrieve any information from a calling sub in a form. I'm trying to have a combo box with the size listing and I want to retrieve a specific piece of information when selecting a size. Like the "HEIGHT". I have to use Class Library's for my projects to create dll files that will work with my 3D modeling program. I've read some about creating class objects but not sure about how to accomplish that or if it's really what I need to do. If someone could shed some light on my dilemma, I would really appreciate it. Module Module1 Public Function RMT(ByVal RMTSize As String, Optional ByRef WIDTH As Double = 0, Optional ByRef HEIGHT As Double = 0, Optional ByRef WALLTH As Double = 0, Optional ByRef OUTRAD As Double = 0) As Double Select Case RMTSize Case "3 x 2 x 3/16" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.1875 OUTRAD = 0.375 Case "3 x 2 x 1/4" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.25 OUTRAD = 0.5
use an enum to extract the specific piece
public enum Sizes
[width]
[height]
wallth
outrad
end enumpublic function rmt(rmtsize as string, iSizes as Sizes) as double
select case rmtsize
case "3 x 2 x 3/16"
select case iSizes
case sizes.height: return 2.0
.
.
.
end select
.
.
.
end select
end function'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
Hello, What practice is best if you are trying to save coping and pasting thousands of lines of reusable code. Currently I have all the code in a module. I have included an example. The problem I'm having is; I cannot retrieve any information from a calling sub in a form. I'm trying to have a combo box with the size listing and I want to retrieve a specific piece of information when selecting a size. Like the "HEIGHT". I have to use Class Library's for my projects to create dll files that will work with my 3D modeling program. I've read some about creating class objects but not sure about how to accomplish that or if it's really what I need to do. If someone could shed some light on my dilemma, I would really appreciate it. Module Module1 Public Function RMT(ByVal RMTSize As String, Optional ByRef WIDTH As Double = 0, Optional ByRef HEIGHT As Double = 0, Optional ByRef WALLTH As Double = 0, Optional ByRef OUTRAD As Double = 0) As Double Select Case RMTSize Case "3 x 2 x 3/16" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.1875 OUTRAD = 0.375 Case "3 x 2 x 1/4" WIDTH = 3.0 HEIGHT = 2.0 WALLTH = 0.25 OUTRAD = 0.5
It looks like you are trying to parse the string? You can make a class that contains the information from the string:
Public Class RmtInfo
Private _width As Double
Private _height As Double
Private _wallThickness As Double
Private _outerRadius As DoublePublic Sub New(size As String)
Dim s As String() = size.Split(New Char() { "x"C, "/"C})
_width = Double.Parse(s(0).Trim())
_height = Double.Parse(s(1).Trim())
_wallThickness = Double.Parse(s(2).Trim()) / Double.Parse(s(3).Trim())
_outerRadius = _wallThickness * 2
End SubPublic ReadOnly Property Width As Double
Get
Return _width
End Get
End PropertyPublic ReadOnly Property Height
Get
Return _height
End Get
End PropertyPublic ReadOnly Property WallThickness
Get
Return _wallThickness
End Get
End PropertyPublic ReadOnly Property OuterRadius
Get
Return _outerRadius
End Get
End PropertyEnd Class
Example:
Dim info As New RmtInfo("3 x 2 x 3/16")
MessageBox.Show("The height is " + info.Height.ToString())Despite everything, the person most likely to be fooling you next is yourself.