Avatar billede c.aa.t Nybegynder
28. august 2001 - 15:04 Der er 10 kommentarer

Hvordan får man en printer til at skifte linje selv? \"Autolinefeed\"

Jeg har lavet et program der printer ud fra en Access database! Og nogle af felterne indeholder mere end der kan stå og så fortsætter linjen bare ud fra papiret! Jeg har ladet mig fortælle at man kan sætte en printer til \"Autolinefeed\" men jeg kan ikke finde ud af hvordan! Printeren er en HP 4100 og en HP 1100 laserjet! Er der nogen der ved hvordan man gør?? Eller om det kan gøres i koden?? Og hvis man kan i koden, så hvordan?
Avatar billede terry Ekspert
28. august 2001 - 16:00 #1
When you say that your printing \"ud fra en Access database\" do you mean that the data is commíng from an Access dB or that you are printing a report via Access?

If your taking the data from Access and printing it via a VB program then you can send a VBCrLf to the printer when ever you want.

But I would also have thought that your printer did it Automatically.
Avatar billede c.aa.t Nybegynder
29. august 2001 - 08:02 #2
My data is comming from at access db and i am printing it from my VB program! What\'s that \"VBCrLf\" you are talking about??
Avatar billede axor Nybegynder
29. august 2001 - 09:48 #3
Du kan evt. indprogramerer denne routine.

Dim NewLine, DinString as String

Nl = Chr(10) + Chr(13)

Hvergang du nu sætter Nl efter en linje vil den automatisk skifte til næste linje.
Avatar billede c.aa.t Nybegynder
29. august 2001 - 10:35 #4
Min Printer kode er nok lidt sløv men den virker!
Kan du ikke hjælpe mig med at sætte dem de rigtige steder??

Private Sub cmdprint_Click()
svar = MsgBox(\"Udskriv side?\", 4, \"slet post\")
If svar = 6 Then
Printer.Print \"  \"
Printer.Print \"OTS SKP NOTA\"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"Opgavenr:\"; \"        \"; txbopgnr.Text
Printer.Print \"Dato Start:\"; \"      \"; txbdatostart.Text
Printer.Print \"Prioitet:\"; \"        \"; txtprio.Text
Printer.Print \"Deadline:\"; \"        \"; txtdeadl.Text
Printer.Print \"  \"
Printer.Print \"              _______________________________________________________________\"
Printer.Print \"  \"
Printer.Print \"Type:\"; \"            \"; txttype.Text
Printer.Print \"Modtaget Af:\"; \"    \"; txtmodt.Text
Printer.Print \"Ansvarlig:\"; \"      \"; txtansv.Text
Printer.Print \"Afdeling:\"; \"        \"; txtafdel.Text
Printer.Print \"Lokalitet:\"; \"      \"; txtloka.Text
Printer.Print \"  \"
Printer.Print \"              _______________________________________________________________\"
Printer.Print \"  \"
Printer.Print \"Fejlraport:\"; \"      \"; txtbopgmodt.Text
Printer.Print \"              _______________________________________________________________\"
Printer.Print \"  \"
Printer.Print \"Opgave Færdig:\"; \"  \"; txtopgaflev.Text
Printer.Print \"              _______________________________________________________________\"
Printer.Print \"  \"
Printer.Print \"Kontakt:\"; \"        \"; txbkont.Text
Printer.Print \"Ring:\"; \"          \"; chkring.Value
Printer.Print \"Tlf:\"; \"            \"; txbtlf.Text
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"                \"; \"Underskrift\"
Printer.Print \"  \"
Printer.Print \"  \"
Printer.Print \"              \"; \"------------------ \"
Printer.EndDoc
End If

End Sub
Avatar billede terry Ekspert
29. august 2001 - 11:12 #5
c.aa.t> If I understand your question correctly you have problems with the contents of some lines containing too many characters for the line. For example, the lines such as

Printer.Print \"              _______________________________________________________________\"
get prined OK and they also get followed by a new line. But lines such as
Printer.Print \"Tlf:\"; \"            \"; txbtlf.Text may get printed incorrectly.

I suggest that you place the contents of a line into a string. Then make a function which scans the line inserting a VBCrLf (This is the same as Chr(10) + Chr(13)) after each 80 characters.



Avatar billede c.aa.t Nybegynder
29. august 2001 - 11:32 #6
Can you give an example?? I am very very new at this... i have only worked with VB about 5 days
so i don\'t know that much
Avatar billede terry Ekspert
29. august 2001 - 12:16 #7
This is just a VERY simple way to do it but it works and it may give you some idea\'s.

You make a function like this:

Function LineFormat(sLine As String) As String
Dim i As Integer
Dim j As Integer

    j = 0
    LineFormat = \"\"
    For i = 1 To Len(sLine)
        j = j + 1
        If j = 80 Then
            LineFormat = LineFormat & vbCrLf
            j = 1
        End If
        LineFormat = LineFormat & Mid(sLine, i, 1)
   
    Next i
   
End Function

Then you replace the lines such as:
Printer.Print \"Kontakt:\"; \"        \"; txbkont.Text

With:
Printer.Print LineFormat(\"Kontakt:\" &  \"        \" & txbkont.Text)

Notice I have replaced the ; with &

This just converts the whole which you printed before to a single string to sedn to the function. The function then formtas the line.


Avatar billede c.aa.t Nybegynder
29. august 2001 - 12:24 #8
Should i replace my entire code??
Avatar billede terry Ekspert
29. august 2001 - 12:29 #9
No. I would suggest that you only replace the lines where you are having problems. I would think its thoughs where you are printing the contents of a text field such as

Printer.Print \"Kontakt:\"; \"        \"; txbkont.Text

You would just replace the line with
Printer.Print LineFormat(\"Kontakt:\" &  \"        \" & txbkont.Text)


Avatar billede c.aa.t Nybegynder
29. august 2001 - 12:45 #10
I keep getting errors!
Private Sub cmdprint_Click() is highlighted
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester