THE BORE

General => The Superdeep Borehole => Topic started by: Ecrofirt on December 06, 2008, 05:01:42 PM

Title: Well now, here's a weird one - VB programming (ugh, I know)
Post by: Ecrofirt on December 06, 2008, 05:01:42 PM
I'm re-writing a co-worker's VB script. The script runs at login, and pulls in some information about the user account and pulls in some information about the user's account account and whatnot. It then emails this info to an address on our network.

I've got a bit of code that pulls in printer information. The data is supposed to look like this:
Printer Information
-------------------
Current Default Printer: \\ps01\mc-3rdcc-01-ps
All Connected Printers:
Adobe PDF
Send To OneNote 2007
PrimoPDF
Microsoft XPS Document Writer
Microsoft Office Document Image Writer
mc-3rd-cc-02-ps_local
\\ps01\adm-1st-03-ps
\\ps01\mc-3rdcc-01-ps
\\ps01\Xerox


and in fact, it DOES look like that if I display it on the screen via a messagebox.

HOWEVER, it looks like this when it comes in via email:
Printer Information
-------------------
Current Default Printer: \\ps01\mc-3rdcc-01-ps All Connected Printers:
Adobe PDF Send To OneNote 2007 PrimoPDF Microsoft XPS Document Writer Microsoft Office Document Image Writer mc-3rd-cc-02-ps_local \\ps01\adm-1st-03-ps
\\ps01\mc-3rdcc-01-ps
\\ps01\Xerox


Somehow, it's losing the line breaks.

Here's the code behind it:
Code: [Select]
Function GetPrinterInformation()
Dim retString
Dim strDefault
Dim intCount
Dim colPrinters

retString = "Printer Information" & vbNewLine &_
"-------------------" & vbNewLine


On Error Resume Next
strDefault = objShell.RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
If Err Then
strDefault = "Error reading default printer from the registry"
Err.Clear
End If
On Error Goto 0

retString = retString & "Current Default Printer: " & strDefault & vbNewLine

retString = retString & "All Connected Printers: " & vbNewLine

Set colPrinters = objNetwork.EnumPrinterConnections

For count = 1 to colPrinters.Count -1 Step 2
retString = retString & colPrinters(count) & vbNewLine
Next

retString = retString & vbNewLine & vbNewLine

Set colPrinters = Nothing

GetPrinterInformation = retString
End Function

As you can see, I've got all the vbNewLine stuff in there, and like I said it outputs correctly if I send the output to a messagebox. It just fucks up when I email it out.

Weirder still, I've found that if I change to a different SMTP server, the output looks a little bit better. The printer stuff comes out like it should, but I've got a network adapter area (that also looks fine in the messagebox) that stays screwed up in the email.

Weird.
Title: Re: Well now, here's a weird one - VB programming (ugh, I know)
Post by: Ecrofirt on December 06, 2008, 05:15:17 PM
More peculiar still, if I add a second vbNewLine to each line that doesn't correctly break, then I have a paragraph break between each line, like this:
Blah Line 1 Blah Line 2

becomes

Blah Line 1

Blah Line 2
Title: Re: Well now, here's a weird one - VB programming (ugh, I know)
Post by: Bocsius on December 06, 2008, 06:46:08 PM
Try vbCrLf instead of vbNewLine. If the email comes through as HTML, try "<br /.>" (minus the period) instead of either. If neither works, I've got nothing.
Title: Re: Well now, here's a weird one - VB programming (ugh, I know)
Post by: Ecrofirt on December 06, 2008, 06:48:42 PM
Try vbCrLf instead of vbNewLine. If the email comes through as HTML, try "<br /.>" (minus the period) instead of either. If neither works, I've got nothing.

Funny thing is, I was initially using vbCrLf, but it gave the same results. The email is coming through text-only, unfortunately :(