Monday, January 31, 2011

If Statements

A few different applications of If statements and Case satements

An if statement that makes one decision
 Public Class Form1
  
   Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
  
     If chkCheck.Checked Then
  
       MessageBox.Show("Congrats, You Are Alive")
  
     End If
  
   End Sub
  
 End Class  

An if statement where it's either or
 Public Class Form1
  
   Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
  
     If chkCheck.Checked Then
  
       MessageBox.Show("You Win")
  
     Else
  
       MessageBox.Show("You Lose")
  
     End If
  
   End Sub
  
 End Class  

An if statement where many decisions are made
 Public Class Form1
  
   Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
  
     If chkCheck.Checked Then
  
       MessageBox.Show("You win 1 dollar")
  
     ElseIf chkCheck2.Checked Then
  
       MessageBox.Show("You lose 1 dollar")
  
     ElseIf chkCheck3.Checked Then
  
       MessageBox.Show("You win 2 dollars")
  
     ElseIf chkCheck4.Checked Then
  
       MessageBox.Show("You lose 2 dollars")
  
     End If
  
   End Sub
  
 End Class  

A case statement
 Public Class Form1
  
   Private Sub btnFeedback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFeedback.Click
  
     Dim team As String
  
     Dim anwser As String
  
     team = txtYesOrNo.Text
  
     Select Case team
  
       Case "yes"
  
         anwser = "Too Bad"
  
       Case "no"
  
         anwser = "Good Choice"
  
       Case Else
  
         anwser = "Check Your Spelling"
  
     End Select
  
     MsgBox(anwser)
  
   End Sub
  
 End Class  

Sunday, January 30, 2011

VB Word Problems

1. Morgan has 6 cows and 7 sheep. How many total animals does she have?
Public Class frmcows
   Private Sub btnAnwser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnwser.Click
  
     Dim sheep As Integer = 7
  
     Dim cows As Integer = 6
  
     Dim total As Integer
  
     total = sheep * cows
  
     MessageBox.Show(total)
  
   End Sub
  
 End Class
  

2. Diane bought 7 burgers, each of which cost $4. How much did she spend on burgers?
   Private Sub btnCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCost.Click
  
     Dim cost As Integer = 4
  
     Dim amount As Integer = 7
  
     Dim totalcost As Integer
  
     totalcost = cost * amount
  
     MessageBox.Show(totalcost)
  
   End Sub
  
 End Class
  

3. Ole has 15 apples and 12 oranges. Whats his total fruit count?
Public Class frmFruit
 Private Sub btnFruit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFruit.Click
  
     Dim apples As Integer = 15
  
     Dim oranges As Integer = 12
  
     Dim totalfruit As Integer
  
     totalfruit = apples + oranges
  
     MessageBox.Show(totalfruit)
  
   End Sub
  
 End Class
  

4. There are 33 horses to begin, 15 go into the barn, 7 come back out. What is the new population?

 Public Class frmHorses
  
   Private Sub btnLeftover_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeftover.Click
  
     Dim beginningpopulation As Integer = 33
  
     Dim barn As Integer = 15
  
     Dim returners As Integer = 7
  
     Dim newpopulation As Integer
  
     newpopulation = beginningpopulation - barn + returners
  
     MessageBox.Show(newpopulation)
  
   End Sub
  
 End Class  

5. Ingelbert has 15 apples and 3 times as many oranges. How many pieces of fruit do they have?
 Public Class frmFruit2
  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
     Dim apples As Integer = 15
  
     Dim oranges As Integer
  
     Dim total As Integer
  
     oranges = apples * 3
  
     total = apples + oranges
  
     MessageBox.Show(total)
  
   End Sub
  
 End Class  

6. Using the grade table decide how many marks did Brian score in math and science combined, how many more does Andrew need for a perfect math score, and what is Andrew's percentages for all o the quizzes put together.
 Public Class frmGradeTABLE
  
   Private Sub btnGradeInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGradeInfo.Click
  
     Dim AEnglish As Integer = 12
  
     Dim AGeography As Integer = 19
  
     Dim AMath As Integer = 18
  
     Dim AScience As Integer = 7
  
     Dim BEnglish As Integer = 22
  
     Dim BGeography As Integer = 15
  
     Dim BMath As Integer = 7
  
     Dim BScience As Integer = 22
  
     Dim combinedmath As Integer
  
     Dim mathperfectscore As Integer
  
     Dim APercentage As Integer
  
     Dim totalanwser As String
  
     combinedmath = BMath + AMath
  
     mathperfectscore = 25 - AMath
  
     APercentage = (AEnglish + AGeography + AMath + AScience) / 100
  
     totalanwser = String.Concat(combinedmath.ToString & Environment.NewLine, mathperfectscore.ToString & Environment.NewLine, APercentage.ToString & Environment.NewLine)
  
     Console.WriteLine(totalanwser)
  
     MessageBox.Show(totalanwser)
  
   End Sub
  
 End Class  

Friday, January 28, 2011

Table Variable Create and Inner Join

