Public Class Form1 '1. Put a textbox and a button on the form. The user must enter a number and press the button. 'When the button is pressed, it will add that many buttons to the form. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num As Integer num = CInt(TextBox1.Text) For num = 1 To num ListBox1.Items.Add(num) Next End Sub Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick ListBox1.Items.Clear() End Sub '2. If you were to put away a certain amount of money every month, how many years would it take 'you to save up $10,000. Use a textbox to gather the amount that is to be put away every month. 'Use a label to display the number of years it would take. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim pay, count, total, goal As Integer goal = 10000 count = 1 pay = CInt(TextBox2.Text) Do While total < goal total += pay count += 1 Loop Label1.Text = FormatNumber((count / 12), 1) & " years left until you get to $10,000.00" End Sub '3. Write a program that will create a times table. '1 2 3 4 5 6 7 8 9 10 '2 4 6 8 10 12 14 16 18 20 '..… 'You could use labels or buttons to hold the numbers. Generate these dynamically and add them 'to the Me.Controls collection. 'You will have to use two loops, one inside of the other to get this to work. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For x = 1 To 10 For y = 1 To 10 Dim button As New Button button.Location = New Point(35 * x, 25 * y) button.Width = 35 Me.Controls.Add(button) button.Text = (x * y) Next Next End Sub End Class
Monday, February 28, 2011
Programming 2 */ A few programs with Loops */
'Loops
Friday, February 25, 2011
Advanced Relation Database */ Outer Joins */
SQL OUTER JOIN has 2 sub-types called: LEFT OUTER JOIN and RIGHT OUTER JOIN.
The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTER keyword in most databases), selects all the rows from the first table listed after the FROM clause, no matter if they have matches in the second table.If we slightly modify our last SQL statement to:
The result will be the following:
As you can see we have selected everything from the Customers (first table). For all rows from Customers, which don’t have a match in the Sales (second table), the SalesPerCustomer column has amount NULL (NULL means a column contains nothing).
The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT JOIN, except that it returns all rows from the second table (the right table in our SQL JOIN statement).
The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTER keyword in most databases), selects all the rows from the first table listed after the FROM clause, no matter if they have matches in the second table.If we slightly modify our last SQL statement to:
SELECT Customers.FirstName, Customers.LastName, SUM(Sales.SaleAmount) AS SalesPerCustomer FROM Customers LEFT JOIN Sales ON Customers.CustomerID = Sales.CustomerID GROUP BY Customers.FirstName, Customers.LastNameand the Sales table still has the following rows:
CustomerID | Date | SaleAmount |
2 | 5/6/2004 | $100.22 |
1 | 5/6/2004 | $99.95 |
The result will be the following:
FirstName | LastName | SalesPerCustomers |
John | Smith | $99.95 |
Steven | Goldfish | $100.22 |
Paula | Brown | NULL |
James | Smith | NULL |
As you can see we have selected everything from the Customers (first table). For all rows from Customers, which don’t have a match in the Sales (second table), the SalesPerCustomer column has amount NULL (NULL means a column contains nothing).
The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT JOIN, except that it returns all rows from the second table (the right table in our SQL JOIN statement).
Wednesday, February 23, 2011
Advanced Relation Database */ Movie Quotes */
--The script for the Movie quotes
--Select statements for the Movie quotes.
USE [DoubleTechnicalQuotes] GO /****** Object: Table [dbo].[xQuoteRef] Script Date: 02/23/2011 14:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[xQuoteRef]( [xID] [int] IDENTITY(1,1) NOT NULL, [mID] [int] NULL, [aID] [int] NULL, [qID] [int] NULL, PRIMARY KEY CLUSTERED ( [xID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[randomizer] Script Date: 02/23/2011 14:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[randomizer]( [quoteid] [int] NULL, [randomid] [int] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[MovieQuote] Script Date: 02/23/2011 14:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[MovieQuote]( [qID] [int] IDENTITY(1,1) NOT NULL, [aID] [int] NULL, [MovieQuote] [varchar](200) NULL, CONSTRAINT [PK__MovieQuo__C276CFE907020F21] PRIMARY KEY CLUSTERED ( [qID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[Movie] Script Date: 02/23/2011 14:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Movie]( [mID] [int] IDENTITY(1,1) NOT NULL, [MovieName] [varchar](50) NULL, PRIMARY KEY CLUSTERED ( [mID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[ActorActress] Script Date: 02/23/2011 14:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[ActorActress]( [aID] [int] IDENTITY(1,1) NOT NULL, [ActorActressName] [varchar](50) NULL, PRIMARY KEY CLUSTERED ( [aID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO
--Select statements for the Movie quotes.
select m.MovieName Movie, a.ActorActressName Actor_or_Actress, q.MovieQuote Quote from Movie m inner join xQuoteRef x on m.mID = x.mID inner join ActorActress a on a.aID = x.aID inner join MovieQuote q on q.aID = x.qID where q.MovieQuote like '%Hey%' select m.MovieName Movie, a.ActorActressName Actor_or_Actress, q.MovieQuote Quote from Movie m inner join xQuoteRef x on m.mID = x.mID inner join ActorActress a on a.aID = x.aID inner join MovieQuote q on q.aID = x.qID where a.ActorActressName = 'Dr. Rumack'
Friday, February 18, 2011
Programming 2 */ Kinds of Loops */
A Do loop repeatedly executes a block of statements either as long as or until a certain condition is true. The condition can be checked either at the top of the loop or at the bottom. There are two different ways that you can do the Do loop. It first can be done by putting While after the Do.
Dim num As Integer = 1 Do While num <= 7 MessageBox.Show(num) num += 1 LoopThe second Do can be done by putting the While after the Loop.
Dim num As Integer = 1 Do MessageBox.Show(num) num += 1 Loop While num <= 7A For...Next loop repeats a block of statements a fixed number of times. The counter variable assumes an initial value and increases it by one after each pass through the loop until it reaches the terminating value. Alternative increment values can be specified with the Step keyword.
'Displays in a message box the first five numbers and their square roots. 'I also used the step keyword to skip step 2. So it will skip 2 4. For i As Integer = 1 To 5 Step 2 MessageBox.Show(i & " " & i ^ 2) NextA For Each loop repeats a group of statements for each element in an array.
Dim i As Integer = 500 For Each number As Integer In New Long() {50, 15, 32} MessageBox.Show(number & " ") Next
Sunday, February 13, 2011
Programming 2 */ Form Object Manipulation */
1. Create a form with a single button (use the gui for this one). When the button is hovered over, move the button to another part of the form. The button should move back and forth between 2 points. If you want to be special, move the button to a random part of the form. You will have to use a random number generator for the x and y coordinates making sure the random x and y are not larger than the form height and width. If you don't feel like being special, just...
a. Button 2: This button will make the textbox enabled/disabled.
b. Button 3: Turn a background color on the textbox on and off. (Toggle between white and
another color)
c. Button 4: Put text inside of the text box and take it away
d. Button 5: Change the border style of the textbox between none and fixed3d
Create a form with 4 buttons and one text box (use the gui). The button wording should
describe what it does.
Create a form with 3 buttons and a listbox.
Load 3 items into the listbox on load so that its not empty
Button 1: Select Item 1
Button 2: Select Item 2
Button 3: Select Item 3
Public Class Form1 Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.MouseEnter Dim rnd1 As New Random Dim x As Integer = rnd1.Next(150) Dim y As Integer = rnd1.Next(300) Button.Location = New Point(x, y) End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.Click MessageBox.Show("You Win") End Sub2.
a. Button 2: This button will make the textbox enabled/disabled.
b. Button 3: Turn a background color on the textbox on and off. (Toggle between white and
another color)
c. Button 4: Put text inside of the text box and take it away
d. Button 5: Change the border style of the textbox between none and fixed3d
Create a form with 4 buttons and one text box (use the gui). The button wording should
describe what it does.
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click If TextBox1.Enabled = True Then TextBox1.Enabled = False Else : TextBox1.Enabled = True End If End Sub Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click If TextBox1.BackColor = Color.White Then TextBox1.BackColor = Color.Black Else : TextBox1.BackColor = Color.White End If End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click If TextBox1.Text = "" Then TextBox1.Text = "HI!!!" Else : TextBox1.Text = "" End If End Sub Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click If TextBox1.BorderStyle = BorderStyle.None Then TextBox1.BorderStyle = BorderStyle.Fixed3D Else : TextBox1.BorderStyle = BorderStyle.None End If End Sub3. Create a form with a button (using the gui). When this button is clicked, it will create 3 labels and 3 textboxes associated with those labels. When the textboxes are hovered over, change their background color. When it is not being hovered over, change the background color back to white.
Dim l1, l2, l3 As New Label Dim WithEvents t1, t2, t3 As New TextBox Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click l1.Location = New Point(50, 50) l1.Text = "Label1" l2.Location = New Point(50, 100) l2.Text = "Label2" l3.Location = New Point(50, 150) l3.Text = "Label3" Me.Controls.Add(l1) Me.Controls.Add(l2) Me.Controls.Add(l3) t1.Location = New Point(150, 50) t2.Location = New Point(150, 100) t3.Location = New Point(150, 150) Me.Controls.Add(t1) Me.Controls.Add(t2) Me.Controls.Add(t3) End Sub Private Sub t1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t1.MouseEnter t1.BackColor = Color.Black End Sub Private Sub t2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.MouseEnter t2.BackColor = Color.Black End Sub Private Sub t3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t3.MouseEnter t3.BackColor = Color.Black End Sub Private Sub t1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t1.MouseLeave t1.BackColor = Color.White End Sub Private Sub t2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.MouseLeave t2.BackColor = Color.White End Sub Private Sub t3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t3.MouseLeave t3.BackColor = Color.White End Sub4.
Create a form with 3 buttons and a listbox.
Load 3 items into the listbox on load so that its not empty
Button 1: Select Item 1
Button 2: Select Item 2
Button 3: Select Item 3
Dim WithEvents b1, b2, b3 As New Button Dim lb1 As New ListBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load b1.Location = New Point(300, 140) b2.Location = New Point(300, 170) b3.Location = New Point(300, 200) lb1.Location = New Point(300, 230) b1.Text = "Button 7" b2.Text = "Button 8" b3.Text = "Button 9" Me.Controls.Add(b1) Me.Controls.Add(b2) Me.Controls.Add(b3) Me.Controls.Add(lb1) lb1.Items.Add("You") lb1.Items.Add("are") lb1.Items.Add("annoying!!!") End Sub Private Sub b1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b1.Click lb1.SelectedIndex = 0 End Sub Private Sub b2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b2.Click lb1.SelectedIndex = 1 End Sub Private Sub b3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b3.Click lb1.SelectedIndex = 2 End Sub Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click TextBox1.Text = "" TextBox1.BackColor = Color.White TextBox1.BorderStyle = BorderStyle.Fixed3D TextBox1.Enabled = True t1.Text = "" t2.Text = "" t3.Text = "" Button.Location = New Point(12, 11) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Application.Exit() End Sub End Class
Friday, February 4, 2011
Programming 2 */ Hand Coding Controls */
Public Class HowToHandCodeControls Private Sub HowToHandCodeControls_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim B As New Button B.Text = "Berries" B.Location = New Point(1, 1) B.Name = "btnBerries" B.Size = New System.Drawing.Size(50, 50) Me.Controls.Add(B) Dim T As New TextBox T.Text = "Terry" T.Location = New Point(100, 1) T.ReadOnly = False Me.Controls.Add(T) Dim L As New Label L.Text = "Larry" L.Location = New Point(1, 100) T.Enabled = False Me.Controls.Add(L) Dim LB As New ListBox LB.Text = "Larry's Berries" LB.Location = New Point(100, 100) Me.Controls.Add(LB) End Sub End Class
Thursday, February 3, 2011
Programming 2 /* Conditionals */
Public Class Conditionals Private Sub Conditionals_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '1) 'Mr. Spacely has been rethinking the company's shipping schemes. As an employee for Spacely's 'Sprockets, Spacely has asked you to write a quick program that will be used to determine shipping 'costs. 'A total purchase of items totaling under $50, we charge $5 shipping. 'A total purchase of items totaling $50 and over, there is no shipping charge. Dim TotalCost, Cost, Shipping As Decimal Cost = 49 If Cost < 50 Then Shipping = 5.0 ElseIf Cost >= 50 Then Shipping = 0.0 End If TotalCost = Cost + Shipping MessageBox.Show(TotalCost) '2) 'You are looking for something to control your heat in your apartment and you discover there is 'NOT an app for that. It's about time that someone created one. You decide that you are the one 'to do it. Here's what you want to do. '- You want to turn the heat on when the temp has dropped below 72 '- You also want to turn the AC on when the temp gets above 76 'Your app should display in a message box if the heat is on, the AC is on, or if the system is idle. 'Plug in different temps for the room in a variable to see what the thermostat will do with it. Dim Temp As Integer Temp = 76 If Temp < 72 Then MessageBox.Show("The Heat Is On") ElseIf Temp > 76 Then MessageBox.Show("The AC Is On") Else MessageBox.Show("The System Is Idle") End If '3) 'a. 0-2 yrs - XS 'b. 3-4 yrs - S 'c. 5-8 yrs - M 'd. 9-12 yrs - L 'e. 13+ yrs - XL 'You are working on a clothing website where people can buy kids socks. It's really hard for the 'customers to know what size they should buy for what age. It would be a good idea for the 'customer to have a tool to input their child's age and have the website suggest a size for them. 'Write a tool where you can set the age as a variable and have it suggest on of the sizes below: Dim Shirts As Integer Select Case Shirts Case 0 - 2 MessageBox.Show("XS") Case 3 - 4 MessageBox.Show("S") Case 5 - 8 MessageBox.Show("M") Case 9 - 12 MessageBox.Show("L") Case Is >= 13 MessageBox.Show("XL") End Select
Subscribe to:
Posts (Atom)
Classes
Programming II
Advanced Relational Database