Option Strict On Imports System.io Imports System.Drawing.Printing ' Persson Technologies Metric Conversion Program ' December 29, 2003 ' ' Design notes ' ' How best to simplify the design of the program? ' It was thought that we could start with the fact that ' each inch is 2.54 centimeters and each centimeter is ' 0.3937 inches. Once we have an input we can easily ' convert down to centimeters and start from there to fill ' in all values. ' However, when the "calculate" button is pressed, how do we ' know what the input value represents and what output value ' to display on the form? ' A case statement for the input unit of measure with a conversion ' multiplier would work well. The multiplier would get us down ' to a centimeter so we can do all calculations from there ' A case statement for the output would be in a subroutine called ' by the calculate routine. Therefore, the calculate routine ' would have one calculate subroutine for each type of measure ' and a display subroutine for each type of measurement ' Public Class Form1 Inherits System.Windows.Forms.Form Const strCopyWrite As String = " Copyright 2004, 2005 by Persson Technologies, all rights reserved " Dim intNumberOfOutputDecimals As Integer = 2 ' Global Constants - for conversion values, down and up 'The conversion constants take us from the standard internal measurement to the desired output Const decConversionInches As Decimal = 0.3937D Const decConversionFeet As Decimal = 0.0328084D Const decConversionYards As Decimal = 0.0109361D Const decConversionMiles As Decimal = 0.0000062137D Const decConversionCentimeters As Decimal = 1D Const decConversionMeters As Decimal = 0.01D Const decConversionKilometers As Decimal = 0.00001D Const decConversionFluidOunces As Decimal = 0.033814D Const decConversionPints As Decimal = 0.002113375D Const decConversionCups As Decimal = 0.00422675D Const decConversionQuarts As Decimal = 0.0010566875D Const decConversionGallons As Decimal = 0.000264171875D Const decConversionMilliliters As Decimal = 1D Const decConversionLiters As Decimal = 0.001D Const decConversionOunces As Decimal = 0.0352736D Const decConversionPounds As Decimal = 0.0022046D Const decConversionGrams As Decimal = 1 Const decConversionKilograms As Decimal = 0.001D 'The downconversion constants take us from the input to the standard internal measurement Const decDownConversionInches As Decimal = 2.54D Const decDownConversionFeet As Decimal = 30.48D Const decDownConversionYards As Decimal = 91.44D Const decDownConversionMiles As Decimal = 160934.4D Const decDownConversionCentimeters As Decimal = 1 Const decDownConversionMeters As Decimal = 100 Const decDownConversionKilometers As Decimal = 100000 Const decDownConversionFluidOunces As Decimal = 29.5735297D Const decDownConversionPints As Decimal = 473.1764752D Const decDownConversionCups As Decimal = 236.5882376D Const decDownConversionQuarts As Decimal = 946.3529504D Const decDownConversionGallons As Decimal = 3785.4118016D Const decDownConversionMilliliters As Decimal = 1 Const decDownConversionLiters As Decimal = 1000 Const decDownConversionOunces As Decimal = 28.35D Const decDownConversionPounds As Decimal = 453.6D Const decDownConversionGrams As Decimal = 1 Const decDownConversionKilograms As Decimal = 1000 ' Global Variables - these receive the conversion output Dim decInches As Decimal Dim decFeet As Decimal Dim decYards As Decimal Dim decMiles As Decimal Dim decCentimeters As Decimal Dim decMeters As Decimal Dim decKilometers As Decimal Dim decFluidOunces As Decimal Dim decPints As Decimal Dim decCups As Decimal Dim decQuarts As Decimal Dim decGallons As Decimal Dim decMilliliters As Decimal Dim decLiters As Decimal Dim decOunces As Decimal Dim decPounds As Decimal Dim decGrams As Decimal Dim decKilograms As Decimal Dim decFahrenheit As Decimal Dim decCelsius As Decimal 'Values for global array lists for conversion chart Dim arlChartFromValuesArray, arlChartToValuesArray As New ArrayList Dim intChartArrayCounter, intChartArrayEntries As Integer 'Values for report writing Dim intReportPageCounter As Integer #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents GrpMeasurementCategory As System.Windows.Forms.GroupBox Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents LblConversionFrom As System.Windows.Forms.Label Friend WithEvents txtConversionFrom As System.Windows.Forms.TextBox Friend WithEvents BtnConvert As System.Windows.Forms.Button Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtChartFrom As System.Windows.Forms.TextBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtChartTo As System.Windows.Forms.TextBox Friend WithEvents CmbChartIncrement As System.Windows.Forms.ComboBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents RbtLength As System.Windows.Forms.RadioButton Friend WithEvents RbtVolume As System.Windows.Forms.RadioButton Friend WithEvents RbtTemperature As System.Windows.Forms.RadioButton Friend WithEvents RbtWeight As System.Windows.Forms.RadioButton Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents CmbFromUnit As System.Windows.Forms.ComboBox Friend WithEvents CmbToUnit As System.Windows.Forms.ComboBox Friend WithEvents GrpUnitSelection As System.Windows.Forms.GroupBox Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents LblConversionTo As System.Windows.Forms.Label Friend WithEvents LblConversionOut As System.Windows.Forms.Label Friend WithEvents BtnChart As System.Windows.Forms.Button Friend WithEvents MnuFile As System.Windows.Forms.MenuItem Friend WithEvents MnuSaveChart As System.Windows.Forms.MenuItem Friend WithEvents MnuExit As System.Windows.Forms.MenuItem Friend WithEvents MnuHelp As System.Windows.Forms.MenuItem Friend WithEvents mnuHowToUse As System.Windows.Forms.MenuItem Friend WithEvents mnuVersionHistory As System.Windows.Forms.MenuItem Friend WithEvents mnuFAQs As System.Windows.Forms.MenuItem Friend WithEvents mnuAbout As System.Windows.Forms.MenuItem Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents mnuPrecision As System.Windows.Forms.MenuItem Friend WithEvents grpMiddle As System.Windows.Forms.GroupBox Friend WithEvents grpTitle As System.Windows.Forms.GroupBox Friend WithEvents dtgOutput As System.Windows.Forms.DataGrid Friend WithEvents mnuPrintChart As System.Windows.Forms.MenuItem Friend WithEvents mnuPrintPreview As System.Windows.Forms.MenuItem Friend WithEvents GrpProduceChart As System.Windows.Forms.GroupBox Friend WithEvents grpChart As System.Windows.Forms.GroupBox Friend WithEvents mnuDecimals0 As System.Windows.Forms.MenuItem Friend WithEvents mnuDecimals1 As System.Windows.Forms.MenuItem Friend WithEvents mnuDecimals2 As System.Windows.Forms.MenuItem Friend WithEvents mnuDecimals3 As System.Windows.Forms.MenuItem Friend WithEvents mnuDecimals4 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem Friend WithEvents mnuCopy As System.Windows.Forms.MenuItem Friend WithEvents mnuPaste As System.Windows.Forms.MenuItem Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Label1 = New System.Windows.Forms.Label Me.GrpMeasurementCategory = New System.Windows.Forms.GroupBox Me.RbtWeight = New System.Windows.Forms.RadioButton Me.RbtTemperature = New System.Windows.Forms.RadioButton Me.RbtVolume = New System.Windows.Forms.RadioButton Me.RbtLength = New System.Windows.Forms.RadioButton Me.MainMenu1 = New System.Windows.Forms.MainMenu Me.MnuFile = New System.Windows.Forms.MenuItem Me.MnuSaveChart = New System.Windows.Forms.MenuItem Me.mnuPrintPreview = New System.Windows.Forms.MenuItem Me.mnuPrintChart = New System.Windows.Forms.MenuItem Me.MnuExit = New System.Windows.Forms.MenuItem Me.MenuItem1 = New System.Windows.Forms.MenuItem Me.mnuPrecision = New System.Windows.Forms.MenuItem Me.mnuDecimals0 = New System.Windows.Forms.MenuItem Me.mnuDecimals1 = New System.Windows.Forms.MenuItem Me.mnuDecimals2 = New System.Windows.Forms.MenuItem Me.mnuDecimals3 = New System.Windows.Forms.MenuItem Me.mnuDecimals4 = New System.Windows.Forms.MenuItem Me.MnuHelp = New System.Windows.Forms.MenuItem Me.mnuHowToUse = New System.Windows.Forms.MenuItem Me.mnuVersionHistory = New System.Windows.Forms.MenuItem Me.mnuFAQs = New System.Windows.Forms.MenuItem Me.mnuAbout = New System.Windows.Forms.MenuItem Me.LblConversionFrom = New System.Windows.Forms.Label Me.txtConversionFrom = New System.Windows.Forms.TextBox Me.LblConversionTo = New System.Windows.Forms.Label Me.LblConversionOut = New System.Windows.Forms.Label Me.BtnConvert = New System.Windows.Forms.Button Me.GrpProduceChart = New System.Windows.Forms.GroupBox Me.BtnChart = New System.Windows.Forms.Button Me.Label5 = New System.Windows.Forms.Label Me.CmbChartIncrement = New System.Windows.Forms.ComboBox Me.TxtChartTo = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.TxtChartFrom = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.dtgOutput = New System.Windows.Forms.DataGrid Me.Label6 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.CmbFromUnit = New System.Windows.Forms.ComboBox Me.CmbToUnit = New System.Windows.Forms.ComboBox Me.GrpUnitSelection = New System.Windows.Forms.GroupBox Me.Label7 = New System.Windows.Forms.Label Me.Label8 = New System.Windows.Forms.Label Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog Me.grpMiddle = New System.Windows.Forms.GroupBox Me.grpTitle = New System.Windows.Forms.GroupBox Me.grpChart = New System.Windows.Forms.GroupBox Me.MenuItem2 = New System.Windows.Forms.MenuItem Me.mnuCopy = New System.Windows.Forms.MenuItem Me.mnuPaste = New System.Windows.Forms.MenuItem Me.GrpMeasurementCategory.SuspendLayout() Me.GrpProduceChart.SuspendLayout() CType(Me.dtgOutput, System.ComponentModel.ISupportInitialize).BeginInit() Me.GrpUnitSelection.SuspendLayout() Me.grpMiddle.SuspendLayout() Me.grpTitle.SuspendLayout() Me.grpChart.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.ForeColor = System.Drawing.Color.Yellow Me.Label1.Location = New System.Drawing.Point(40, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(520, 32) Me.Label1.TabIndex = 0 Me.Label1.Text = "Persson Technologies Metric Conversion Program" ' 'GrpMeasurementCategory ' Me.GrpMeasurementCategory.Controls.Add(Me.RbtWeight) Me.GrpMeasurementCategory.Controls.Add(Me.RbtTemperature) Me.GrpMeasurementCategory.Controls.Add(Me.RbtVolume) Me.GrpMeasurementCategory.Controls.Add(Me.RbtLength) Me.GrpMeasurementCategory.Location = New System.Drawing.Point(0, 56) Me.GrpMeasurementCategory.Name = "GrpMeasurementCategory" Me.GrpMeasurementCategory.Size = New System.Drawing.Size(184, 144) Me.GrpMeasurementCategory.TabIndex = 1 Me.GrpMeasurementCategory.TabStop = False Me.GrpMeasurementCategory.Text = "Measurement Category" ' 'RbtWeight ' Me.RbtWeight.Location = New System.Drawing.Point(16, 82) Me.RbtWeight.Name = "RbtWeight" Me.RbtWeight.TabIndex = 3 Me.RbtWeight.Text = "Weight" ' 'RbtTemperature ' Me.RbtTemperature.Location = New System.Drawing.Point(16, 111) Me.RbtTemperature.Name = "RbtTemperature" Me.RbtTemperature.TabIndex = 2 Me.RbtTemperature.Text = "Temperature" ' 'RbtVolume ' Me.RbtVolume.Location = New System.Drawing.Point(16, 53) Me.RbtVolume.Name = "RbtVolume" Me.RbtVolume.TabIndex = 1 Me.RbtVolume.Text = "Liquid Volume" ' 'RbtLength ' Me.RbtLength.Location = New System.Drawing.Point(16, 24) Me.RbtLength.Name = "RbtLength" Me.RbtLength.TabIndex = 0 Me.RbtLength.Text = "Length/Height" ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuFile, Me.MenuItem2, Me.MenuItem1, Me.MnuHelp}) ' 'MnuFile ' Me.MnuFile.Index = 0 Me.MnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuSaveChart, Me.mnuPrintPreview, Me.mnuPrintChart, Me.MnuExit}) Me.MnuFile.Text = "&File" ' 'MnuSaveChart ' Me.MnuSaveChart.Index = 0 Me.MnuSaveChart.Text = "&Save Chart" ' 'mnuPrintPreview ' Me.mnuPrintPreview.Index = 1 Me.mnuPrintPreview.Text = "P&rint Preview" ' 'mnuPrintChart ' Me.mnuPrintChart.Index = 2 Me.mnuPrintChart.Text = "&Print Chart" ' 'MnuExit ' Me.MnuExit.Index = 3 Me.MnuExit.Text = "E&xit" ' 'MenuItem1 ' Me.MenuItem1.Index = 2 Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuPrecision}) Me.MenuItem1.Text = "&Settings" ' 'mnuPrecision ' Me.mnuPrecision.Index = 0 Me.mnuPrecision.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuDecimals0, Me.mnuDecimals1, Me.mnuDecimals2, Me.mnuDecimals3, Me.mnuDecimals4}) Me.mnuPrecision.Text = "&Change number of decimals" ' 'mnuDecimals0 ' Me.mnuDecimals0.Index = 0 Me.mnuDecimals0.Text = "0" ' 'mnuDecimals1 ' Me.mnuDecimals1.Index = 1 Me.mnuDecimals1.Text = "1" ' 'mnuDecimals2 ' Me.mnuDecimals2.Index = 2 Me.mnuDecimals2.Text = "2" ' 'mnuDecimals3 ' Me.mnuDecimals3.Index = 3 Me.mnuDecimals3.Text = "3" ' 'mnuDecimals4 ' Me.mnuDecimals4.Index = 4 Me.mnuDecimals4.Text = "4" ' 'MnuHelp ' Me.MnuHelp.Index = 3 Me.MnuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuHowToUse, Me.mnuVersionHistory, Me.mnuFAQs, Me.mnuAbout}) Me.MnuHelp.Text = "&Help" ' 'mnuHowToUse ' Me.mnuHowToUse.Index = 0 Me.mnuHowToUse.Text = "&How To Use" ' 'mnuVersionHistory ' Me.mnuVersionHistory.Index = 1 Me.mnuVersionHistory.Text = "&Version History" ' 'mnuFAQs ' Me.mnuFAQs.Index = 2 Me.mnuFAQs.Text = "&FAQs" ' 'mnuAbout ' Me.mnuAbout.Index = 3 Me.mnuAbout.Text = "&About" ' 'LblConversionFrom ' Me.LblConversionFrom.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblConversionFrom.Location = New System.Drawing.Point(64, 24) Me.LblConversionFrom.Name = "LblConversionFrom" Me.LblConversionFrom.Size = New System.Drawing.Size(112, 23) Me.LblConversionFrom.TabIndex = 5 Me.LblConversionFrom.Text = "Inches" ' 'txtConversionFrom ' Me.txtConversionFrom.Location = New System.Drawing.Point(16, 48) Me.txtConversionFrom.MaxLength = 20 Me.txtConversionFrom.Name = "txtConversionFrom" Me.txtConversionFrom.Size = New System.Drawing.Size(128, 20) Me.txtConversionFrom.TabIndex = 6 Me.txtConversionFrom.Text = "" ' 'LblConversionTo ' Me.LblConversionTo.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblConversionTo.Location = New System.Drawing.Point(56, 160) Me.LblConversionTo.Name = "LblConversionTo" Me.LblConversionTo.Size = New System.Drawing.Size(104, 23) Me.LblConversionTo.TabIndex = 7 Me.LblConversionTo.Text = "Inches" ' 'LblConversionOut ' Me.LblConversionOut.BackColor = System.Drawing.Color.White Me.LblConversionOut.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.LblConversionOut.Location = New System.Drawing.Point(16, 184) Me.LblConversionOut.Name = "LblConversionOut" Me.LblConversionOut.Size = New System.Drawing.Size(128, 24) Me.LblConversionOut.TabIndex = 8 ' 'BtnConvert ' Me.BtnConvert.BackColor = System.Drawing.Color.Bisque Me.BtnConvert.Location = New System.Drawing.Point(16, 104) Me.BtnConvert.Name = "BtnConvert" Me.BtnConvert.Size = New System.Drawing.Size(128, 32) Me.BtnConvert.TabIndex = 9 Me.BtnConvert.Text = "Convert Now" ' 'GrpProduceChart ' Me.GrpProduceChart.Controls.Add(Me.BtnChart) Me.GrpProduceChart.Controls.Add(Me.Label5) Me.GrpProduceChart.Controls.Add(Me.CmbChartIncrement) Me.GrpProduceChart.Controls.Add(Me.TxtChartTo) Me.GrpProduceChart.Controls.Add(Me.Label2) Me.GrpProduceChart.Controls.Add(Me.TxtChartFrom) Me.GrpProduceChart.Controls.Add(Me.Label4) Me.GrpProduceChart.Location = New System.Drawing.Point(368, 56) Me.GrpProduceChart.Name = "GrpProduceChart" Me.GrpProduceChart.Size = New System.Drawing.Size(248, 128) Me.GrpProduceChart.TabIndex = 10 Me.GrpProduceChart.TabStop = False Me.GrpProduceChart.Text = "Produce Chart" ' 'BtnChart ' Me.BtnChart.BackColor = System.Drawing.Color.Bisque Me.BtnChart.Location = New System.Drawing.Point(16, 88) Me.BtnChart.Name = "BtnChart" Me.BtnChart.Size = New System.Drawing.Size(216, 32) Me.BtnChart.TabIndex = 7 Me.BtnChart.Text = "Create Chart" ' 'Label5 ' Me.Label5.Location = New System.Drawing.Point(136, 24) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(72, 16) Me.Label5.TabIndex = 5 Me.Label5.Text = "Increment" ' 'CmbChartIncrement ' Me.CmbChartIncrement.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.CmbChartIncrement.Location = New System.Drawing.Point(136, 48) Me.CmbChartIncrement.Name = "CmbChartIncrement" Me.CmbChartIncrement.Size = New System.Drawing.Size(80, 21) Me.CmbChartIncrement.TabIndex = 4 ' 'TxtChartTo ' Me.TxtChartTo.Location = New System.Drawing.Point(56, 56) Me.TxtChartTo.MaxLength = 10 Me.TxtChartTo.Name = "TxtChartTo" Me.TxtChartTo.Size = New System.Drawing.Size(56, 20) Me.TxtChartTo.TabIndex = 3 Me.TxtChartTo.Text = "" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(16, 56) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(32, 23) Me.Label2.TabIndex = 2 Me.Label2.Text = "To" ' 'TxtChartFrom ' Me.TxtChartFrom.Location = New System.Drawing.Point(56, 24) Me.TxtChartFrom.MaxLength = 10 Me.TxtChartFrom.Name = "TxtChartFrom" Me.TxtChartFrom.Size = New System.Drawing.Size(56, 20) Me.TxtChartFrom.TabIndex = 1 Me.TxtChartFrom.Text = "" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(16, 24) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(32, 23) Me.Label4.TabIndex = 0 Me.Label4.Text = "From" ' 'dtgOutput ' Me.dtgOutput.BackgroundColor = System.Drawing.Color.Tan Me.dtgOutput.CaptionVisible = False Me.dtgOutput.DataMember = "" Me.dtgOutput.HeaderForeColor = System.Drawing.Color.Black Me.dtgOutput.Location = New System.Drawing.Point(0, 8) Me.dtgOutput.Name = "dtgOutput" Me.dtgOutput.Size = New System.Drawing.Size(248, 208) Me.dtgOutput.TabIndex = 8 ' 'Label6 ' Me.Label6.Location = New System.Drawing.Point(8, 24) Me.Label6.Name = "Label6" Me.Label6.TabIndex = 11 Me.Label6.Text = "Convert From:" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(8, 88) Me.Label3.Name = "Label3" Me.Label3.TabIndex = 12 Me.Label3.Text = "Convert To:" ' 'CmbFromUnit ' Me.CmbFromUnit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.CmbFromUnit.Location = New System.Drawing.Point(32, 56) Me.CmbFromUnit.Name = "CmbFromUnit" Me.CmbFromUnit.Size = New System.Drawing.Size(121, 21) Me.CmbFromUnit.TabIndex = 13 ' 'CmbToUnit ' Me.CmbToUnit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.CmbToUnit.Location = New System.Drawing.Point(32, 120) Me.CmbToUnit.Name = "CmbToUnit" Me.CmbToUnit.Size = New System.Drawing.Size(121, 21) Me.CmbToUnit.TabIndex = 14 ' 'GrpUnitSelection ' Me.GrpUnitSelection.Controls.Add(Me.Label6) Me.GrpUnitSelection.Controls.Add(Me.CmbFromUnit) Me.GrpUnitSelection.Controls.Add(Me.Label3) Me.GrpUnitSelection.Controls.Add(Me.CmbToUnit) Me.GrpUnitSelection.Location = New System.Drawing.Point(0, 200) Me.GrpUnitSelection.Name = "GrpUnitSelection" Me.GrpUnitSelection.Size = New System.Drawing.Size(184, 192) Me.GrpUnitSelection.TabIndex = 15 Me.GrpUnitSelection.TabStop = False Me.GrpUnitSelection.Text = "Select Units of Measure" ' 'Label7 ' Me.Label7.Location = New System.Drawing.Point(16, 24) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(40, 23) Me.Label7.TabIndex = 16 Me.Label7.Text = "FROM" ' 'Label8 ' Me.Label8.Location = New System.Drawing.Point(16, 160) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(40, 23) Me.Label8.TabIndex = 17 Me.Label8.Text = "TO" ' 'grpMiddle ' Me.grpMiddle.Controls.Add(Me.Label7) Me.grpMiddle.Controls.Add(Me.LblConversionFrom) Me.grpMiddle.Controls.Add(Me.txtConversionFrom) Me.grpMiddle.Controls.Add(Me.BtnConvert) Me.grpMiddle.Controls.Add(Me.Label8) Me.grpMiddle.Controls.Add(Me.LblConversionTo) Me.grpMiddle.Controls.Add(Me.LblConversionOut) Me.grpMiddle.Location = New System.Drawing.Point(184, 56) Me.grpMiddle.Name = "grpMiddle" Me.grpMiddle.Size = New System.Drawing.Size(184, 336) Me.grpMiddle.TabIndex = 18 Me.grpMiddle.TabStop = False ' 'grpTitle ' Me.grpTitle.BackColor = System.Drawing.Color.DarkCyan Me.grpTitle.Controls.Add(Me.Label1) Me.grpTitle.Location = New System.Drawing.Point(0, 0) Me.grpTitle.Name = "grpTitle" Me.grpTitle.Size = New System.Drawing.Size(616, 56) Me.grpTitle.TabIndex = 19 Me.grpTitle.TabStop = False ' 'grpChart ' Me.grpChart.Controls.Add(Me.dtgOutput) Me.grpChart.Location = New System.Drawing.Point(368, 176) Me.grpChart.Name = "grpChart" Me.grpChart.Size = New System.Drawing.Size(248, 216) Me.grpChart.TabIndex = 20 Me.grpChart.TabStop = False ' 'MenuItem2 ' Me.MenuItem2.Index = 1 Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuCopy, Me.mnuPaste}) Me.MenuItem2.Text = "&Edit" ' 'mnuCopy ' Me.mnuCopy.Index = 0 Me.mnuCopy.Text = "&Copy" ' 'mnuPaste ' Me.mnuPaste.Index = 1 Me.mnuPaste.Text = "&Paste" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.BackColor = System.Drawing.Color.LightBlue Me.ClientSize = New System.Drawing.Size(616, 413) Me.Controls.Add(Me.grpChart) Me.Controls.Add(Me.grpTitle) Me.Controls.Add(Me.grpMiddle) Me.Controls.Add(Me.GrpUnitSelection) Me.Controls.Add(Me.GrpProduceChart) Me.Controls.Add(Me.GrpMeasurementCategory) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Menu = Me.MainMenu1 Me.MinimumSize = New System.Drawing.Size(624, 440) Me.Name = "Form1" Me.Text = "Persson Metric Conversion" Me.GrpMeasurementCategory.ResumeLayout(False) Me.GrpProduceChart.ResumeLayout(False) CType(Me.dtgOutput, System.ComponentModel.ISupportInitialize).EndInit() Me.GrpUnitSelection.ResumeLayout(False) Me.grpMiddle.ResumeLayout(False) Me.grpTitle.ResumeLayout(False) Me.grpChart.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region 'NOTE: Human-entered code begins here. 'TODO: Do we want to have a license file appear the first time the program is run? Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With CmbChartIncrement.Items .Add("1") .Add("2") .Add("3") .Add("5") .Add("10") .Add("15") .Add("20") End With RbtLength.Checked = True End Sub Private Sub RbtLength_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtLength.CheckedChanged CmbFromUnit.Items.Clear() CmbToUnit.Items.Clear() With CmbFromUnit.Items .Add("Inches") .Add("Feet") .Add("Yards") .Add("Miles") .Add("Centimeters") .Add("Meters") .Add("Kilometers") End With With CmbToUnit.Items .Add("Inches") .Add("Feet") .Add("Yards") .Add("Miles") .Add("Centimeters") .Add("Meters") .Add("Kilometers") End With InitializeScreen() End Sub Private Sub RbtVolume_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtVolume.CheckedChanged CmbFromUnit.Items.Clear() CmbToUnit.Items.Clear() With CmbFromUnit.Items .Add("Fluid Ounces") .Add("Pints") .Add("Cups") .Add("Quarts") .Add("Gallons") .Add("Milliliters") .Add("Liters") End With With CmbToUnit.Items .Add("Fluid Ounces") .Add("Pints") .Add("Cups") .Add("Quarts") .Add("Gallons") .Add("Milliliters") .Add("Liters") End With InitializeScreen End Sub Private Sub RbtWeight_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtWeight.CheckedChanged CmbFromUnit.Items.Clear() CmbToUnit.Items.Clear() With CmbFromUnit.Items .Add("Ounces") .Add("Pounds") .Add("Grams") .Add("Kilograms") End With With CmbToUnit.Items .Add("Ounces") .Add("Pounds") .Add("Grams") .Add("Kilograms") End With InitializeScreen End Sub Private Sub RbtTemperature_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtTemperature.CheckedChanged CmbFromUnit.Items.Clear() CmbToUnit.Items.Clear() With CmbFromUnit.Items .Add("Fahrenheit") .Add("Celsius") End With With CmbToUnit.Items .Add("Fahrenheit") .Add("Celsius") End With InitializeScreen End Sub Private Sub CmbFromUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbFromUnit.SelectedIndexChanged LblConversionFrom.Text = CStr(CmbFromUnit.SelectedItem) End Sub Private Sub CmbToUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbToUnit.SelectedIndexChanged LblConversionTo.Text = CStr(CmbToUnit.SelectedItem) End Sub Private Sub BtnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConvert.Click 'You should not proceed if the from unit = the to unit of measure If CStr(CmbFromUnit.SelectedItem) = CStr(CmbToUnit.SelectedItem) Then MsgBox("You have instructed the program to convert from " & CStr(CmbFromUnit.SelectedItem) & " to " & _ CStr(CmbFromUnit.SelectedItem) & ", please correct this and try again.") Exit Sub End If ' The conversion routine is the "heart" of the program and will ' perform the following tasks: ' 1. Determine whether we are doing length, weight, volume, or temperature ' 2. Read the input value from the screen and pass it to the ' appropriate routine for conversion ' 3. Call a routine to provide the appropriate result based ' on the desired unit of mesure If Not MainInputOkay() Then Exit Sub ClearGlobalVariables() If RbtLength.Checked Then LengthConversion(CDec(txtConversionFrom.Text)) If RbtWeight.Checked Then WeightConversion(CDec(txtConversionFrom.Text)) If RbtVolume.Checked Then VolumeConversion(CDec(txtConversionFrom.Text)) If RbtTemperature.Checked Then TemperatureConversion(CDec(txtConversionFrom.Text)) LblConversionOut.Text = FormatNumber(ChooseOutputValue(), intNumberOfOutputDecimals) End Sub ' There will be two types of routines here to provide needed functions. ' 1. Four conversion routines which will have the ability to ' downconvert the incoming number to a standard unit ' of measure and then convert to all associated units ' of measure ' 2. A routine with 4 if statements, each if statement having ' a case statement to determine the correct output ' value based on the desired unit of measure ' ' For an example as to how this would work, let's take the simple ' case of someone wanting to know how many millimeters are in ' a yard. On the screen, they choose Length, they choose yard ' to millimeter and they input a "1" for the yard. They hit the ' "convert" button. First we call the appropriate conversion ' routine and PASS it the input number. It will take the input ' number and based on the screen unit of measure will convert it ' to centimeters (the "standard internal program length"). The ' conversion routine will then generate all the output ' unit of mesures (number of miles, inches, kilometers, etc.). ' At this point a routine will be called to return the correct ' value based on the output unit of measure ' ' When producing a chart we would for each value PASS the input ' number to the conversion routine, then call the output ' determination routine ' ' Assuming we would want to create one routine to perform the ' downconversion and upconversion, it would look sometime like: ' case input of inches - use this downconversion ' case input of centimeters - use this downconversion ' case input of miles - use this downconversion ' ' convert input to standard (one line mutiplication) ' create all output values ' ' Internal standard units of measure will be centimeters, ' milliliters, and grams ' Private Sub LengthConversion(ByVal decInputValue As Decimal) Dim decDownConversion As Decimal Select Case CmbFromUnit.SelectedItem Case "Inches" decDownConversion = decDownConversionInches Case "Feet" decDownConversion = decDownConversionFeet Case "Yards" decDownConversion = decDownConversionYards Case "Miles" decDownConversion = decDownConversionMiles Case "Centimeters" decDownConversion = decDownConversionCentimeters Case "Meters" decDownConversion = decDownConversionMeters Case "Kilometers" decDownConversion = decDownConversionKilometers Case Else MsgBox("Unrecognized input unit of measure for length " & _ "in lengthconversion = " & CStr(CmbFromUnit.SelectedItem)) Exit Sub End Select Try decCentimeters = decInputValue * decDownConversion Catch ex As ArithmeticException MsgBox("Math error in Length downconversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try Try decInches = decCentimeters * decConversionInches decFeet = decCentimeters * decConversionFeet decYards = decCentimeters * decConversionYards decMiles = decCentimeters * decConversionMiles decMeters = decCentimeters * decConversionMeters decKilometers = decCentimeters * decConversionKilometers Catch ex As ArithmeticException MsgBox("Math error in Length conversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try End Sub Private Sub WeightConversion(ByVal decInputValue As Decimal) Dim decDownConversion As Decimal Select Case CmbFromUnit.SelectedItem Case "Ounces" decDownConversion = decDownConversionOunces Case "Pounds" decDownConversion = decDownConversionPounds Case "Grams" decDownConversion = decDownConversionGrams Case "Kilograms" decDownConversion = decDownConversionKilograms Case Else MsgBox("Unrecognized input unit of measure for weight " & _ "in weightconversion = " & CStr(CmbFromUnit.SelectedItem)) Exit Sub End Select Try decGrams = decInputValue * decDownConversion Catch ex As ArithmeticException MsgBox("Math error in Weight downconversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try Try decOunces = decGrams * decConversionOunces decPounds = decGrams * decConversionPounds decKilograms = decGrams * decConversionKilograms Catch ex As ArithmeticException MsgBox("Math error in Weight conversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try End Sub Private Sub VolumeConversion(ByVal decInputValue As Decimal) Dim decDownConversion As Decimal Select Case CmbFromUnit.SelectedItem Case "Fluid Ounces" decDownConversion = decDownConversionFluidOunces Case "Pints" decDownConversion = decDownConversionPints Case "Cups" decDownConversion = decDownConversionCups Case "Quarts" decDownConversion = decDownConversionQuarts Case "Gallons" decDownConversion = decDownConversionGallons Case "Milliliters" decDownConversion = decDownConversionMilliliters Case "Liters" decDownConversion = decDownConversionLiters Case Else MsgBox("Unrecognized input unit of measure for volume " & _ "in volumeconversion = " & CStr(CmbFromUnit.SelectedItem)) Exit Sub End Select Try decMilliliters = decInputValue * decDownConversion Catch ex As ArithmeticException MsgBox("Math error in Fluid downconversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try Try decFluidOunces = decMilliliters * decConversionFluidOunces decPints = decMilliliters * decConversionPints decCups = decMilliliters * decConversionCups decQuarts = decMilliliters * decConversionQuarts decGallons = decMilliliters * decConversionGallons decMilliliters = decMilliliters * decConversionMilliliters decLiters = decMilliliters * decConversionLiters Catch ex As ArithmeticException MsgBox("Math error in calculating fluid upconversion, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try End Sub Private Sub TemperatureConversion(ByVal decInputValue As Decimal) 'F = (C * 9/5) + 32 C = (F - 32) * (5/9) If CStr(CmbFromUnit.SelectedItem) = "Fahrenheit" Then decFahrenheit = decInputValue Try decCelsius = CDec(((decInputValue - 32) * (5 / 9))) Catch ex As ArithmeticException MsgBox("Math error in calculating Celsius, error" & vbNewLine & _ "is " & ex.Message) Exit Sub End Try ElseIf CStr(CmbFromUnit.SelectedItem) = "Celsius" Then decCelsius = decInputValue Try decFahrenheit = CDec(((decInputValue * (9 / 5) + 32))) Catch ex As ArithmeticException MsgBox("Math error in calculating Fahrenheit, error" & vbNewLine & _ "is " & ex.message) End Try Else MsgBox("Error - unrecognized input unit of measure in tempconvert") End If End Sub Function ChooseOutputValue() As Decimal If RbtLength.Checked Then Select Case CmbToUnit.SelectedItem Case "Inches" Return decInches Case "Feet" Return decFeet Case "Yards" Return decYards Case "Miles" Return decMiles Case "Centimeters" Return decCentimeters Case "Meters" Return decMeters Case "Kilometers" Return decKilometers Case Else MsgBox("Unrecognized output unit of measure for length " & _ "output = " & CStr(CmbToUnit.SelectedItem)) End Select End If If RbtWeight.Checked Then Select Case CmbToUnit.SelectedItem Case "Ounces" Return decOunces Case "Pounds" Return decPounds Case "Grams" Return decGrams Case "Kilograms" Return decKilograms Case Else MsgBox("Unrecognized output unit of measure for weight " & _ "output = " & CStr(CmbToUnit.SelectedItem)) End Select End If If RbtVolume.Checked Then Select Case CmbToUnit.SelectedItem Case "Fluid Ounces" Return decFluidOunces Case "Pints" Return decPints Case "Cups" Return decCups Case "Quarts" Return decQuarts Case "Gallons" Return decGallons Case "Milliliters" Return decMilliliters Case "Liters" Return decLiters Case Else MsgBox("Unrecognized output unit of measure for volume " & _ "output = " & CStr(CmbToUnit.SelectedItem)) End Select End If If RbtTemperature.Checked Then Select Case CmbToUnit.SelectedItem Case "Fahrenheit" Return decFahrenheit Case "Celsius" Return decCelsius Case Else MsgBox("Unrecognized output unit of measure for temperature " & _ "output = " & CStr(CmbToUnit.SelectedItem)) End Select End If End Function Private Sub ClearGlobalVariables() decInches = 0 decFeet = 0 decYards = 0 decMiles = 0 decCentimeters = 0 decMeters = 0 decKilometers = 0 decFluidOunces = 0 decPints = 0 decCups = 0 decQuarts = 0 decGallons = 0 decMilliliters = 0 decLiters = 0 decOunces = 0 decPounds = 0 decGrams = 0 decKilograms = 0 decFahrenheit = 0 deccelsius = 0 End Sub Private Sub BtnChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChart.Click If Not ChartInputOkay() Then Exit Sub 'You cannot proceed if the from unit = the to unit of measure, it will crash If CStr(CmbFromUnit.SelectedItem) = CStr(CmbToUnit.SelectedItem) Then MsgBox("You have instructed the program to convert from " & CStr(CmbFromUnit.SelectedItem) & " to " & _ CStr(CmbFromUnit.SelectedItem) & ", please correct this and try again.") Exit Sub End If Dim lngFrom, lngTo, lngIncrement, lngCounter As Long lngFrom = CLng(TxtChartFrom.Text) lngTo = CLng(TxtChartTo.Text) lngIncrement = CLng(CmbChartIncrement.SelectedItem) If lngTo < lngFrom Then MsgBox("The 'to' value must be larger than the 'from' value!") Exit Sub End If If lngTo < lngIncrement Then MsgBox("The 'increment' specified is larger than the 'to' value!") Exit Sub End If 'The following is a check relating to the maximum number of calculations 'we want the program to make - too many will appear to hang the computer If ((lngTo - lngFrom) / lngIncrement) > 1000 Then MsgBox("That would display a chart that is too large." & vbNewLine & _ "Please make the maximum chart entries no greater that 1000.") Exit Sub End If Dim dsOutputDataset As New DataSet("OutputDataSet") Dim dtOutputDatatable As DataTable = dsOutputDataset.Tables.Add("OutputDataTable") 'TODO: we need to clear columns for new chart - but why???? Dim OneRow As DataRow With dtOutputDatatable .Columns.Add(CStr(CmbFromUnit.SelectedItem), Type.GetType("System.String")) .Columns.Add(CStr(CmbToUnit.SelectedItem), Type.GetType("System.String")) End With 'create a new row with the same structure as that in the table dtgOutput.DataSource = dsOutputDataset.Tables(0) Dim ts As New DataGridTableStyle ts.MappingName = dsOutputDataset.Tables(0).ToString dtgOutput.TableStyles.Clear() dtgOutput.TableStyles.Add(ts) ts.GridColumnStyles(0).Width = CInt(grpChart.Width / 2) ts.GridColumnStyles(1).Width = CInt(grpChart.Width / 2) ts.AlternatingBackColor = Color.LightCyan arlChartFromValuesArray.Clear() arlChartToValuesArray.Clear() For lngCounter = lngFrom To lngTo Step lngIncrement If RbtLength.Checked Then LengthConversion(CDec(lngCounter)) If RbtWeight.Checked Then WeightConversion(CDec(lngCounter)) If RbtVolume.Checked Then VolumeConversion(CDec(lngCounter)) If RbtTemperature.Checked Then TemperatureConversion(CDec(lngCounter)) OneRow = dsOutputDataset.Tables(0).NewRow OneRow(CStr(CmbFromUnit.SelectedItem)) = CStr(lngCounter) OneRow(CStr(CmbToUnit.SelectedItem)) = CStr(FormatNumber(ChooseOutputValue(), intNumberOfOutputDecimals)) dsOutputDataset.Tables(0).Rows.Add(OneRow) 'add same values to our global array lists for reporting and export functions arlChartFromValuesArray.Add(CStr(lngCounter)) arlChartToValuesArray.Add(CStr(FormatNumber(ChooseOutputValue(), intNumberOfOutputDecimals))) Next lngCounter dtgOutput.Show() End Sub Private Sub CmbChartIncrement_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbChartIncrement.SelectedIndexChanged End Sub Function InsertSpaces(ByVal intNumberOfSpaces As Integer) As String ' ' This is used to provide a variable number of spaces to improve readability ' Dim strSpaceLine As String Dim intCounter As Integer strSpaceLine = "" For intCounter = 1 To intNumberOfSpaces Step 1 strSpaceLine &= " " Next intCounter Return strSpaceLine End Function Private Sub mnuVersionHistory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVersionHistory.Click 'Version history must be updated when a major program change is made MsgBox("Metric Conversion Program Version History" & _ vbNewLine & vbNewLine & _ "Version 1.0.0 1-20-2004 Initial Creation" & vbNewLine & _ "Version 1.0.1 1-31-2004 Fixed bug in converting Celsius to Fahrenheit" & vbNewLine & _ " Negative numbers not allowed unless input is temperature" & vbNewLine & _ "Version 2.0.0 5-08-2005 Changed the chart on the screen to datagrid" & vbNewLine & _ " Added reports for chart output along with .CSV files" & vbNewLine & _ " Added method to vary the number of decimals in calculations" & vbNewLine & _ "Version 2.0.1 5-13-2005 Verified and repaired problems in the conversion" & vbNewLine & _ " factors for various measurements" & vbNewLine & _ vbNewLine, , "Version History") End Sub Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click 'Version number must be changed here to reflect latest with date MsgBox("Persson Technologies Metric Conversion Program" & _ vbNewLine & "Version 2.0.1 created 5-13-2005" & _ vbNewLine & "Copyright 2004, 2005 by Persson Technologies, all rights reserved", , "About Metric Conversion") End Sub Private Sub mnuFAQs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFAQs.Click MsgBox("Metric Conversion Program Frequently Asked Questions" & _ vbNewLine & vbNewLine & _ "Q. How accurate are the results of the calculations?" & _ vbNewLine & _ "A. The results were rounded to two decimal places" & vbNewLine & _ "however you can change this in the settings menu" & _ vbNewLine & vbNewLine & _ "Q. Why is a chart limited to only 1000 entries?" & _ vbNewLine & _ "A. A chart of over 1000 entries resulted in too much" & vbNewLine & _ "computation time causing the appearance of a loop." & _ vbNewLine & vbNewLine, , "FAQS") End Sub Private Sub mnuHowToUse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHowToUse.Click MsgBox("Here is a little tutorial to explain how this program is supposed to work." & vbNewLine & _ vbNewLine & _ "In the first section called 'Measurement Category' you" & vbNewLine & _ "choose whether you want to convert length, weight, etc." & vbNewLine & _ "Then you proceed to the 'Select Units of Measure' section" & vbNewLine & _ "where you decide what units of measure you wish to use." & vbNewLine & _ "For instance, if you want to convert from miles to yards you" & vbNewLine & _ "would use the down arrows next to the boxes to choose miles in" & vbNewLine & _ "the first box and yards in the second. Once you have chosen" & vbNewLine & _ "your measurement category and the units of measure you" & vbNewLine & _ "are using, you enter a 'from' value and then click on" & vbNewLine & _ "the 'Convert Now' button. If there are no errors your answer" & vbNewLine & _ "will appear in the box below the 'Convert Now' button." & vbNewLine & _ vbNewLine & _ "Creating Charts:" & vbNewLine & _ "The program can also create conversion charts for you" & vbNewLine & _ "as a handy reference tool. Let's say you email to a relative" & vbNewLine & _ "in a foreign land and they use the Celsius system for" & vbNewLine & _ "temperature. You want to have a handy reference chart of" & vbNewLine & _ "Celsius to Fahrenheit conversions. You simply choose temperature" & vbNewLine & _ "as your 'Measurement Category' then set 'convert from' to Celsius," & vbNewLine & _ "set 'convert to' to Fahrenheit, then in the 'Produce Chart'" & vbNewLine & _ "section you need to enter a starting and ending value and an" & vbNewLine & _ "increment. For instance, if you want a chart of all temperatures" & vbNewLine & _ "between -20 Celsius and 70 Celsius and you want the chart to appear" & vbNewLine & _ "in increments of 5 you would enter -20 and 70 and then set the" & vbNewLine & _ "increment to 5. If you are not clear on how this works, just try" & vbNewLine & _ "a few numbers. When you are ready to produce a chart, just click" & vbNewLine & _ "on the 'Create Chart' button and it will display in the box." & vbNewLine & _ vbNewLine & _ "Saving Charts:" & vbNewLine & _ "If you like the chart you have created, you can save it to a" & vbNewLine & _ "text file by using the file-save function. You can then" & vbNewLine & _ "open it with a word processing program and customize the" & vbNewLine & _ "chart to your liking. If you save the chart as a CSV file" & vbNewLine & _ "then you also have the option of opening the file with a spreadsheet program" & vbNewLine & _ vbNewLine & _ "Printing Charts:" & vbNewLine & _ "The program will also allow you to print the chart as a report." & vbNewLine & _ "It is recommended that you first use the print preview feature to " & vbNewLine & _ "verify that the report is what you desire before sending it to the printer.") End Sub Private Sub txtConversionFrom_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtConversionFrom.KeyPress ' code here limits keys to the digits "0" to "9" Dim KeyAscii As Integer KeyAscii = AscW(e.KeyChar) Select Case KeyAscii Case Is < Keys.Space ' These are control keys, ignore Case Keys.D0 To Keys.D9 ' These are numeric keys, ignore Case Asc("-") If Not RbtTemperature.Checked Then MsgBox("We will only allow negative numbers for temperature conversion") e.Handled = True 'suppress this key if length, weight, or volume is negative End If Case Asc(".") ' Okay for decimal numbers Case Else MsgBox("Please only enter numeric keys") e.Handled = True 'suppress this key End Select End Sub Private Sub txtChartFrom_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtChartFrom.KeyPress ' code here limits keys to the digits "0" to "9" Dim KeyAscii As Integer KeyAscii = AscW(e.KeyChar) Select Case KeyAscii Case Is < Keys.Space ' These are control keys, ignore Case Keys.D0 To Keys.D9 ' These are numeric keys, ignore Case Asc("-") If Not RbtTemperature.Checked Then MsgBox("We will only allow negative numbers for temperature conversion") e.Handled = True 'suppress this key if length, weight, or volume is negative End If Case Asc(".") ' Someone is trying to use a decimal, we don't allow MsgBox("Please only enter whole numbers here") e.Handled = True 'suppress this key Case Else MsgBox("Please only enter numeric keys") e.Handled = True 'suppress this key End Select End Sub Private Sub txtChartTo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtChartTo.KeyPress ' code here limits keys to the digits "0" to "9" Dim KeyAscii As Integer KeyAscii = AscW(e.KeyChar) Select Case KeyAscii Case Is < Keys.Space ' These are control keys, ignore Case Keys.D0 To Keys.D9 ' These are numeric keys, ignore Case Asc("-") ' We will allow negative numbers for temperature Case Asc(".") ' Someone is trying to use a decimal, we don't allow MsgBox("Please only enter whole numbers here") e.Handled = True 'suppress this key Case Else MsgBox("Please only enter numeric keys") e.Handled = True 'suppress this key End Select End Sub Private Function MainInputOkay() As Boolean If IsNumeric(txtConversionFrom.Text) Then Return True Else MsgBox("The input value is not numeric!") txtConversionFrom.Focus() txtConversionFrom.SelectAll() Return False End If End Function Private Function ChartInputOkay() As Boolean If IsNumeric(TxtChartFrom.Text) And IsNumeric(TxtChartTo.Text) Then Return True If Not IsNumeric(TxtChartFrom.Text) Then MsgBox("The input value is not numeric!") TxtChartFrom.Focus() TxtChartFrom.SelectAll() Return False End If If Not IsNumeric(TxtChartTo.Text) Then MsgBox("The input value is not numeric!") TxtChartTo.Focus() TxtChartTo.SelectAll() Return False End If End Function Private Sub MnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuExit.Click Me.Close() End Sub Private Sub MnuSaveChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuSaveChart.Click If arlChartFromValuesArray.Count = 0 Then MsgBox("There is no chart to save, please generate a conversion" & vbNewLine & _ "chart before attempting to save it!") Exit Sub End If Dim strReportFileName, strReportDelimeter, strFromValue, strToValue As String Dim decTempNumber As Decimal Dim intDotLocation As Integer Dim blnTXTFile As Boolean Dim outfile As StreamWriter SaveFileDialog1.Filter = "Text files (*.txt)|*.txt|Comma-Separated Value files (*.csv)|*.csv" If SaveFileDialog1.ShowDialog() = DialogResult.OK Then strReportFileName = SaveFileDialog1.FileName ' 'we need to see if the extension to the right of the dot is TXT 'If our output will be a text file then the report delimeter is spaces 'but if we are doing a CSV file for import into a spreadsheet we want a comma intDotLocation = InStr(strReportFileName, ".") If UCase(Mid(strReportFileName, intDotLocation + 1, 3)) = "TXT" Then strReportDelimeter = InsertSpaces(20) blnTXTFile = True Else strReportDelimeter = "," blnTXTFile = False End If ' Try outfile = New StreamWriter(strReportFileName, False) Catch ex As IO.IOException MsgBox("Could not open report file for output, error is:" & vbNewLine & _ ex.Message) Exit Sub End Try Try outfile.WriteLine(CStr(CmbFromUnit.SelectedItem) & strReportDelimeter & CStr(CmbToUnit.SelectedItem)) For intChartArrayCounter = 0 To arlChartFromValuesArray.Count - 1 If blnTXTFile Then outfile.WriteLine(CStr(arlChartFromValuesArray(intChartArrayCounter)) & _ strReportDelimeter & CStr(arlChartToValuesArray(intChartArrayCounter))) Else 'we need to do some conversions to strip the commas from the numbers for CSV 'this was done in this fashion to aid in debugging strFromValue = CStr(arlChartFromValuesArray(intChartArrayCounter)) decTempNumber = CDec(strFromValue) strFromValue = CStr(decTempNumber) strToValue = CStr(arlChartToValuesArray(intChartArrayCounter)) decTempNumber = CDec(strToValue) strToValue = CStr(decTempNumber) outfile.WriteLine(strFromValue & strReportDelimeter & strToValue) End If Next outfile.Flush() Catch ex As IO.IOException MsgBox("Could not write to report file, error is:" & vbNewLine & _ ex.Message) Exit Sub End Try Try outfile.Close() Catch ex As IO.IOException MsgBox("Could not close report file for output, error is:" & vbNewLine & _ ex.Message) Exit Sub End Try End If End Sub Private Sub InitializeScreen() CmbFromUnit.SelectedIndex = 0 CmbToUnit.SelectedIndex = 0 CmbChartIncrement.SelectedIndex = 0 txtConversionFrom.Text = "0" TxtChartFrom.Text = "0" TxtChartTo.Text = "10" LblConversionOut.Text = "0" End Sub Private Sub mnuPrintChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrintChart.Click If arlChartFromValuesArray.Count = 0 Then MsgBox("There is no chart to print, please generate a conversion" & vbNewLine & _ "chart before attempting to print it!") Exit Sub End If PrintMetricChart() End Sub Private Sub mnuPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrintPreview.Click If arlChartFromValuesArray.Count = 0 Then MsgBox("There is no chart to preview, please generate a conversion" & vbNewLine & _ "chart before attempting to preview it!") Exit Sub End If Dim MetricChart As New PrintDocument Dim dlgPrintPreview As New PrintPreviewDialog AddHandler MetricChart.BeginPrint, AddressOf InitializeReportData AddHandler MetricChart.PrintPage, AddressOf PrintMetricPage dlgPrintPreview.Document = MetricChart dlgPrintPreview.ShowDialog() End Sub Private Sub PrintMetricChart() Dim MetricChart As New PrintDocument Dim PrinterSetupScreen As New PrintDialog Dim ButtonPressed As DialogResult AddHandler MetricChart.BeginPrint, AddressOf InitializeReportData AddHandler MetricChart.PrintPage, AddressOf PrintMetricPage PrinterSetupScreen.Document = MetricChart PrinterSetupScreen.AllowPrintToFile = False ButtonPressed = PrinterSetupScreen.ShowDialog 'TODO: We need to disable the landscape feature since it makes no sense If ButtonPressed = DialogResult.OK Then MetricChart.Print() End If End Sub Sub InitializeReportData(ByVal sender As Object, ByVal e As PrintEventArgs) intChartArrayCounter = 0 intReportPageCounter = 1 End Sub Sub PrintMetricPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Const LeftMargin As Integer = 30 Const FirstTab As Integer = 100 Const SecondTab As Integer = 300 Const TitleTab As Integer = 190 Const PageNumTab As Integer = 650 Const ReportTitle As String = "Persson Metric Conversion Chart" Const OneLine As String = "----------------------------------------------------------" Dim RecordsPerPage As Integer = 40 Dim CurrentRecord As Integer = 0 Dim CurrentY As Integer = 10 Dim TheDate As Date = Now Dim PageString, DateString As String Dim HeadingFont As New Font("Arial", 18, FontStyle.Bold) Dim ReportFont As New Font("Arial", 12, FontStyle.Regular) Dim ReportFontHeight As Integer = CInt(ReportFont.GetHeight(e.Graphics)) 'Write date and page number on very top of each page PageString = "Page No. " & CStr(intReportPageCounter) DateString = Format(TheDate, "MMMM d, yyyy") e.Graphics.DrawString(DateString, ReportFont, Brushes.Black, LeftMargin, CurrentY) e.Graphics.DrawString(PageString, ReportFont, Brushes.Black, PageNumTab, CurrentY) CurrentY = 85 'Here is where we write the report heading e.Graphics.DrawString(ReportTitle, HeadingFont, Brushes.Black, TitleTab, CurrentY) CurrentY += ReportFontHeight * 4 e.Graphics.DrawString((CStr(CmbFromUnit.SelectedItem)), ReportFont, Brushes.Black, FirstTab, CurrentY) e.Graphics.DrawString((CStr(CmbToUnit.SelectedItem)), ReportFont, Brushes.Black, SecondTab, CurrentY) CurrentY += ReportFontHeight e.Graphics.DrawString(OneLine, ReportFont, Brushes.Black, FirstTab, CurrentY) CurrentY += ReportFontHeight 'Here is where we write the details lines of the report While CurrentRecord < RecordsPerPage e.Graphics.DrawString(CStr(arlChartFromValuesArray(intChartArrayCounter)), ReportFont, Brushes.Black, FirstTab, CurrentY) e.Graphics.DrawString(CStr(arlChartToValuesArray(intChartArrayCounter)), ReportFont, Brushes.Black, SecondTab, CurrentY) CurrentY += ReportFontHeight intChartArrayCounter += 1 'If we have run out of records, exit If intChartArrayCounter > arlChartFromValuesArray.Count - 1 Then Exit While End If CurrentRecord += 1 End While intReportPageCounter += 1 If CurrentRecord < RecordsPerPage Then e.HasMorePages = False Else e.HasMorePages = True End If End Sub Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize 'When the form is re-sized we want to re-calculate the size of all portions 'to allocate more room for the chart grpTitle.Width = Me.Width grpMiddle.Height = Me.Height - grpTitle.Height GrpUnitSelection.Height = Me.Height - grpTitle.Height - GrpMeasurementCategory.Height grpChart.Height = Me.Height - grpTitle.Height - GrpProduceChart.Height - 50 grpChart.Width = Me.Width - grpMiddle.Width - GrpUnitSelection.Width - 7 dtgOutput.Height = grpChart.Height dtgOutput.Width = grpChart.Width End Sub Private Sub mnuDecimals0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDecimals0.Click intNumberOfOutputDecimals = 0 End Sub Private Sub mnuDecimals1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDecimals1.Click intNumberOfOutputDecimals = 1 End Sub Private Sub mnuDecimals2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDecimals2.Click intNumberOfOutputDecimals = 2 End Sub Private Sub mnuDecimals3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDecimals3.Click intNumberOfOutputDecimals = 3 End Sub Private Sub mnuDecimals4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDecimals4.Click intNumberOfOutputDecimals = 4 End Sub Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click ' copy data in the label to the Clipboard Clipboard.SetDataObject(LblConversionOut.Text) End Sub Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click ' paste data from the Clipboard to a textbox - get the data from the clipboard Dim Data As IDataObject Data = Clipboard.GetDataObject txtConversionFrom.SelectedText = Data.GetData(DataFormats.Text, True).ToString End Sub End Class