Below is code on how I created 2 Table Variables and then inner joined the two using a primary key.

 use blog
  
 go
  
 declare @Potatoe_Varieties table
  
 (
  
      Potatoe_ID int identity (1,1) PRIMARY KEY,
  
      Name varchar (40),
  
      Color varchar (10),
  
      Uses varchar (60)
  
 );
  
 Insert into @Potatoe_Varieties
  
 (Name, Color, Uses)
  
 Values
  
 ('Norlands', 'Red', 'Fresh Market Sales')
  
 Insert into @Potatoe_Varieties
  
 (Name, Color, Uses)
  
 Values
  
 ('Russet Burbank', 'Yellow', 'Chips, fries, dehydrated for later use')
  
 Insert into @Potatoe_Varieties
  
 (Name, Color, Uses)
  
 Values
  
 ('Yukon Gold', 'Golden', 'Fresh Market Sales and dehydrated for later use')
  
 declare @Potatoe_size table
  
 (
  
      Potatoe_ID int identity (1,1) PRIMARY KEY,
  
      [weight] varchar (10),
  
      diameter varchar (10),
  
      yield varchar (30)
  
 );
  
 Insert into @Potatoe_size
  
 ([weight], diameter, yield)
  
 Values
  
 ('8oz', '6 inches', '150-300 100lb bags per acre')
  
 Insert into @Potatoe_size
  
 ([weight], diameter, yield)
  
 Values
  
 ('12oz', '7 inches', '250-375 100lb bags per acre')
  
 Insert into @Potatoe_size
  
 ([weight], diameter, yield)
  
 Values
  
 ('7oz', '6 inches', '150-300 100lb bags per acre')
  
 select PV.*, [weight], diameter, yield
  
 from @Potatoe_Varieties PV
  
 inner join @Potatoe_size PS
  
      on PV.Potatoe_ID = PS.Potatoe_ID
  

Wednesday, January 26, 2011

Joining Two Strings

 Public Class Form1
  
 
  
   Private Sub btnJoin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJoin.Click
  
     Dim start As String = 9
  
     Dim finish As String = 7
  
     Dim together As String = String.Concat(start, finish)
  
     Console.WriteLine(together)
  
 
  
 
  
     MessageBox.Show(together)
  
 
  
   End Sub
  
 End Class  

Converting Into to Dec and Dec to Int

   Private Sub btnDecToInt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecToInt.Click
  
     Dim value As Integer
  
     Dim quantity As Decimal
  
 
  
     value = 5
  
     quantity = 0.3
  
 
  
     quantity = Convert.ToDecimal(value)
  
     MessageBox.Show(quantity.GetType.ToString)
  
   End Sub
  
 
  
   Private Sub btnIntToDec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIntToDec.Click
  
     Dim X As Integer
  
     Dim Y As Decimal
  
 
  
     X = 1
  
     Y = 0.1
  
 
  
     X = Convert.ToInt16(Y)
  
     MessageBox.Show(X.GetType.ToString)
  
   End Sub
  
 End Class  

Monday, January 24, 2011

Assignment1 - Creating Database and table, inserting records, and selecting all records

 create database Frogs
  
 create table Wyoming_Species
  
      (
  
      Frog_ID int identity (1,1) PRIMARY KEY,
  
      Scientific_Name varchar (100),
  
      IUCN_Red_List_Status varchar (50),
  
      Vernacular_Name varchar (50),
  
      Family varchar(30)
  
      );
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Bufo baxteri', 'Extinct in the Wild(EW)', 'Wyoming Toad', 'Bufonidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Bufo boreas', 'Near Threatened(NT)', 'Western Toad', 'Bufonidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Bufo cognatus', 'Least Concern(LC)', 'Great Plains Toad', 'Bufonidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Bufo hemiophrys', 'Lese Concern(LC)', 'Canadian Toad', 'Bufonidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Bufo woodhousii', 'Least Concern(LC)', 'Woodhouse''s Toad', 'Bufonidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Psedacris maculata', 'Least Concern(LC)', 'Boreal Chorus Frog', 'Hylidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Rana catesbeiana', 'Least Concern(LC)', 'Bullfrog', 'Ranidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Ranna luteiventris', 'Least Concern(LC)', 'Columbia Spotted Frog', 'Ranidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Rana pipiens', 'Least Concern(LC)', 'Northern Leopard Frog', 'Ranidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Rana sylvatica', 'Least Concern(LC)', 'Wood Frog', 'Ranidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Spea bombifrons', 'Least Concern(LC)', 'Plains Spadefoot', 'Scaphiopodidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Spea intermontana', 'Least Concern(LC)', 'Great Basin Spreadfoot', 'Scaphiopodidae');
  
 Insert Into Wyoming_Species
  
 (Scientific_Name, IUCN_Red_List_Status, Vernacular_Name, Family)
  
 Values
  
 ('Ambystoma mavortium', ' ', 'Barred Tiger Salamander', 'Ambystomatidae');
  
 select *
  
 from Wyoming_Species  

Create and Use Database

 create database Fields
  
 Use Fields