Search This Blog

Sunday, July 17, 2011

Using progress bar in VB.NET

A simple example of how to user a progress bar.  Here we will do a
simple query, and advance through the records while showing a
progress bar.  In order to try this, simple create a new Windows
Application, and drap a progress bar control onto your form.Next,
you can add the code from below, and you should be all set.
The progress bar will automatically increase steps based on the
number of records we have in the database.This gives an idea to
the user of how long they will be waiting.


Progress Bar Code :-


DataSet DS = new DataSet();DS = GetDataSet("select * from Employees");
//Verify we have recordsif (DS != null && DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
{
      
//Set Progress Bar
      
ProgressBarMigration.Visible = true//Make it visible
      ProgressBarMigration.Minimum = 0;  //Set Min Steps
      ProgressBarMigration.Maximum = DS.Tables[0].Rows.Count;  //Set Number of Max Steps
      ProgressBarMigration.Value = 0;  //Initiliaze to beginning

      //parse through each record
      
foreach (DataRow dr in DS.Tables[0].Rows)
      {
            ProgressBarMigration.Value += 1;
            System.Threading.
Thread.Sleep(50);  //Sleep to slow down to see steps

            //Ideally here you would do your transactions
      }
      ProgressBarMigration.Visible =
false;
      
MessageBox.Show("Migration Complete.");
}

Destroy cookie using VB.NET and ASP.NET

This is a small function which allows you to destroy a cookie.
All that is needed is to pass the cookie name.  If the cookie is
found, it'll set it so that it has expired.

Public Shared Sub DestroyCookie(ByVal CookieName As String)
 Dim CookieObj As HttpCookie = HttpContext.Current.Request.Cookies("CookieName")
   
    If CookieObj IsNot Nothing Then
        CookieObj.Expires = DateTime.Now.AddDays(-1d)
        HttpContext.Current.Response.Cookies.Add(CookieObj)
       
    End If
End Sub


Just call this static function and.If you are calling it from a regular
class you may want to make it a non static method.  I had this is
a HttpHelper class, which I would just call by using
HttpHelper.DestroyCookie("mycookiename")