Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Saving Code and saving time.

Saving Code and saving time.

Scheduled Pinned Locked Moved Visual Basic
tutorialhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Herrwolf1
    wrote on last edited by
    #1

    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

    N G 2 Replies Last reply
    0
    • H Herrwolf1

      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

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      use an enum to extract the specific piece

      public enum Sizes
      [width]
      [height]
      wallth
      outrad
      end enum

      public 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

      1 Reply Last reply
      0
      • H Herrwolf1

        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

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        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 Double

        Public 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 Sub

        Public ReadOnly Property Width As Double
        Get
        Return _width
        End Get
        End Property

        Public ReadOnly Property Height
        Get
        Return _height
        End Get
        End Property

        Public ReadOnly Property WallThickness
        Get
        Return _wallThickness
        End Get
        End Property

        Public ReadOnly Property OuterRadius
        Get
        Return _outerRadius
        End Get
        End Property

        End 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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups