Archive for February, 2009
Good Morning! Well it was a pretty quiet week. I had a lot of work related things to do so that is what I pretty much did. My daughter has been released to huber so that has got us all in an uproar as she needs many things. It will be interesting to see how this turns out. I pray for her daily despite everything that has happened.
Today’s topic is one that confounds many programmers. The PrintDocument object! Yes I can hear the snarling and gnashing of teeth going on out there. What we want to do is make the PrintDocument object follow our orders to make the document of legal size. If you have any experience with this you know this is not an easy task! Don’t forget if your printer does not support legal paper size (it happens) this will not work. Anyway, make it a great day!
Dim storedPageSettings As PageSettings = New PageSettings()
Dim PSize As PaperSize = Nothing
For Each PaperSizeContained As PaperSize In PrintDocument1.PrinterSettings.PaperSizes
If (PaperSizeContained.RawKind = Printing.PaperKind.Legal) Then
PSize = PaperSizeContained
If (PSize Is Nothing) Then
Throw New Exception("Oops! Can’t find Legal paper for this printer.")
storedPageSettings.PaperSize = PSize ‘<– this is the issue
storedPageSettings.Landscape = True
Dim dlg As New PrintPreviewDialog()
PrintDocument1.DefaultPageSettings = storedPageSettings
dlg.Document = PrintDocument1
Technorati Tags: vb.net,.NET Framework,csharp,Default,Paper,Size,Document,Legal,topic,PrintDocument,task,printer,PageSettings,
If you can make this statement I will tell you I agree with you – but not for the reasons you might think.
You as a Christian who has served God in front of others have gone and done something that you know is wrong. You’ve probably shamed yourself, perhaps your family, community and church, and feel that God must be ashamed of you as well. God feels distant, and perhaps you are not even bothering to reach out to him. Your depressed, anxious and afraid. You might be afraid others in your church might find out.
What is wrong with this picture? In short everything.
The first mistake was for you to assume your service to God was about you. It was not. It’s about him. Perhaps this might be at the root of your issues. When the focus is on yourself instead of the one you are serving, you are bound to fail.
The next mistake was that you have fallen prey to the disease of shame. Not all shame is bad mind you, but this kind of shame consists of self loathing, self pitying and self punishment. (Did you catch the common word of self in there?) This kind of shame generates depression, anxiety and fear and is spiritually deadly, and can be physically harmful. We would never attribute those characteristics to God would we? This is how we know we are not in the will of God as what we are doing we know God would not desire us to be here. This you can take all the credit for in the world because you have forgotten five things:
1. He is God. You are not. You are worrying about what you have done and what others in your church, family and community will think even though you have no chance of actually affecting any of it by obsessing on this. It is a vicious circle. The more you worry, the more miserable you become.
2. By doing this, you have taken God off the throne of your life and have put yourself there. Is God not to be trusted now, just because you have done something wrong? Did God change? The truth is your shame over what you have done is preventing you from turning it over to God and letting him handle these things. God loves you and is wanting this to happen for you.
3. You are not alone. We all have fallen at various times. I say this to make you feel better but to also as further evidence that your service to God has been about you and not him. Otherwise why would it matter?
4. God’s call on your life remains. When you are ready to let go of the bricks that are weighing you down because of what you have done and turn them over to God, your calling still awaits. God didn’t change just cause you did. God’s call on your life didn’t change.
5. Don’t deny the cross – By not accepting the forgiveness of Christ for what you have done, you deny his sacrifice for you. You were never worthy of that sacrifice to begin with nor will you start now.
Any Christian of course, when times like this confront them, must of course stand back and reevaluate where they are. It may call for a time to step back from ministry and think about what it is you have done, the reasons behind it, and correct it. In the end, when you return to ministry again, your testimony becomes more powerful as God has restored you when it all seemed hopeless.
The truth is, however, I can quote scripture about forgiveness until I am blue in the face, pray with you unceasingly, and you can talk to all the spiritual gurus you know. You can go to church, read the Bible, and pray out of habit but nothing will change until you are ready inside yourself to come to grips with what you have done, ask for forgiveness and move on from it. This is not something you can intellectually do. It’s something that has to occur within your soul, between you and God. And that is quite appropriate as that is where the beginning of ministry is.
God’s work awaits and you are part of that, and the the local church body you attend miss your contributions – and YOU!. So get right with God, get your heart and mind focused on who you should be focusing on, and get back to work!
Good afternoon everyone! I had an extremely quiet evening last night and this morning. We are really at crunch time at work right now but I think I am where I need to be with what I need to do.
Anyway, today’s topic is one that can throw a lot of for fits. We need to print barcode labels but some characters don’t translate as you would expect in print. So this class is a little old but it still works. Make it a great day!
Public Class Form1
Private WithEvents BarcodeDoc As barcode.TextPrint ‘BarcodingParts.TextPrint
#Region " Windows Form Designer generated code "
Public Sub New()
‘This call is required by the Windows Form Designer.
‘Add any initialization after the InitializeComponent() call
‘Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
‘Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
‘NOTE: The following procedure is required by the Windows Form Designer
‘It can be modified using the Windows Form Designer.
‘Do not modify it using the code editor.
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
Me.Button1 = New System.Windows.Forms.Button
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
Me.Button1.Location = New System.Drawing.Point(196, 224)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Enabled = True
Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(132, 132)
Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
Me.PrintPreviewDialog1.Visible = False
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
‘ BarcodeDoc = New BarcodingParts.TextPrint("*00417955*", "Here is Second line from Extended Barcode")
‘ BarcodeDoc.Font = New Font("FREE 3 OF 9 Extended", 30) ‘<—- Free Font on the internet or add your own
‘ OR USE THIS
BarcodeDoc = New TextPrint("*00417 955*", "Here is Second line from Regular Barcode")
BarcodeDoc.Font = New Font("FREE 3 OF 9", 30) ‘<—- Free Font on the internet or add your own
‘For Pre-veiw Printing
PrintPreviewDialog1.Document = BarcodeDoc
‘For Direct Printing
Dim PrintDialog1 As New PrintDialog
‘PrintDialog1.Document = BarcodeDoc
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
BarcodeDoc.PrinterSettings.PrinterName = InitializeDefaultPrinter() ‘"Zebra"
BarcodeDoc.DefaultPageSettings.Margins.Left = 10
BarcodeDoc.DefaultPageSettings.Margins.Right = 10
BarcodeDoc.DefaultPageSettings.Margins.Top = 40
#Region " Initialize Default Printer "
Public Function InitializeDefaultPrinter()
‘ Set the specified printer to the default printer for this program. Return
‘ true if the printer was found.
Dim objprinter As PageSettings = New PageSettings
Dim strname = objprinter.PrinterSettings.PrinterName
InitializeDefaultPrinter = strname
Public Class TextPrint
‘ Inherits all the functionality of a PrintDocument
‘ Private variables to hold default font and text
Private fntPrintFont As Font
Private strText As String
Private strText2 As String
Private PrintBarCodeText As String
Public Sub New(ByVal Text As String, ByVal Text2 As String)
‘ Sets the file stream
strText = Text
strText2 = Text2
Public Property Text() As String
Set(ByVal Value As String)
strText = Value
Public Property Text2() As String
Set(ByVal Value As String)
strText2 = Trim(Value)
Public Property CodeText() As String
PrintBarCodeText = Trim(Replace(strText, "*", " "))
Set(ByVal Value As String)
If PrintBarCodeText = "" Then
PrintBarCodeText = Trim(Replace(Value, "*", " "))
PrintBarCodeText = Value
Protected Overrides Sub OnBeginPrint(ByVal ev As Printing.PrintEventArgs)
‘ Run base code
‘ Sets the default font
If fntPrintFont Is Nothing Then
fntPrintFont = New Font("Times New Roman", 12)
Public Property Font() As Font
‘ Allows the user to override the default font
Set(ByVal Value As Font)
fntPrintFont = Value
Protected Overrides Sub OnPrintPage(ByVal ev As Printing.PrintPageEventArgs)
‘ Provides the print logic for our document
‘ Run base code
Static intCurrentChar As Integer
Dim intPrintAreaHeight, intPrintAreaWidth, intMarginLeft, intMarginTop As Integer
‘ Set printing area boundaries and margin coordinates
intPrintAreaHeight = .PaperSize.Height – .Margins.Top – .Margins.Bottom
intPrintAreaWidth = .PaperSize.Width – .Margins.Left – .Margins.Right
intMarginLeft = .Margins.Left ‘X
intMarginTop = .Margins.Top ‘Y
‘ If Landscape set, swap printing height/width
If MyBase.DefaultPageSettings.Landscape Then
Dim intTemp As Integer
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
‘ Calculate total number of lines
Dim intLineCount As Int32 = CInt(intPrintAreaHeight / Font.Height)
‘ Initialise rectangle printing area
Dim rectPrintingArea As New RectangleF(intMarginLeft, intMarginTop, intPrintAreaWidth, intPrintAreaHeight)
‘ Initialise StringFormat class, for text layout
Dim objSF As New StringFormat(StringFormatFlags.LineLimit)
‘ Figure out how many lines will fit into rectangle
Dim intLinesFilled, intCharsFitted As Int32
Dim stringSize As New SizeF
stringSize = ev.Graphics.MeasureString(Mid(strText, _
UpgradeZeros(intCurrentChar)), Font, New SizeF(intPrintAreaWidth, _
intPrintAreaHeight), objSF, intCharsFitted, intLinesFilled)
‘ Print the text to the page
UpgradeZeros(intCurrentChar)), Font, Brushes.Black, rectPrintingArea, objSF)
‘ Initialise rectangle printing area for the Barcode Text
Dim stringFont As New Font("Arial", 12, FontStyle.Bold)
Dim size As SizeF = ev.Graphics.MeasureString(CodeText, stringFont)
Dim size2 As SizeF = ev.Graphics.MeasureString(strText2, stringFont)
Dim BCPrintingArea As New RectangleF(stringSize.Width – size.Width / 2, intMarginTop + stringSize.Height, intPrintAreaWidth, intPrintAreaHeight)
‘Move Second line to center
Dim moveStr As Integer
moveStr = stringSize.Width – size2.Width / 2
moveStr = intMarginLeft + (moveStr / intMarginLeft)
Dim BCPrintingArea2 As New RectangleF(moveStr, intMarginTop + stringSize.Height + size2.Height, intPrintAreaWidth, intPrintAreaHeight)
‘ADD text Bottom of Barcode
ev.Graphics.DrawString(CodeText, stringFont, Brushes.Black, BCPrintingArea)
ev.Graphics.DrawString(strText2, stringFont, Brushes.Black, BCPrintingArea2)
‘ Increase current char count
intCurrentChar += intCharsFitted
‘ Check whether we need to print more
If intCurrentChar < strText.Length Then
ev.HasMorePages = True
ev.HasMorePages = False
intCurrentChar = 0
Public Function UpgradeZeros(ByVal Input As Integer) As Integer
‘ Upgrades all zeros to ones
‘ – used as opposed to defunct IIF or messy If statements
If Input = 0 Then
Technorati Tags: vb.net,.NET Framework,csharp,Drawing,labels,Print,Barcode,characters,System,Graphics,Public,Class,Form,Private,WithEvents,BarcodeDoc,TextPrint,
Good Morning all! Yesterday was an intense day of coding as we are in the middle of rollout of our plans at work. These plans have what are called Elements, and those elements have element details, allocators, allocator details, allocator detail rules, rates, rate tables, rate table details, and rate table detail items. i got tired of manually creating these when others were so close so I came up with code to duplicate the element and what was below to another plan. So I was happy.
Today’s topic is how to get your application to wait for an external process that you called with System.Diagnostics.Process to finish. Make it a great day!
Dim TgtDirectory As String = "MyDir\"
Dim XYZFilter As String = "*.xyz"
Dim FileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim Process As New System.Diagnostics.Process
FileList = My.Computer.FileSystem.GetFiles(TgtDirectory, _
For Each foundfile As String In FileList
Using P As Process = Process.Start("dlg2dlx.bat", foundfile)
Technorati Tags: vb.net,.NET Framework,csharp,Process,Wait,External,Complete,System,Diagnostics,FileList,ObjectModel,ReadOnlyCollection,
Good Morning! Well my time publish didn’t work like I wanted it to. But that’s okay I am sure I did something wrong.
My night was not great. But lets leave it at that.
Anyway, yesterday’s post we created a chart in Excel and now we want to put that chart into a Microsoft Word Document. Not complicated stuff now but it drove me nuts for a while.
Make it a great day!
‘Dim Word As Word.Application
‘Dim WSheet As New Excel.Worksheet
‘ WSheet = Excel.Workbooks.Add.Worksheets.Add
Label3.Text = "Creating Word Table…."
Word.Application.ActiveWindow.ActivePane.Document.Tables.Add(Range:=Word.Application.ActiveWindow.ActivePane.Document.Content.Application.Selection.Range, NumRows:=3, NumColumns:= _
1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
Label3.Text = "Adding RX Chart to Word Document……"
Appearance:=1, Size:=1, Format:=-4147)
Word.Application.ActiveWindow.Selection.PasteSpecial(Link:=False, DataType:=3, _
Technorati Tags: vb.net,csharp,.NET Framework,Place,Excel,Chart,Microsoft,Word,Document,Application,Worksheet,Workbooks,Worksheets,Text,Table,ActivePane,
Good Morning! This post is being written early because I knew I would be busy the next couple of days. I am hoping this is published at the time I ask that it be done! If not, I guess you got two posts early!
Today and tomorrow’s topic are interrelated. Basically first we want to create a databound Excel Chart using a specified Excel worksheet as its data source using vb.net. Tomorrow we will address adding that Excel Chart to a Microsoft Word document with vb.net.
This assumes you already have a worksheet populated with data. If you are unsure of how to do this with vb.net see here.
Make it a great day!
‘ASSUMED Dim WSheet As New Excel.Worksheet
‘ASSUMED WSheet = Excel.Workbooks.Add.Worksheets.Add
Label3.Text = "Adding RX Chart….."
‘ WSheet.Application.ActiveChart.Name = "TxChart"
‘WSheet.Application.ActiveChart.ApplyCustomType(ChartType:=21, TypeName:="Column – Area")
WSheet.Application.ActiveChart.SetSourceData(Source:=Excel.Application.Sheets(thisname).Range("B1:L14"), PlotBy _
WSheet.Application.ActiveChart.SeriesCollection(1).XValues = "=" & thisname & "!R2C1:R14C1"
.HasTitle = True
.ChartTitle.Characters.Text = "Network Use – RX for " & CustomerName & vbCrLf & CombinedDate
.Axes(1, 1).HasTitle = True
.Axes(1, 1).AxisTitle.Characters.Text = "Hours"
.Axes(2, 1).HasTitle = True
.Axes(2, 1).AxisTitle.Characters.Text = "WAN%"
.Name = "rxChart"
.ChartType = 76
.Legend.Font.Size = 12
.ChartSize = 2
.CenterHorizontally = False
.CenterVertically = False
.Orientation = 2
.Draft = False
.BlackAndWhite = False
.Zoom = 70
WSheet.Application.Selection.Height = 400
WSheet.Application.ActiveChart.HasDataTable = False
Label3.Text = "Page Setup For RX Worksheet…."
.RightHeader = "Page &P Of &N"
.RightHeader = "Page &P Of &N"
.CenterHeader = ""
‘.LeftHeader = ‘arrgen.ItemNumberGlobal & " " & ReportType & vbCrLf & ReportComments
.LeftHeader = CustomerName & " Network Usage (Rx) on " & CombinedDate & " for " & CustomerName ‘arrgen.ItemNumberGlobal & " " & ReportType & vbCrLf & ReportComments
.LeftFooter = "Property of Kelly Martens"
.RightFooter = "&D / &T"
.LeftMargin = WSheet.Application.InchesToPoints(0.54)
.RightMargin = WSheet.Application.InchesToPoints(0.3)
.TopMargin = WSheet.Application.InchesToPoints(1.0)
.BottomMargin = WSheet.Application.InchesToPoints(1.0)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = -4142 ‘XlPrintLocation.xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = False
.Orientation = 2 ‘XlPageOrientation.xlLandscapeXlPageOrientation.xlLandscape
.PrintTitleRows = "$1:$1"
.Draft = False
.Order = 1 ‘XlOrder.xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 100
.FitToPagesTall = 100
.Zoom = 80
Technorati Tags: vb.net,csharp,.NET Framework,Create,Data,Bound,Excel,Chart,worksheet,Microsoft,Word,Workbooks,
Good Morning! Well yesterday I told you I was considering doing a new project. It seems there is someone else who has done something similar and does even more than what I was thinking of doing. I decided that it is ok. Really I am writing it for myself as exercise for my coding skills so I am going to do it anyway. But I probably will get it anyway (am awaiting the download link from a friend) just cause it sounds really cool.
Anyway, today’s topic is to check to see if a SQL database already exists on a server. My thinking is when the user added a database we only want to let them add that database once. So here it is. Make it a great day!
Public Shared Function CheckDatabaseExists(ByVal server As String, ByVal database As String) As Boolean
Dim connString As String = ("Data Source=" _
+ (server + ";Initial Catalog=master;Integrated Security=True;"))
Dim cmdText As String = ("select * from master.dbo.sysdatabases where name=\’" _
+ (database + "\’"))
Dim bRet As Boolean = false
Using sqlConnection As SqlConnection = New SqlConnection(connString)
Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
Using reader As SqlDataReader = sqlCmd.ExecuteReader
bRet = reader.HasRows