Tag Archives: basic

VB.net Compare Assignment

Here’s the assignment for Lab3. The next class session will show us .

Public Class frmCompare

    '----JDS-----------------------
    'CREATED:    10/15/2014
    'CREATED BY: James Strickland
    'CLASS:      COP2010 - 090898
    'PURPOSE:    Write a Windows Application
    '            program that inputs
    '            three different integers
    '            and displays results
    '            in a listbox
    '----JDS-----------------------

    ' Declare variables
    ' inum=InputNumber
    Dim inum1, inum2, inum3 As Integer

    ' onum=OutputNumber
    Dim onum1, onum2, onum3, max, min As Integer

    Private Sub frmCompare_Load(sender As Object, _
                                e As EventArgs) _
                            Handles MyBase.Load

        ' Hide the "About" label at form load
        lblAbout.Visible = False

    End Sub


    Private Sub btnGo_Click(sender As Object, _
                        e As EventArgs) _
                        Handles btnExe.Click

        ' The following code is executed 
        ' when the EXECUTE button is pressed

        ' Get the users 3 numbers and load
        ' them into the 3 input variables
        inum1 = txtInput1.Text
        inum2 = txtInput2.Text
        inum3 = txtInput3.Text

        ' Clear list box encase user wants to 
        ' repeat program without scrolling 
        ' down listbox.
        LstBoxResults.Items.Clear()

        ' Display numbers as user entered them
        ' seperated by comma
        LstBoxResults.Items.Add("Numbers in User Order:")
        LstBoxResults.Items.Add(inum1 & ", " & inum2 & ", " & inum3)
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Sum of users entered numbers
        LstBoxResults.Items.Add("Sum of numbers:") ' Displays to user
        LstBoxResults.Items.Add(inum1 + inum2 + inum3) ' does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Average of numbers
        LstBoxResults.Items.Add("Average of Numbers:") ' Displays to user
        LstBoxResults.Items.Add((inum1 + inum2 + inum3) \ 3) ' does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Product of numbers
        LstBoxResults.Items.Add("Product of numbers:") ' Displays to user
        LstBoxResults.Items.Add(inum1 * inum2 * inum3) ' Does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Largest of the 3 numbers
        LstBoxResults.Items.Add("Largest of the 3:")
        max = inum1 ' Init variable mas a first number entered, the compare below...

        If inum2 > max Then
            max = inum2 ' inum2 greater than max, init max as inum2 (inum2 is smaller)
        End If

        If inum3 > max Then
            max = inum3 ' inum3 greater than max, init max as inum3 (inum3 is smaller)
        End If

        LstBoxResults.Items.Add(max)
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Smallest of the 3 numbers
        LstBoxResults.Items.Add("Smallest of the 3:")
        min = inum1 ' init min as inum1

        If inum2 < min Then
            min = inum2 ' inum2 less than min, init min as inum2 (inum2 is bigger)
        End If

        If inum3 < min Then
            min = inum3 ' inum3 less than min, init min as inum3 (inum3 is bigger)
        End If

        LstBoxResults.Items.Add(min) ' Display results of min
        LstBoxResults.Items.Add("") ' simply creates a space between answers

    End Sub

    ' Close/Exit the program
    Private Sub btnExit_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles btnExit.Click
        Close()

    End Sub



    Private Sub btnAbout_Click(sender As Object, _
                               e As EventArgs) _
                               Handles btnAbout.Click
        ' The below code hides the form content and 
        ' displays information about the programmer
        ' (when the user presses the "about" button)
        ' which happens to be me. For those who does
        ' not know me, I am a big deal around here..
        ' I mean, I didn't want to say nuthin.......

        ' Clear Form
        btnExe.Visible = False
        lblEnterNumbers.Visible = False
        lblInstruction.Visible = False
        txtInput1.Visible = False
        txtInput2.Visible = False
        txtInput3.Visible = False
        LstBoxResults.Visible = False

        ' About Programmer
        lblAbout.Visible = True

    End Sub

End Class

 

I will not throw paper airplanes in class!!!

Stumbled upon this cartoon:
Paper Airplanes

Thought this was hilarious!!!  Of course, since I’m not much of a C++ programmer, I would do something like this:

Sub airplanes()

Range("A1").Value = "I will not throw paper airplanes in class"
Range("A1").Copy
Range("A2:A500").PasteSpecial

End Sub

throw this in a spreadsheet then email it to the teacher!!! Ok, so this method wouldn’t be as cool as the pic, but it would work and save time! Wonder how you could do this in BASH…

AutoFormat a spreadsheet

Trying to AutoFormat an Excel Spreadsheet…

Sub OLVIMS_REPORT()
'======================================================
' CLOSED 868 REPORT AUTO FORMAT SCRIPT/MACRO
'======================================================

    Columns("A:B").Select
    Selection.Delete Shift:=xlToLeft
    Range("H1").Select
    Cells.Replace What:="END OF REPORT", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("A2").Select
    Columns("H:H").EntireColumn.AutoFit
    Columns("I:I").EntireColumn.AutoFit
    Columns("C:C").EntireColumn.AutoFit
    Columns("B:B").EntireColumn.AutoFit
    Range("A2:I2").Select
    Selection.Cut Destination:=Range("H1:P1")
    Range("A4:I4").Select
    Selection.Cut Destination:=Range("H3:P3")
' the rest was cut out
    '
    ' Delete Blank Rows Macro
    '
    On Error Resume Next

    Columns("I:I").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

    '
    ' auto_width Macro
    '
    '
    Columns("A:Z").EntireColumn.AutoFit

'
' COLOR Macro
'
'
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual   'pre XL97 xlManual
  Dim Rng As Range, ix As Long
  Set Rng = Intersect(Range("P:P"), ActiveSheet.UsedRange)
  For ix = Rng.Count To 1 Step -1
      If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
        Rng.Item(ix).ClearContents
      End If
  Next
done:
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True

    Columns("H:H").SpecialCells(xlCellTypeBlanks).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .COLOR = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Columns("P:P").Select
    Columns("P:P").SpecialCells(xlCellTypeBlanks).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .COLOR = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

End Sub

Here is the full code, in txt format.