1: Public Class Form1
2: Dim nWord As Integer
3: Dim nCharacter As Integer
4: Dim nSentence As Integer
5: Dim nSpace As Integer
6: Private Sub Analyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Analyze.Click
7: Dim str As String = txtPar.Text
8: nWord = WordCount(str)
9: nCharacter = CharacterCount(str)
10: nSentence = SentenceCount(str)
11: nSpace = SpaceCount(str)
12: Answer()
13: End Sub
14: Private Function CharacterCount(ByVal str As String) As Integer
15: Return str.Length
16: End Function
17: Public Function WordCount(ByVal value As String) As Integer
18: Return System.Text.RegularExpressions.Regex.Matches(value, "\S+").Count()
19: End Function
20: Public Function SentenceCount(ByVal sentence As String) As Integer
21: Dim x As Integer
22: x = sentence.Split(".").Count()
23: x -= 1
24: Return x
25: End Function
26: Public Function SpaceCount(ByVal space As String) As Integer
27: Dim x As Integer
28: x = space.Split(" ").Count()
29: x -= 1
30: Return x
31: End Function
32: Private Sub Answer()
33: txtWords.Text = nWord
34: txtCharacters.Text = nCharacter
35: txtSentences.Text = nSentence
36: txtSpaces.Text = nSpace
37: End Sub
38: End Class
Wednesday, April 13, 2011
Practice # 6
Wednesday, March 30, 2011
Practice # 5
Hashtables and Queues
1.
2.
3.
1.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str() As String = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
For Each s As String In str
MsgBox(s)
Next
End Sub
End Class
2.
Public Class btnFirst
Dim info As New Hashtable
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
info.Clear()
info.Add("First Name", txtFirst.Text)
info.Add("Last Name", txtLast.Text)
info.Add("E-mail", txtMail.Text)
txtFirst.Clear()
txtLast.Clear()
txtMail.Clear()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(info.Item("First Name"))
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
MsgBox(info.Item("Last Name"))
End Sub
Private Sub btnMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMail.Click
MsgBox(info.Item("E-mail"))
End Sub
End Class
3.
Public Class frmPrinter
Dim print As New Queue
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim page As New Hashtable
page.Add("Title", txtTitle.Text)
page.Add("Pages", txtPages.Text)
print.Enqueue(page)
refreshJobs()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
print.Dequeue()
refreshJobs()
End Sub
Private Sub refreshJobs()
lstQueue.Items.Clear()
For Each d As Hashtable In print
lstQueue.Items.Add(d.Item("Pages") & (" ") & d.Item("Title"))
Next
End Sub
End Class
Monday, March 21, 2011
Practice # 4
1.
2.
3.
Private Sub btnNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumber.Click
Dim number As Integer = txtNumber.Text
Dim x As Integer = 0
lstNumber.Items.Clear()
For x = 1 To number
lstNumber.Items.Add(x & " item")
Next
End Sub
End Class
2.
Public Class Form1
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
Dim pay, months, total As Integer
months = 0
total = 0
pay = CInt(txtPay.Text)
Do While total < 10000
total += pay
months += 1
Loop
lblTotal.Text = (months / 12).ToString("f1")
End Sub
End Class
3.
Public Class Form1
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
For x = 1 To 10
For y = 1 To 10
Dim button1 As New Button
button1.Location = New Point(40 * x, 40 * y)
button1.Width = 40
Me.Controls.Add(button1)
button1.Text = x * y
Next
Next
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
End Class
Saturday, March 5, 2011
Validation
<script language="javascript">
<!--
Function CheckForm(form)
{
for(var intCtr = 0; intCtr <= (form.elements.length - 5); ++intCtr)
{
var temp = form.elements[intCtr];
if(temp.type == "text" && temp.value == "")
{
alert("Please Enter All Information!");
temp.focus();
return false;
}
}
return true;
}
//-->
</script>
This sample piece of JavaScript does some validation, but it doesn't check for all the in-formation that you might need on the form you are building.
Redirect
Protected Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Server.Transfer("Page2.aspx", True)
End Sub
This is a example of how to redirect a user to another page when a button
Menu control
<asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="3">
<Items>
<asp:MenuItem Text="File" Value="File">
<asp:MenuItem Text="New" Value="New"></asp:MenuItem>
<asp:MenuItem Text="Open" Value="Open"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Edit" Value="Edit">
<asp:MenuItem Text="Copy" Value="Copy"></asp:MenuItem>
<asp:MenuItem Text="Paste" Value="Paste"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="View" Value="View">
<asp:MenuItem Text="Normal" Value="Normal"></asp:MenuItem>
<asp:MenuItem Text="Preview" Value="Preview"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
This is a example of a Menu ControlFor making a menu change its orientation you just need to change the Orientation property of the Menu control to Horizontal or Vertical.
The Menu control has two modes of display: static and dynamic. Static display means that the Menu control is fully expanded all the time. The entire structure is visible, and a user can click on any part. In a dynamically displayed menu, only the portions you specify are static, while their child menu items are displayed when the user holds the mouse pointer over the parent node.
Each menu level supports style properties. If no dynamic style properties are set, the static style properties are used. If dynamic style properties are set and no static style properties are set, the default rendering of static style properties is used. The Menu control style hierarchy is as follows:
- Control
- SubMenuStyles
- MenuItemStyles
- SelectedItemStyles
- HoverMenuItemStyles
Wednesday, February 16, 2011
Loops
This is a example of a FOR LOOP. The For is the keyword you use to start the loop.
basically what is happening is that it is going to step threw by 1 until it gets to 10
This is a example of Do (While last)
Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.
This is a example of Do (While first)
Do checks when the loop starts.
This is a example of a For Each
This is going to display each letter one by one until it spells the whole thing out.
For i = 1 To 10 Step 1
Print("programmershelp")
Next i
End Sub
basically what is happening is that it is going to step threw by 1 until it gets to 10
This is a example of Do (While last)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Do
Debug.Print("hello")
x = x + 1
Loop Until x = 10
End Sub
End Class
Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.
This is a example of Do (While first)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Do Until x = 10
Debug.Print("hello")
x = x + 1
Loop
End Sub
End Class
Do checks when the loop starts.
This is a example of a For Each
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim siteName As String
Dim singleChar As Char
siteName = "HTTP://NET-INFORMATIONS.COM"
For Each singleChar In siteName
MsgBox(singleChar)
Next
End Sub
This is going to display each letter one by one until it spells the whole thing out.
Monday, February 14, 2011
Practice 3 assignment
1.
2.
3.
Public Class Form1
Private Sub btnMove_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMove.MouseHover
Dim P1 As New Point(5, 239)
Dim P2 As New Point(39, 215)
If btnMove.Location = P1 Then
btnMove.Location = P2
ElseIf btnExit.Location = P2 Then
btnMove.Location = P1
Else
btnMove.Location = P1
End If
'btnMove.Location = New Point(39, 151)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
2.
Public Class Form1
Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click
'to change the color back and forth i just used a if statement so that if i click the button and it is Black then it will
'change to White but if it is not already Black then it would change to black
If txtTest.BackColor = Color.Black Then
txtTest.BackColor = Color.White
Else
txtTest.BackColor = Color.Black
End If
End Sub
Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
'I did this one the same as the color one the only change i made was that i am using text now so the second one is just a
'empty string
If txtTest.Text = "hello" Then
txtTest.Text = " "
Else
txtTest.Text = "hello"
End If
End Sub
Private Sub btnBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorder.Click
'This one it the same as the two above.
If txtTest.BorderStyle = BorderStyle.Fixed3D Then
txtTest.BorderStyle = BorderStyle.None
Else
txtTest.BorderStyle = BorderStyle.Fixed3D
End If
End Sub
Private Sub btnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisable.Click
'This one is also the same
If txtTest.Enabled = False Then
txtTest.Enabled = True
Else
txtTest.Enabled = False
End If
End Sub
End Class
3.
Public Class Form1
Dim lbl1, lbl2, lbl3 As New Label
Dim WithEvents txt1, txt2, txt3 As New TextBox
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
lbl1.AutoSize = True
lbl1.Text = "Hi"
Me.Controls.Add(lbl1)
lbl1.Location = New Point(8, 163)
lbl2.AutoSize = True
lbl2.Text = "Good"
Me.Controls.Add(lbl2)
lbl2.Location = New Point(5, 236)
lbl3.AutoSize = True
lbl3.Text = "Morning"
Me.Controls.Add(lbl3)
lbl3.Location = New Point(1, 6)
txt1.Location = New Point(65, 6)
Me.Controls.Add(txt1)
txt1.Name = "txt1"
txt2.Location = New Point(125, 240)
Me.Controls.Add(txt2)
txt2.Name = "txt2"
txt3.Location = New Point(54, 166)
Me.Controls.Add(txt3)
txt3.Name = "txt3"
End Sub
Private Sub txthightlight1() Handles txt1.MouseEnter
txt1.BackColor = Color.Blue
End Sub
Private Sub txthightlight1B() Handles txt1.MouseLeave
txt1.BackColor = Color.White
End Sub
Private Sub txthightlight2() Handles txt2.MouseEnter
txt2.BackColor = Color.Black
End Sub
Private Sub txthightlight2B() Handles txt2.MouseLeave
txt2.BackColor = Color.White
End Sub
Private Sub txthightlight3() Handles txt3.MouseEnter
txt3.BackColor = Color.Red
End Sub
Private Sub txthightlight3B() Handles txt3.MouseLeave
txt3.BackColor = Color.White
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Practice 2 assignment
1.
2.
3.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim total, cost As Integer
cost = 60
If cost < 50 Then
total = cost + 5
ElseIf cost > 50 Then
total = cost
End If
MessageBox.Show(total)
End Sub
End Class
2.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim temp As Integer
temp = 72
If temp < 72 Then
MessageBox.Show("The Heat is on")
ElseIf temp > 76 Then
MessageBox.Show("The AC is on")
ElseIf temp > 77 & temp < 71 Then
MessageBox.Show("Idle")
End If
End Sub
End Class
3.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim size As String
Dim shirt As String
size = 5
shirt = size
Select Case shirt
Case 0 To 2
size = "XS"
Case 3 To 5
size = "S"
Case 6 To 8
size = "M"
Case 9 To 11
size = "L"
Case Is < 11
size = "XL"
End Select
MessageBox.Show(size)
End Sub
End Class
Friday, February 4, 2011
This is some code that allows you to add buttons, labels, textbox, and listbox
First you have to declare then control then from there you have to set what ever you want like the size, back color, or any thing like that. Once you done with that you have to follow it with a Me.Controls.Add() to add it to the form.
Dim Button1 As New Button
Dim textbox1 As New TextBox
Dim label1 As New Label
Dim listbox1 As New ListBox
Button1.Text = "Go"
Me.Controls.Add(Button1)
textbox1.Text = "Hello"
textbox1.BackColor = Color.Chocolate
Me.Controls.Add(textbox1)
label1.Text = "Good Morning"
label1.BackColor = Color.Aqua
Me.Controls.Add(label1)
listbox1.BackColor = Color.Black
listbox1.Location = New System.Drawing.Point(77, 162)
Me.Controls.Add(listbox1)
First you have to declare then control then from there you have to set what ever you want like the size, back color, or any thing like that. Once you done with that you have to follow it with a Me.Controls.Add() to add it to the form.
Monday, January 31, 2011
If Statements
This is a example of a If statement.
I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.
This is a example of a If statment where its either or
This is a example of a if statement where many decisions are made
This is a example of a case statement
1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select
Dim name, correct As String
name = "Dalonte"
If name = "Dalonte" Then
correct = "Yes"
End If
MessageBox.Show(correct)
I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.
This is a example of a If statment where its either or
Dim name, correct As String
name = "Gibson"
If name = "Dalonte" Then
correct = "yes"
Else
correct = "no"
End If
MessageBox.Show(correct)
This is just like my example above but the only thing i did different is that i added a "ELSE" so that if the name does not match up it was say no This is a example of a if statement where many decisions are made
Dim name, As String
name = "anderson"
If name = "Dalonte" Then
MessageBox.Show("First Name")
ElseIf name = "Gibson" Then
MessageBox.Show("last name")
ElseIf name = "anderson" Then
MessageBox.Show("Middle Name")
End If
The only thing that i did different on this one is that i added a elseif statement which allows me to make more then 2 decisions.This is a example of a case statement
Select [ Case ] testexpression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select
Friday, January 28, 2011
How to join a String with another String
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = "Bill"
LastName = "Gates"
FullName = FirstName & LastName
MessageBox.Show(FullName)
first you have to declare your variables then you have to give each variable a value such as Bill and Gates. From there you add them together with a "&" sign then display it with a messagebox
Monday, January 24, 2011
How to set variables
This is how you set the following variables: String, Integer, Decimal
The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory.
The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can represent values in excess of 7.9228 x 10^28. It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.
The default value of Decimal is 0.
Use the String data type to hold multiple characters without the array management overhead of Char(), an array of Char elements.
The default value of String is Nothing (a null reference). Note that this is not the same as the empty string (value "").
The default value of Integer is 0.
This is how you set a Boolean variable:
Use the Boolean data type to contain two-state values such as true/false, yes/no, or on/off.
The default value of Boolean is False.
When Visual Basic converts numeric data type values to Boolean, 0 becomes False and all other values become True. When Visual Basic converts Boolean values to numeric types, False becomes 0 and True becomes -1.
This is how to convert a number variable into a string
you start by declaring a int, then after you do that you have to declare a string = int.ToString()
so that what ever value you entered for your int will also be = to your string variable.
This is how you convert a int into a decimal
This is easy all you have to do is that when you declare your int follow it by as Double
This is how you join two strings
For this one all you have to is declare to string and give them both a value. This declare another variable witch will be use to join them. Once you declare another string to add the other two you have to = is to String1 & String2
Public Class Form1
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim FirstName As String
Dim Age As Integer
Dim GPA As Decimal
Dim Result As DialogResult
FirstName = "Dalonte"
Age = "22"
GPA = "3.6"
Result = MessageBox.Show(FirstName & Age & GPA)
End Sub
End Class
The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory.
The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can represent values in excess of 7.9228 x 10^28. It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.
The default value of Decimal is 0.
Use the String data type to hold multiple characters without the array management overhead of Char(), an array of Char elements.
The default value of String is Nothing (a null reference). Note that this is not the same as the empty string (value "").
The default value of Integer is 0.
This is how you set a Boolean variable:
Dim runningVB As Boolean
' Check to see if program is running on Visual Basic engine.
If scriptEngine = "VB" Then
runningVB = True
End If
Use the Boolean data type to contain two-state values such as true/false, yes/no, or on/off.
The default value of Boolean is False.
When Visual Basic converts numeric data type values to Boolean, 0 becomes False and all other values become True. When Visual Basic converts Boolean values to numeric types, False becomes 0 and True becomes -1.
This is how to convert a number variable into a string
Dim int As Integer = 789
Dim str As String = int.ToString()
str now holds 789 as a string.
you start by declaring a int, then after you do that you have to declare a string = int.ToString()
so that what ever value you entered for your int will also be = to your string variable.
This is how you convert a int into a decimal
Dim d=132.31223 as Double
This is easy all you have to do is that when you declare your int follow it by as Double
This is how you join two strings
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = "Bill"
LastName = "Gates"
FullName = FirstName & LastName
Textbox1.Text = FullName
For this one all you have to is declare to string and give them both a value. This declare another variable witch will be use to join them. Once you declare another string to add the other two you have to = is to String1 & String2
Wednesday, January 19, 2011
Repeatable Process examples
Calculate the final grade
30% Blog 40% assignments 10% peer evals 20% final
86/100 Blog, 345/450 assignment, 43/50 peer, 55/80 final
BlogTP = 100
BlogS = 86 86/100 x .3 = 23.8
BlogW = .3
BlogP = BlogS/BlogTP
AssignTP = 450
AssignS = 345
AssignP = AssignS/AssignTP(76.7) x .4 = 30.68
Grade = (BlogP x BlogW) + (AssignP x AssignW)
30% Blog 40% assignments 10% peer evals 20% final
86/100 Blog, 345/450 assignment, 43/50 peer, 55/80 final
BlogTP = 100
BlogS = 86 86/100 x .3 = 23.8
BlogW = .3
BlogP = BlogS/BlogTP
AssignTP = 450
AssignS = 345
AssignP = AssignS/AssignTP(76.7) x .4 = 30.68
Grade = (BlogP x BlogW) + (AssignP x AssignW)
Tuesday, January 18, 2011
Content place holder
Content place holder is the part of the website that changes, then from there is defined by a content page. Here is some example code:
<%-- ContentPlaceHolder control --%>
<asp:contentplaceholder id="FlowerText" runat="server"/>
<%-- ContentPlaceHolder with default content --%>
<asp:contentplaceholder id="FlowerText" runat="server">
<h3>Welcome to my florist website!</h3>
</asp:contentplaceholder>
Content Page
A content page is the part of the website that changes every time you go to a different page of the website. Content pages define the content place holders. Some example code is:
The contentplaceholderid lets you know what place holder you are working with at the time.
<%@ Page MasterPageFile="Site.master" %>
<asp:content id="Content1" contentplaceholderid="FlowerText" runat="server">
With sunshine, water, and careful tending, roses will bloom several times in a season.
</asp:content>
<asp:content id="Content2" contentplaceholderid="FlowerPicture" runat="server">
<asp:Image id="image1" imageurl="~/images/rose.jpg" runat="server"/>
</asp:content>
The contentplaceholderid lets you know what place holder you are working with at the time.
Master Page
Master page is basically a template page that you see on every page of the web site. Here is some example code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head>
<body> <form id="form1" runat="server"> <div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form> </body> </html>
Create Web Project
Step:
1) Go to file and click new web site
2) At the bottom name the file then click on OK
1) Go to file and click new web site
2) At the bottom name the file then click on OK
Friday, January 14, 2011
Name: Message Box
Description: Making a message box
Description: Making a message box
MessageBox.Show("Hello World!")
Subscribe to:
Posts (Atom)