Category: VB.NET

Importing data from an Excel sheet

C# Example using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Linq; using System.Text; namespace Excel2Table { public class ExcelReader { /// <summary> /// Reads an excel file with OLEDB, and returns a datatable object from the content. The sheet to be imported /// needs to be named “Import” in the excel file. /// </summary> /// <param name=”sFilehandle”>Complete path to the excel file, including the filename and extension</param> /// <returns>A datatable containing the imported file</returns> […]

XtraReports – Selecting a paper tray

This sample shows how to enumerate and select a specific tray to use for printing. The code works bij intercepting the oReport.PrintingSystem.StartPrint event and adding a handler to send it to a routine which enumerates the trays of the printer. There are a few pitfalls to take note off: My HP drivers insisted on having spaces at the end of the tray names, so i needed to trim the Papersources.Name enumeration. Also, the printer trays […]

Getting and setting the clipboard content

These samples show handling the clipboard in the most basic way. First a test is done to see if there currently is text on the clipboard. If a text is found, the programm proceeds to read and display the text, and then replace it with a new text. By modifieing the parameters you can use the same technique to handle other formats such as images or audio and video fragments. VB.NET Implementation Imports System.Windows.forms Module […]

Demonstration of structures and enumerable types

Module Module1 ‘ MCTS70-536-1-2 ‘ VB.NET ‘ Demonstration of a structure and an override of the ToString method to display ‘ all parts of our person Public Structure Person ‘ — Example of an enumaration, see the actual Main() Method for use Enum Genders Male Female End Enum Private _firstname As String Private _lastname As String Private _age As Integer Private _gender As Genders Public Property Gender() As Genders Get Return _gender End Get Set(ByVal […]

Getting the current date/time from a NIST server

‘ — Get the current time/date from an internet nist server ‘ more timeserver here: http://tf.nist.gov/service/time-servers.html Dim s_checkserver As String = “time.nist.gov” Dim myreader As StreamReader Dim s_timestring As String Try myreader = New StreamReader(New Net.Sockets.TcpClient(s_checkserver, 13).GetStream) s_timestring = myreader.ReadToEnd s_timestring = Trim(LTrim(s_timestring)) Catch ex As Exception ‘ — unable to contact timeserver End End Try ‘ — Process the response from the server Dim n_work As Integer n_work = Val(Strings.Mid(s_timestring, 1, 6)) Dim years […]

Demonstration of Extending a class

Module Module1 ‘ MCTS70-536/1/1/3 ‘ Extending an existing class ”’ <summary> ”’ A simple base class ”’ </summary> ”’ <remarks></remarks> Public Class Customer Private _naam As String Private _adres As String Private _woonplaats As String Public Property Naam() As String Get Return _naam End Get Set(ByVal value As String) _naam = value End Set End Property Public Property Adres() As String Get Return _adres End Get Set(ByVal value As String) _adres = value End Set […]

Demonstration of structures and overriding operators

Module Module1 ‘ MCTS70-536-1-1 ‘ VB.NET ‘ Demonstration of a structure with ‘ an operator (+) ‘ an Override (toString) ‘ Public Structure DemoStruct Private _waarde As Integer ‘ — Read and write initial & current value Public Property Value() As Integer Get Return _waarde End Get Set(ByVal value As Integer) _waarde = value End Set End Property ‘ — Override de + OPERATOR, to SUBSTRACT the value in arg2 from the struct defined in […]

Demonstration of creating an event handler and attaching to an event

Public Class Form1 ‘ MCTS70-536-1-3 ‘ Registering and handling Events Private t As Timer Private p As ProgressBar Private Sub t_Tick(ByVal sender As Object, ByVal e As EventArgs) p.Value += 1 If p.Value = 100 Then p.Value = 1 End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ‘ — Create a progressbar and add it to the form p = New ProgressBar p.Location = New Point(20, 20) […]

Changing the runtime priority of your application

Module Module1 Sub Main() ‘ — Idle time only, the lowest priority. Use with care as your application could get very little cpu ‘ time allocated on a busy system System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle ‘ — Below normal priority System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal ‘ — Default priority, equal to other programms System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal ‘ — High priority, use for importan applications and processes that need to be responsive all the time. System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.AboveNormal ‘ — […]

Compressing and decompressing files with GZIPStream or Deflatestream

These samples whow how to compress and decompress files with the build in framework methods. For real world applications consider using something like .netzip from codeplex, since the compression quality from the build in methods is limited. Also, the build in methods will allow you to just compress and decompress a single file. Compressing a file Imports System.IO Imports System.IO.Compression Module packtool ”’ <summary> ”’ Example on using a deflatestream to compress a file into […]

Next Page »