Public Class Form1
Dim WithEvents lstItems As New ListBox
Dim strone As String = "Item One"
Dim strtwo As String = "Item Two"
Dim strthree As String = "Item Three"
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lstItems.Location = New Point(82, 5)
lstItems.Items.Add(strone)
lstItems.Items.Add(strtwo)
lstItems.Items.Add(strthree)
Me.Controls.Add(lstItems)
End Sub
Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
lstItems.SelectedIndex = 0
End Sub
Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
lstItems.SelectedIndex = 1
End Sub
Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
lstItems.SelectedIndex = 2
End Sub
End Class
Monday, February 14, 2011
Assignment Three - Question Four
Create a form with three buttons and a listbox. Upon loading put three items in the listbox so it is not empty. Make button one selct item one, button two select item two, and button three select item three.
Assignment Three - Question Three
When button is clicked, it will create 3 labels and 3 textboxes associated with those labels. When textboxes are hovered over, change their background color. When it is not being hovered over, change the bacground color back to white.
Public Class Form1
Dim WithEvents txtone, txttwo, txtthree As New TextBox
Dim WithEvents lblone, lbltwo, lblthree As New Label
Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
txtone.Height = 75
txtone.Width = 100
txtone.Text = "I Am Textbox One"
txtone.Location = New Point(4, 1)
txtone.BackColor = Color.White
txttwo.Height = 75
txttwo.Width = 100
txttwo.Text = "I Am Textbox Two"
txttwo.Location = New Point(225, 1)
txttwo.BackColor = Color.White
txtthree.Height = 75
txtthree.Width = 100
txtthree.Text = "I Am Textbox Three"
txtthree.Location = New Point(450, 1)
txtthree.BackColor = Color.White
lblone.Height = 100
lblone.Width = 100
lblone.Text = "I Am Label One"
lblone.Location = New Point(4, 85)
lbltwo.Height = 100
lbltwo.Width = 100
lbltwo.Text = "I Am Label Two"
lbltwo.Location = New Point(225, 85)
lblthree.Height = 100
lblthree.Width = 100
lblthree.Text = "I Am Label Three"
lblthree.Location = New Point(450, 85)
Me.Controls.Add(txtone)
Me.Controls.Add(txttwo)
Me.Controls.Add(txtthree)
Me.Controls.Add(lblone)
Me.Controls.Add(lbltwo)
Me.Controls.Add(lblthree)
End Sub
Private Sub txtone_mouseenter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtone.MouseEnter
txtone.BackColor = Color.Red
End Sub
Private Sub txtone_mouseleave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtone.MouseLeave
txtone.BackColor = Color.White
End Sub
Private Sub txttwo_mouseenter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttwo.MouseEnter
txttwo.BackColor = Color.Red
End Sub
Private Sub txttwo_mouseleave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttwo.MouseLeave
txttwo.BackColor = Color.White
End Sub
Private Sub txtthree_mouseenter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtthree.MouseEnter
txtthree.BackColor = Color.Red
End Sub
Private Sub txtthree_mouseleave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtthree.MouseLeave
txtthree.BackColor = Color.White
End Sub
End Class
Assignment Three - Question Two
Form with 4 buttons
1 - enable/disable textbox
2 - change background color in textbox between two colors
3 - Put in and remove text in textbox
4 - Change border style between fixed 3d and none
1 - enable/disable textbox
2 - change background color in textbox between two colors
3 - Put in and remove text in textbox
4 - Change border style between fixed 3d and none
Public Class Form1
Private Sub btnEnable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnable.Click
If txtBox.Enabled = True Then
txtBox.Enabled = False
ElseIf txtBox.Enabled = False Then
txtBox.Enabled = True
End If
End Sub
Private Sub btnBackground_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackground.Click
If txtBox.BackColor = Color.White Then
txtBox.BackColor = Color.Red
ElseIf txtBox.BackColor = Color.Red Then
txtBox.BackColor = Color.White
End If
End Sub
Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click
If txtBox.Text = "Now You See Me" Then
txtBox.Text = ""
ElseIf txtBox.Text = "" Then
txtBox.Text = "Now You See Me"
End If
End Sub
Private Sub btnBoarder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBoarder.Click
If txtBox.BorderStyle = BorderStyle.Fixed3D Then
txtBox.BorderStyle = BorderStyle.None
ElseIf txtBox.BorderStyle = BorderStyle.None Then
txtBox.BorderStyle = BorderStyle.Fixed3D
End If
End Sub
End Class
Assignment 3 - Question One
When button is hovered over move button to a random location
Public Class Form1
Private Sub btn1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.MouseHover
Dim rnd1 As New Random
Dim x As Integer = rnd1.Next(100)
Dim y As Integer = rnd1.Next(100)
btn1.Location = New Point(x, y)
End Sub
End Class
Friday, February 4, 2011
Assignment
use Yummys
go
--drop table Brand
--drop table Flavor
--drop table xrefFlavorBrand
create table Brand
(
BrandID int identity(1,1) primary key
,BrandName varchar(50)
,BrandLocation varchar(50)
)
insert into Brand (BrandName, BrandLocation) values ('BlueBunny', 'San Francisco')
insert into Brand (BrandName, BrandLocation) values ('PurpleMonkey', 'Detroit')
insert into Brand (BrandName, BrandLocation) values ('PinkHippo', 'Malibu')
insert into Brand (BrandName, BrandLocation) values ('GreenRabbit', 'Tucson')
insert into Brand (BrandName, BrandLocation) values ('RainbowLamb', 'Minneapolis')
select *
from Brand
create table flavor
(
Flavor_ID int identity (1,1) PRIMARY KEY,
flavor_name varchar (40),
descraption varchar (100)
)
insert into flavor
(flavor_name, descraption)
values
('choclate', 'classic choclate')
insert into flavor
(flavor_name, descraption)
values
('Vanilla', 'Plain Vanilla')
insert into flavor
(flavor_name, descraption)
Values
('Neopolatin', '1/3 Choclate, 1/3 Vanilla. 1/3 Strawberry')
insert into flavor
(flavor_name, descraption)
Values
('Coffee', 'Fresh Cround Coffee Flavor')
insert into flavor
(flavor_name, descraption)
Values
('Sardine', 'Self-Explanatory')
select *
from flavor
create table xrefFlavorBrand
(
xrefID int identity (1,1) primary key
, BrandID int
, FlavorID int
)
Insert into xrefFlavorBrand (BrandID, FlavorID) values (1,1)
Insert into xrefFlavorBrand (BrandID, FlavorID) values (2,2)
Insert into xrefFlavorBrand (BrandID, FlavorID) values (3,3)
Insert into xrefFlavorBrand (BrandID, FlavorID) values (4,4)
insert into xrefFlavorBrand (BrandID, FlavorID) values (5,5)
select *
from xrefFlavorBrand
select FL.*, xFB.BrandID, B.BrandName
from flavor FL
inner join xrefFlavorBrand xFB
on FL.Flavor_ID = xFB.xrefID
inner join Brand B
on xFB.BrandID = B.BrandID
where FL.flavor_name = 'Coffee'
Adding a button, label, listbox, and text box programmatically
Here I added a button, label, listbox, and text box programmatically. I also changed some properties along the way.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtBox As New TextBox
Dim lblLabel As New Label
Dim btnButton As New Button
Dim lstList As New ListBox
txtBox.Height = 7
txtBox.Width = 150
txtBox.Text = "Hello"
txtBox.Location = New Point(50, 1)
lblLabel.Text = "Hola"
lblLabel.Location = New Point(50, 150)
btnButton.Height = 75
btnButton.Width = 75
btnButton.Text = "Bonjour"
btnButton.Location = New Point(50, 50)
lstList.Height = 70
lstList.Width = 50
lstList.Text = "Hi"
lstList.Location = New Point(50, 175)
Me.Controls.Add(txtBox)
Me.Controls.Add(lblLabel)
Me.Controls.Add(btnButton)
Me.Controls.Add(lstList)
End Sub
End Class
Wednesday, February 2, 2011
Using If and Case statements
1. Shipping Costs
2. Temperature Control App
3. Sock Size by Age
Public Class Form1
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
Dim itemscost As String
Dim totalcost As Integer
itemscost = txtItemsCost.Text
If itemscost >= 50 Then
totalcost = itemscost
ElseIf itemscost < 50 Then
totalcost = itemscost + 5
End If
MessageBox.Show(totalcost)
End Sub
End Class
2. Temperature Control App
Public Class Form1
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
Dim temp As Integer = txtTemp.Text
Dim AC As Integer = 76
Dim heat As Integer = 72
If temp < heat Then
MessageBox.Show("Heat Turned On")
ElseIf temp > AC Then
MessageBox.Show("AC Turned on")
ElseIf temp <> heat And AC Then
MessageBox.Show("Temperature Perfect")
End If
End Sub
End Class
3. Sock Size by Age
Public Class Form1
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSize.Click
Dim size As String
Dim age As String = txtAge.Text
Select Case age
Case 0 To 2
size = "XS"
Case 3 To 4
size = "S"
Case 5 To 8
size = "M"
Case 9 To 12
size = "L"
Case 13 To 20
size = "XL"
End Select
MsgBox(size)
End Sub
End Class
Subscribe to:
Posts (Atom)