Advertisement
7_2009-2012 Miscellaneous #217295

Send a preformated file to any printer

Q. How can I send a preformated file to a printer "as is". If I use Printer.Print then things like ESC get converted to a box or whatever chr$(27) is in the current font. A.I'm using following code to send AutoCAD .plt-files to my printer, and it works ok for me. "Soren Staun Jorgensen"

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Sub SendFileToPrinter()
  Dim FileName As String
  Dim s As Long
  Dim i As Integer
  
  For i = 0 To frmMain.List.ListCount - 1
    If frmMain.List.Selected(i) Then
      FileName = CurFolder & "\" & frmFileList.File.List(i)
      s = SendToPort(FileName, CurPrnPort, vbNull)
      frmMain.List.Selected(i) = False
    End If
  Next i
  
End Sub
Public Function SendToPort(sFileName$, sPortName$, lPltFailed&)
Dim s As Long
  s = CopyFile(sFileName, sPortName, lPltFailed)
End Function
<table width="97%" border="0" cellpadding="2" cellspacing="3" bgcolor="#FFFFFF">
 <tr> 
 <td bgcolor="#CCCCCC"> <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Opacity 
  - Now you see it.., now you don't..</strong></font></p></td>
 </tr>
 <tr> 
 <td valign="top"> <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">VB.Net 
  has exposed some new properties for us to play with. One of them is "opacity". 
  Opacity is that wonderful abilty to set the transparency of an object. 
  The first time I saw form opacity or form transpanency was on a box running 
  Linux. It had a couple of windows open and you could see through them 
  to the form underneath and to the wall paper. I thought this was very 
  cool. We've all seen applications that have semi-transparent forms that 
  you can see through and there are quite a few good examples of form opacity 
  or transparency on PSC that you might want to take a look at.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">In this article 
  we will create a form that, when closed, will adjust it's opacity over 
  time and fade away. It's a neat effect that has gotten some milage in 
  the past and will undoubtedly get more in the future. Especially now that 
  it's so easy to do.<br>
  We will also look at the <font color="#000000">Closing Event </font> and 
  a neat new coding feature that will allow us to streamline our code.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">So, let's 
  get started.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
  </font></p></td>
 </tr>
 <tr> 
 <td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Building 
  the interface</strong></font></td>
 </tr>
 <tr> 
 <td><p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Let's begin 
  by placing a label on our form. This really serves no purpose other than 
  to show an additional control on the form with some text that will change 
  as we press the button we will create. <br>
  On the toolbar locate the label control and drag and draw the label where 
  you want it on the form. We'll go to the property inspector and change 
  the name property of the label to "lblPrompt".<br>
  At this point you will notice that the new name that we entered for the 
  label is in bold text. This is because it is no longer the default property 
  value. If you change any of the property values they will become bold. 
  This makes it easy to glance at the property inspector and see what you 
  have changed.<br>
  In the text property let's add some text. The text we'll add is "Just 
  click the button below and watch me go!". We will change this later 
  in the button Event Handler.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Now let's 
  add a button to the form. <br>
  Find the button control in the toolbox and drag and draw it on the form 
  where you want it. In the property inspector set the name property to 
  "btnExit" and the text property to "E&xit". This 
  will work the same as it has before in VB and put an underscore under 
  the "x" and allow the keystroke alt+x to activate the button.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">The last 
  thing we'll add is a timer. <br>
  Again go to the toolbox and locate the timer. When you click on the timer 
  and drag it on the form you will notice that it doesn't appear on the 
  form as it used to in earlier versions of VB, but instead it will appear 
  below the form in another window. That's because the timer is not a control 
  as in the past but is now called a "component", and the window 
  it appears in is the "component tray". If we click on the timer 
  componet you'll see that the properties display in the property inspector. 
  We are interested in two properites. The "interval" and the 
  "enabled" properties.<br>
  The interval property defaults to 100, or 100 miliseconds, or 1/10th of 
  a second.<br>
  The enabled property defaults to False, meaning that the timer is not 
  enabled or counting until we set this property to True.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
  </font></p></td>
 </tr>
 <tr> 
 <td bgcolor="#3399FF"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000000"><em><font color="#FFFFFF"> 
  Something New!</font></em></font></strong></font></td>
 </tr>
 <tr bgcolor="#FFDFBF"> 
 <td valign="top" bgcolor="#FFDFBF"> <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>If 
  you look under the text property you will see a property called "TextAlign". 
  By clicking on the value box you get a graphical representation that will 
  allow you to align the text to 9 different places on the button. The default 
  is Middle Center, and for right now we'll leave it at the default value.</strong></font></p></td>
 </tr>
 <tr> 
 <td> </td>
 </tr>
 <tr> 
 <td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Now 
  let's look at some code</strong></font></td>
 </tr>
 <tr> 
 <td valign="top"> <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Double 
  click on the Exit button.<br>
  Like before it will take you to the Sub proceedure for the Click Event. 
  However, you'll notice something a little different.</font></p>
  <p> <font color="#0000FF" size="2">Private Sub</font><font size="2"> btnExit_Click(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> System.Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.EventArgs) <font color="#0000FF">Handles</font> 
  btnExit.Click<br>
  <br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">VB.Net 
  has automatically created a Private Sub Proceedure for us and placed two 
  parameters into the proceedure that we weren't used to seeing before. 
  One is "sender" and the other is "e".<br>
  The name of the Sub, </font><font color="#000000" size="3"><strong>btnExit_Click</strong></font><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">, 
  is automatically assigned by VB.Net from the property we set earlier in 
  the properties inspector when we renamed the button. However, unlike previous 
  versions of VB we don't have to leave this name as it was assigned by 
  the IDE. You can name it anything because the Sub name isn't what defines 
  the event. The </font><font color="#0000FF" size="3"><strong>Handles</strong></font><strong><font color="#000000" size="3"> 
  btnExit.Click</font></strong><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
  argument is what defines the event. This tells VB.Net specifically what 
  event the code is going to handle.<br>
  The first parameter, </font><font color="#0000FF" size="3"><strong>ByVal</strong></font><strong><font color="#000000" size="3"> 
  sender <font color="#0000FF">As</font> System.Object, </font></strong><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">tells 
  us who fired this event or who the sender of this event was as a System.Object. 
  System.Object is similar to a variant in VB6 in that it can contain anything. 
  It refers back to an Object in the System class. In this case the sender 
  object was our button, btnExit.<br>
  The second parameter, </font><font color="#0000FF" size="3"><strong>ByVal</strong></font><strong><font color="#000000" size="3"> 
  e <font color="#0000FF">As</font> System.EventArgs</font></strong><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">, 
  passes information that might need to be processed for this particular 
  event. We aren't passing any additional information for this event so 
  we'll just ignor it for now, but keep in mind what it does and why it's 
  there. </font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">The 
  code we'll add to this proceedure is;<br>
  </font><font color="#000000" size="3"><strong><font color="#0000FF">Me</font>.Close() 
  <br>
  </strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">You 
  won't need to add the parenthisis after "Close". VB.Net will 
  do that for you. Like in VB6 this will call the the method, Close(), for 
  the form object, Me. </font></font></p>
  <p><font color="#0000FF" size="2">Private Sub</font><font size="2"> btnExit_Click(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> System.Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.EventArgs) <font color="#0000FF">Handles</font> 
  btnExit.Click<br>
       <font color="#0000FF"> Me</font>.Close()<br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font color="#000000" size="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">If 
  we were to run the application now what would happen is when we clicked 
  on the button on our form the form would close and the application would 
  end. But we want the form to fade away as it closes. To do this we'll 
  need to add some code in the timer event handler. The code we will add 
  will set the new form level property "Opacity". The values we 
  will use are 1 and 0. (1 for visable and 0 for transparent)</font></font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Timer 
  Event Handler<br>
  </strong>In the component tray double click on the timer component. This 
  will take you to the code for the timer event handler. </font></p>
  <p><font color="#0000FF" size="2">Private Sub</font><font size="2"> Timer1_Tick(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> System.Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.EventArgs) <font color="#0000FF">Handles</font> 
  Timer1.Tick<br>
    <br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">The 
  timer event handler looks pretty much like the button event handler we 
  just reviewed in that it also has the same two parameters, "sender" 
  and "e", but this event handles the </font><font color="#000000" size="3"><strong>Timer1.Tick</strong></font><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
  event. This tick event is the interval that we saw in the properties inspector 
  that was set to 100. When this timer is enabled the tick event will fire 
  off every 1/10th of a second (10 times a second).</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">What we want 
  to do is set the opacity property to decrease in opacity everytime the 
  tick event fires off until the form is totally transparent and then exit 
  the program. To do this we'll need to set a value that we will decrease, 
  or decrement, the opacity property value with. In the past we have done 
  this with a statement that looked something like this;</font></p>
  <p><font size="3"><strong><font color="#0000FF">Me</font>.Opacity = <font color="#0000FF">Me</font>.Opacity 
  - 0.1</strong></font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">This would 
  take the value of Opacity and decrease it by 0.1. So if the timer interval 
  is 100 then the opacity value would decrement from 1 to 0, or from visable 
  to totally transparent in 1 second. If we set the decrement value to 0.05 
  then it would decrement from 1 to 0 in 2 seconds.</font></p>
  <p> </p></td>
 </tr>
 <tr> 
 <td bgcolor="#3399FF"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><em> <font color="#FFFFFF">Something 
  New! </font></em></strong></font></td>
 </tr>
 <tr> 
 <td valign="top" bgcolor="#FFDFBF"> <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>However, 
  VB.Net has some new features that allow us to write less code to do the 
  same thing. Instead of using the code above we can simply write;<br>
  </strong></font><strong><font size="3"><font color="#0000FF">Me</font>.Opacity 
  <font face="Verdana, Arial, Helvetica, sans-serif">-=</font> 0.1<br>
  </font></strong><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">This 
  will decrement the property value exactly the same way as above. Pretty 
  nifty huh!?!</font></strong></p></td>
 </tr>
 <tr> 
 <td> </td>
 </tr>
 <tr> 
 <td valign="top">
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Now that 
  we have a decrement value we need to make sure that we don't try to go 
  beyond the lower value of 0. This we can do with a simple "if" 
  statement.</font></p>
  <p><font size="3"><strong><font color="#0000FF">If</font> <font color="#0000FF">Me</font>.Opacity 
  = 0 <font color="#0000FF">Then</font><br>
       <font color="#0000FF">Me</font>.Close()<br>
  <font color="#0000FF">End If</font></strong></font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">This 
  just says that if the value of the property opacity is equal to 0 then 
  close the form. So our timer event handler code should now look like this;</font></p>
  <p><font color="#0000FF" size="2">Private Sub</font><font size="2"> Timer1_Tick(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> System.Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.EventArgs) <font color="#0000FF">Handles</font> 
  Timer1.Tick</font><font size="2"><br>
     <font color="#0000FF"> Me</font>.Opacity -= 0.1<font color="#009900" face="Verdana, Arial, Helvetica, sans-serif"> 
  'Look at this, we are decrementing the opacity property</font></font></p>
  <p>    <font color="#009900" size="2" face="Verdana, Arial, Helvetica, sans-serif">'Now 
  let's check to see if the opacity has gone from 1 to 0 yet.</font><font size="2"><br>
       <font color="#0000FF">If Me</font>.Opacity 
  = 0 <font color="#0000FF">Then</font><font color="#009900">  <font face="Verdana, Arial, Helvetica, sans-serif"> 'If 
  it is then</font></font><br>
             <font color="#0000FF">Me</font>.Close()<br>
      <font color="#0000FF"> End If </font><br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Now we have 
  written the code for the button and the code for the timer. But we haven't 
  enabled our timer so that it can start firing off the Timer1.Tick event 
  handler. We could go back and place it in our button event handler, but 
  what happens if someone closes the application by clicking on the x on 
  the top of the form? Or what if they pressed the keys alt+F4? The program 
  will close, but it won't fade away like we want it to. To get it to fade 
  away no matter what the user does to close the program we will have to 
  place some code in the event that fires when the program closes.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>The 
  Closing Event Handler<br>
  </strong>In VB6 when you wanted to access form level events you would 
  go to the left drop down and select "Form1", or what ever the 
  name of your form was, and then go to the right drop down and select one 
  of the form level events.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">But what 
  happens when we try to find the form in the left drop down? It isn't there. 
  This is because everything in VB.Net is based on classes. We will have 
  to select the item, "(Base Class Events)". This refers to the 
  top most declaration in our code window.</font></p>
  <p><font color="#0000FF" size="2">Public Class</font><font size="2"> Form1<br>
  <font color="#0000FF">Inherits</font> System.Windows.Forms.Form</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">This is the 
  grand daddy of all the classes for the form. The </font><font size="3"><strong>System.Windows.Forms.Form</strong></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif">. 
  All of our form level events are going to inherit from the definitions 
  in System.Windows.Forms.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Now that 
  we have established where to find our form level, lets look at the method 
  we want to call. When all forms are closing they fire the "Closing" 
  event. Makes sense doesn't it. So on the right drop down select the Closing 
  event. This will cause VB.Net to create the Sub for us.</font></p>
  <p><font color="#0000FF" size="2">Private Sub</font><font size="2"> Form1_Closing(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.ComponentModel.CancelEventArgs) 
  <font color="#0000FF">Handles</font> MyBase.Closing<br>
  </font><font size="2"><br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">This proceedure 
  looks like the others for the most part, except that the second parameter 
  now has;<br>
  </font><font size="2"><font color="#0000FF"><strong><font size="3">ByVal</font></strong></font><font size="3"><strong> 
  e <font color="#0000FF">As</font> System.ComponentModel.CancelEventArgs</strong></font></font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">CancelEventArgs.., 
  this parameter allows us to cancel the closing of the form. So if we type 
  "e" followed by a "." we will get the intellesense 
  drop down with a "cancel" event that we can select and assign 
  a boolean value to. <br>
  Lets add the code;</font></p>
  <p><font color="#0000FF" size="2">Private Sub</font><font size="2"> Form1_Closing(<font color="#0000FF">ByVal</font> 
  sender <font color="#0000FF">As</font> Object, <font color="#0000FF">ByVal</font> 
  e <font color="#0000FF">As</font> System.ComponentModel.CancelEventArgs) 
  <font color="#0000FF">Handles</font> MyBase.Closing</font><font size="2"><br>
  <br>
            e.Cancel = 
  <font color="#0000FF">True</font>   <font color="#009900" face="Verdana, Arial, Helvetica, sans-serif">'Set 
  the cancel method on the closing event to True</font><br>
            <font color="#0000FF">Me</font>.lblPrompt.Text 
  = "I'm fading away!!!!"  <font color="#009900" face="Verdana, Arial, Helvetica, sans-serif"> 
  'Add some fun text</font><br>
            <font color="#0000FF">Me</font>.Timer1.Enabled 
  = <font color="#0000FF">True</font>  <font color="#009900" face="Verdana, Arial, Helvetica, sans-serif"> 
  'Enable the timer</font><br>
  <br>
  <font color="#0000FF">End Sub</font></font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">The first 
  line </font><font size="3"><strong>e.Cancel = <font color="#0000FF">True</font></strong></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
  will cancel the closing of the form.<br>
  The second line </font><font size="3"><strong><font color="#0000FF">Me</font>.lblPrompt.Text 
  = "I'm fading away!!!!"</strong></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
  will change the text in our label.<br>
  The third line </font><font size="3"><strong><font color="#0000FF">Me</font>.Timer1.Enabled 
  = <font color="#0000FF">True</font></strong></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
  will start the timer.</font></p>
  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Now when 
  we run the program and press the button the form fades away over a second 
  and the program exits.</font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Wasn't 
  that easy? We actually only had to write seven short lines of code in 
  order to achieve this effect. Explore the possibilities.</font></p>
  <p><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Happy 
  coding.... </font></p>
  </td>
 </tr>
</table>
<?php
  $countfile = "data/counter.txt";
  $logfile = "data/WebLog.txt";
  
  if (!file_exists("$countfile")) {
    $fp = fopen("$countfile", "a");
    fputs($fp, "0");
    fclose($fp);
  }
  	
  $count = join('', file($countfile));
  trim($count);
  $count++;
  echo $count;
  
  $fp = fopen($countfile, "w");
  fputs($fp, $count);
  fclose($fp);
  
  $fp = fopen($logfile, "a");
  $date = date("d M, Y");
  $time = date("g:i a");
  fputs($fp, "IP: ".$_SERVER['REMOTE_ADDR']." Date: ".$date." Time: ".$time);
  fputs($fp, "\n");
  fclose($fp);
  
?>
Original Comments (3)
Recovered from Wayback Machine