Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,085 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,781 people online right now. Registration is fast and FREE... Join Now!




Year 12 Major Programming task

 
Reply to this topicStart new topic

Year 12 Major Programming task

omalsa04
5 May, 2008 - 03:52 AM
Post #1

New D.I.C Head
*

Joined: 5 May, 2008
Posts: 11

Hey everybody biggrin.gif

I am making a conversion tool for my major project in IT this year.
It's features are:

Able to convert different values (obviously)
Save to log file
Copy results to clipboard


I was wondering if you had any ideas for features I could add to my program.
I will post my code as well. Please give me feedback, any help is appreciated. At the moment its as efficient as I can get it.

CODE

Imports System.IO 'Imports the settings needed to save to a text file
Public Class Converter
    'Name: Sam O'Malley
    'Task: Major Visual Basic Project
    'Date: 3-03-2008
    'Teacher: ## #####
    'SACE Number: ######

    'Declaring all variables

    Dim Input 'Input variable is in most cases the inputed number converted to SI units
    Dim Output 'Output is the variable that is calculated from Input and will be displayed

    Dim a 'Used in the storing of data, represents the input units
    Dim b 'Used in the storing of data, represents the output units
    Dim StoreData 'Used in the storing of data, holds the string copied to clipboard

    '####### Array or values that hold the conversion units ########
    Dim LengthArray(10)
    Dim WeightArray(22)
    Dim TimeArray(13)
    Dim SpeedArray(12)
    Dim AccelerationArray(20)
    Dim AngleArray(13)
    Dim AreaArray(10)
    Dim VolumeArray(16)


    Private Sub SelectTab()
        'This sub checks what tab is selected
        'It then directs traffic to the appropriate sub
        Select Case Tabs.SelectedTab.Text
            Case "Length"
                Length()
            Case "Weight/Mass"
                Weight()
            Case "Time"
                Time()
            Case "Speed"
                Speed()
            Case "Acceleration"
                Acceleration()
            Case "Angles"
                Angles()
            Case "Area"
                Area()
            Case "Volume"
                Volume()
            Case "Temperature"
                Temperature()
            Case "Ascii"
                Ascii()
        End Select
    End Sub

    Private Sub Converter_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Configures the text that loads on the status strip
        lblDate.Text = Today.Date
        lblPI.Text = "                    "

        LengthArray(0) = 0.01
        LengthArray(1) = 0.3048
        LengthArray(2) = 0.0254
        LengthArray(3) = 1000
        LengthArray(4) = 4828.0417
        LengthArray(5) = 5556
        LengthArray(6) = 1
        LengthArray(7) = 0.0000000254
        LengthArray(8) = 1609.344
        LengthArray(9) = 0.001
        LengthArray(10) = 0.9144

        WeightArray(0) = 0.00001
        WeightArray(1) = 0.0001
        WeightArray(2) = 0.01
        WeightArray(3) = 0.001771845195
        WeightArray(4) = 0.00006479891
        WeightArray(5) = 0.001
        WeightArray(6) = 0.1
        WeightArray(7) = 50.80234544
        WeightArray(8) = 45.359237
        WeightArray(9) = 1
        WeightArray(10) = 0.45359237
        WeightArray(11) = 1016.0469088
        WeightArray(12) = 1000
        WeightArray(13) = 1000
        WeightArray(14) = 0.000000001
        WeightArray(15) = 0.000001
        WeightArray(16) = 0.28349523125
        WeightArray(17) = 0.45359237
        WeightArray(18) = 907.18474
        WeightArray(19) = 1016.0469088
        WeightArray(20) = 907.18474
        WeightArray(21) = 1000
        WeightArray(22) = 1000

        TimeArray(0) = 0.00000001
        TimeArray(1) = 0.001
        TimeArray(2) = 1
        TimeArray(3) = 60
        TimeArray(4) = 3600
        TimeArray(5) = 86400
        TimeArray(6) = 604800
        TimeArray(7) = 1209600
        TimeArray(8) = 2628000
        TimeArray(9) = 7884000
        TimeArray(10) = 31536000
        TimeArray(11) = 315360000
        TimeArray(12) = 3153600000
        TimeArray(13) = 31536000000

        SpeedArray(0) = 0.01
        SpeedArray(1) = 0.3048
        SpeedArray(2) = 0.0254
        SpeedArray(3) = (1 / 3.6)
        SpeedArray(4) = 1000
        SpeedArray(5) = 0.5144444444
        SpeedArray(6) = 340.29
        SpeedArray(7) = 1
        SpeedArray(8) = 0.44704
        SpeedArray(9) = 1609.344
        SpeedArray(10) = 0.001
        SpeedArray(11) = 299792458
        SpeedArray(12) = 340.29

        AccelerationArray(0) = 0.0001
        AccelerationArray(1) = 0.01
        AccelerationArray(2) = 0.001
        AccelerationArray(3) = 0.1
        AccelerationArray(4) = 10
        AccelerationArray(5) = 0.3048
        AccelerationArray(6) = 9.80665
        AccelerationArray(7) = 0.01
        AccelerationArray(8) = 0.01
        AccelerationArray(9) = 9.80665
        AccelerationArray(10) = 9.80665
        AccelerationArray(11) = 100
        AccelerationArray(12) = 0.0254
        AccelerationArray(13) = (1 / 3.6)
        AccelerationArray(14) = 1000
        AccelerationArray(15) = 1
        AccelerationArray(16) = 0.0074507
        AccelerationArray(17) = 0.44704
        AccelerationArray(18) = 1609.344
        AccelerationArray(19) = 0.00001
        AccelerationArray(20) = 0.001

        AngleArray(0) = (180 / (Math.PI))
        AngleArray(1) = 0.05625
        AngleArray(2) = 0.9
        AngleArray(3) = 1
        AngleArray(4) = 1 / 60
        AngleArray(5) = 0.0002778
        AngleArray(6) = 11.25
        AngleArray(7) = 22.5
        AngleArray(8) = 36
        AngleArray(9) = 45
        AngleArray(10) = 60
        AngleArray(11) = 90
        AngleArray(12) = 180
        AngleArray(13) = 360

        AreaArray(0) = 4046.8564224
        AreaArray(1) = 10000
        AreaArray(2) = 80937.128
        AreaArray(3) = 0.0001
        AreaArray(4) = 0.09290304
        AreaArray(5) = 0.00064516
        AreaArray(6) = 8.9505412E+31
        AreaArray(7) = 2589988.110336
        AreaArray(8) = 0.000001
        AreaArray(9) = 1
        AreaArray(10) = 9.5214087E+32

        VolumeArray(0) = 0.000001
        VolumeArray(1) = 0.028316846592
        VolumeArray(2) = 0.000016387064
        VolumeArray(3) = 1
        VolumeArray(4) = 1000000000
        VolumeArray(5) = 0.000000001
        VolumeArray(6) = 0.0001
        VolumeArray(7) = 0.01
        VolumeArray(8) = 1
        VolumeArray(9) = 0.001
        VolumeArray(10) = 1000
        VolumeArray(11) = 0.000000001
        VolumeArray(12) = 0.000001
        VolumeArray(13) = 0.00002957353
        VolumeArray(14) = 0.000473176473
        VolumeArray(15) = 0.000946352946
        VolumeArray(16) = 0.000005


    End Sub

    Private Sub Length()
        'Sets the conversion formula to convert to SI units for length (metres)
        'depending on the selected units

        Dim n

        n = LengthIn.SelectedIndex
        Input = (txtInput.Text * LengthArray(n))
        n = LengthOut.SelectedIndex
        Output = (Input / LengthArray(n))


        'Sets the units variable for the copy to clipboard function
        a = LengthIn.Text
        b = LengthOut.Text

    End Sub

    Private Sub Weight()
        'Sets the conversion formula to convert to SI units for weight (kilograms)
        'depending on the selected units

        Dim n

        n = WeightIn.SelectedIndex
        Input = (txtInput.Text * WeightArray(n))
        n = WeightOut.SelectedIndex
        Output = (Input / WeightArray(n))


        'Sets the units variable for the copy to clipboard function
        a = WeightIn.Text
        b = WeightOut.Text

    End Sub

    Private Sub Time()
        'Sets the conversion formula to convert to SI units for time (seconds)
        'depending on the selected units

        Dim n

        n = TimeIn.SelectedIndex
        Input = (txtInput.Text * TimeArray(n))
        n = TimeOut.SelectedIndex
        Output = (Input / TimeArray(n))


        'Sets the units variable for the copy to clipboard function
        a = TimeIn.Text
        b = TimeOut.Text

    End Sub

    Private Sub Speed()
        'Sets the conversion formula to convert to SI units for speed (metres/second)
        'depending on the selected units

        Dim n

        n = SpeedIn.SelectedIndex
        Input = (txtInput.Text * SpeedArray(n))
        n = SpeedOut.SelectedIndex
        Output = (Input / SpeedArray(n))


        'Sets the units variable for the copy to clipboard function
        a = SpeedIn.Text
        b = SpeedOut.Text

    End Sub

    Private Sub Acceleration()
        'Sets the conversion formula to convert to SI units for acceleration(metres/second/second)
        'depending on the selected units

        Dim n

        n = AccelIn.SelectedIndex
        Input = (txtInput.Text * AccelerationArray(n))
        n = AccelOut.SelectedIndex
        Output = (Input / AccelerationArray(n))


        'Sets the units variable for the copy to clipboard function
        a = AccelIn.Text
        b = AccelOut.Text

    End Sub

    Private Sub Angles()
        'Sets the conversion formula to convert to SI units for angles(degrees)
        'depending on the selected units

        Dim n

        n = AngleIn.SelectedIndex
        Input = (txtInput.Text * AngleArray(n))
        n = AngleOut.SelectedIndex
        Output = (Input / AngleArray(n))


        'Sets the units variable for the copy to clipboard function
        a = AngleIn.Text
        b = AngleOut.Text

    End Sub

    Private Sub Area()
        'Sets the conversion formula to convert to SI units for area(metres^2)
        'depending on the selected units

        Dim n

        n = AreaIn.SelectedIndex
        Input = (txtInput.Text * AreaArray(n))
        n = AreaOut.SelectedIndex
        Output = (Input / AreaArray(n))


        'Sets the units variable for the copy to clipboard function
        a = AreaIn.Text
        b = AreaOut.Text

    End Sub

    Private Sub Volume()
        'Sets the conversion formula to convert to SI units for volume(metres^3)
        'depending on the selected units

        Dim n

        n = VolumeIn.SelectedIndex
        Input = (txtInput.Text * VolumeArray(n))
        n = VolumeOut.SelectedIndex
        Output = (Input / VolumeArray(n))


        'Sets the units variable for the copy to clipboard function
        a = VolumeIn.Text
        b = VolumeOut.Text

    End Sub

    Private Sub Temperature()
        'Sets the more complicated formulas for temperature conversion

        If (TempIn.Text = "Degrees Celsius" And TempOut.Text = "Degrees Fahrenheit") Then
            Output = ((txtInput.Text * 1.8) + 32)

            'If Input is Fahrenheit and Output is Celsius then use this formula
        ElseIf (TempIn.Text = "Degrees Fahrenheit" And TempOut.Text = "Degrees Celsius") Then
            Output = Format((txtInput.Text - 32) / 1.8)

            'If Input and Output are both Fahrenheit then txtinput.text = Output
        ElseIf TempIn.Text = TempOut.Text Then
            Output = txtInput.Text
        End If

        a = TempIn.Text
        b = TempOut.Text
    End Sub

    Private Sub Ascii()
        If AsciiIn.Text = "Ascii" And AsciiOut.Text = "Character" Then
            Output = ChrW(txtInput.Text)
            a = "in ascii code"
            b = "as a character"
        ElseIf AsciiIn.Text = "Character" And AsciiOut.Text = "Ascii" Then
            Output = Microsoft.VisualBasic.AscW(txtInput.Text)
            a = "as a character"
            b = "in ascii code"
        ElseIf AsciiIn.Text = AsciiOut.Text Then
            Output = txtInput.Text
        End If

    End Sub

    Private Sub btnConvert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        If Tabs.SelectedTab.Text = "Ascii" Then
            SelectTab()
            txtOutput.Text = Output
            StoreData = (txtInput.Text & " " & a & " is equal to " & txtOutput.Text & " " & b)
            lblPI.Text = StoreData

            'Configures an error message to appear when you enter a non-numeric
        ElseIf IsNumeric(txtInput.Text) = False Then
            Beep()
            txtOutput.Text = "Error: Only numbers are accepted as input!"
        Else
            SelectTab()
            txtOutput.Text = Output 'Displays the results
            StoreData = (txtInput.Text & " " & a & " is equal to " & txtOutput.Text & " " & b)
            lblPI.Text = StoreData
        End If

        If chkKeepLog.Checked = True Then
            CopySub()
        End If
    End Sub

    Private Sub Converter_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        Select Case e.KeyChar
            Case ChrW(Keys.Escape)
                Me.Close()
        End Select
    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
        'Configures the error message for trying to copy nothing
        If StoreData = "" Then
            StoreData = "Error: There is no data to copy"
        End If
        Clipboard.SetText(StoreData)
    End Sub

    Private Sub chkAlwaysOnTop_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAlwaysOnTop.CheckedChanged
        'Sets the "always on top" checkbox
        If chkAlwaysOnTop.Checked Then
            Me.TopMost() = True
        Else
            Me.TopMost() = False
        End If
    End Sub

    Private Sub CopySub()

        Dim filename As String = (txtSaveLocation.Text)
        If txtSaveLocation.Text = "" Then
            Beep()
            MsgBox("Error: you need to enter a location first", MsgBoxStyle.OkCancel)
        Else
            If System.IO.File.Exists(filename) Then
                Dim objWriterappend As New System.IO.StreamWriter(filename, True)
                objWriterappend.Write(StoreData & vbNewLine)
                objWriterappend.Close()
            Else
                Dim objWriternew As New System.IO.StreamWriter(filename, False)
                objWriternew.Write(StoreData & vbCrLf)
                objWriternew.Close()
            End If
        End If
    End Sub

    Private Sub toolstripAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolstripAbout.Click
        AboutBox.Show()
    End Sub

    Private Sub OpenLogFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenLogFileToolStripMenuItem.Click
        HelpBox.Show()
    End Sub

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ResetAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetAllToolStripMenuItem.Click
        'Reset Input and output text boxes
        txtInput.Text = ""
        txtOutput.Text = ""

        'Reset all Unit selection boxes
        LengthIn.Text = "Select Units:"
        AreaIn.Text = "Select Units:"
        VolumeIn.Text = "Select Units:"
        WeightIn.Text = "Select Units:"
        TempIn.Text = "Select Units:"
        TimeIn.Text = "Select Units:"
        SpeedIn.Text = "Select Units:"
        AccelIn.Text = "Select Units:"
        AngleIn.Text = "Select Units:"
        AsciiIn.Text = "Select Units:"

        LengthOut.Text = "Select Units:"
        AreaOut.Text = "Select Units:"
        VolumeOut.Text = "Select Units:"
        WeightOut.Text = "Select Units:"
        TempOut.Text = "Select Units:"
        TimeOut.Text = "Select Units:"
        SpeedOut.Text = "Select Units:"
        AccelOut.Text = "Select Units:"
        AngleOut.Text = "Select Units:"
        AsciiOut.Text = "Select Units:"

        'Reset the Latest conversion label
        StoreData = ""
        lblPI.Text = StoreData

    End Sub
End Class



Thanks for your help

by Sam O'Malley <<just incase the SACE guys come across this and think I've plagiarised, lol
User is offlineProfile CardPM
+Quote Post

omalsa04
RE: Year 12 Major Programming Task
6 May, 2008 - 05:20 AM
Post #2

New D.I.C Head
*

Joined: 5 May, 2008
Posts: 11

This is a screen shot of the main form:

Attached File  Screen_Shot.bmp ( 441.48k ) Number of downloads: 34



EDIT: How do I edit the main post?? I didn't mean to bump it

This post has been edited by omalsa04: 6 May, 2008 - 05:23 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month