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