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> […]
Category: VB.NET
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]