Wednesday, April 13, 2011

Practice # 6

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, March 30, 2011

Practice # 5

Hashtables and Queues


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.
   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 Control

For 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:
  1. Control
  2. SubMenuStyles
  3. MenuItemStyles
  4. SelectedItemStyles
  5. 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.

  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.