Print to POS Display Unit - vba

I have an Epson Display Unit (for the Point of Sale), and have it set up as a printer. I can only get it to print what I want when I go to Printer Properties > Fonts (there is a test input box).
However printing from an app such as notepad yields no results. I'm trying to get it to work with the p.o.s. app I made in Excel. I found a COMM port communication script here, but I can't get past the OPEN command. Seems there's a "file in use". I'd like to know if anyone else has had experience with this sort of thing.

Under the assumption that your printer is connected to serial interface 1, provided that the serial interface parameters are correctly set, and you want to send a string of characters to that interface, you may try this ...
Sub WriteToCOM()
Open "COM1:" For Output As #1
Write #1, "ddd"
Close #1
End Sub
Paste this code into an Excel VBA script and cycle thru it with F8 - it worked for me
You may replace "COM1:" by any existing "COMx:" or "LPTx:" as well (don't forget the semicolon!)
I am using this to control an Amateur Radio (setting the frequency) from an Excel table containing broadcast station names and their frequencies. I am of course sending special characters to my gear using the chr() function.
The Macro is tied to a control button. My Excel is Office 2003 (it worked already in Office97)
Good luck
MikeD

Related

Mysterious Black Lines in Word When Using In-House VB.Net Application

A little backstory. I work at an organization that uses Mail Merge and SQL Databases to populate letters with names/addresses. Those letters are sent out to our donors as thank yous. These letters change frequently, and new ones come up at least 10 times a month.
To simplify our process, I created a program that allows you to copy/paste the letter body content into rich text boxes and when you press the 'Go' button, it opens a pre-made Word template and replaces bookmarks in the template with the copied body content.
The program works great with most letters, but some of them have a problem where these thick black lines are created and I'm unable to do ANYTHING to remove them. I can't right click them, I can't delete them with Backspace or Delete, and I can't highlight them.
I'm thinking that the problem may come from hidden formatting. Some of the employees that write the letters are using the Mac version of Office 2016, and I'm using Windows version. I sent an RTF file that showed the black lines for me to someone who uses the Mac version, and they said they couldn't see the lines.
My question is, is there a way to get rid of these lines or prevent them in the future? I've thought about upgrading Office version to 2019 on both ends, but there are quite a few people that have their hands in these letters and it may be difficult to upgrade everyone.
Please refer to the attached image for visual reference. Names and personal details have been removed.
EDIT: Here is the 'Go' code:
'create temp rtf files to maintain rtf
If strForm = "ANG2" Then
txtPreD.SaveFile("\\server\AcknowledgementLetters\fptemp.rtf")
txtPostD.SaveFile("\\server\AcknowledgementLetters\bptemp.rtf")
ElseIf strForm = "ANGL" Then
txtPreD.SaveFile("\\server\AcknowledgementLetters\predtemp.rtf")
txtPostD.SaveFile("\\server\AcknowledgementLetters\postdtemp.rtf")
txtBP.SaveFile("\\server\AcknowledgementLetters\bptemp.rtf")
Else
txtPreD.SaveFile("\\server\AcknowledgementLetters\predtemp.rtf")
txtPostD.SaveFile("\\server\AcknowledgementLetters\postdtemp.rtf")
End If
'if bookmarks exists, insert appropriate rtf files
If odoc.Bookmarks.Exists("fp") = True Then
goWord.ActiveDocument.Bookmarks("fp").Select()
goWord.Selection.InsertFile(FileName:="\\server\AcknowledgementLetters\fptemp.rtf")
End If
If odoc.Bookmarks.Exists("bp") = True Then
goWord.ActiveDocument.Bookmarks("bp").Select()
goWord.Selection.InsertFile(FileName:="\\server\AcknowledgementLetters\bptemp.rtf")
End If
If odoc.Bookmarks.Exists("PreD") = True Then
goWord.ActiveDocument.Bookmarks("PreD").Select()
goWord.Selection.InsertFile(FileName:="\\server\AcknowledgementLetters\predtemp.rtf")
End If
If odoc.Bookmarks.Exists("PostD") = True Then
goWord.ActiveDocument.Bookmarks("PostD").Select()
goWord.Selection.InsertFile(FileName:="\\server\AcknowledgementLetters\postdtemp.rtf")
End If
Before this happens, the program checks to see which template it needs to open and opens it as a Word object (odoc). This bit of code is really the only important part. After this, I just click Finish it just saves the file once I'm done checking it for errors. Also, yes, the RTF files that it creates DO have the black lines as well. Here is another picture of the program itself just so you can get a better idea of what's going on.

Getting a Screenshot From A Bloomberg Terminal

I have a project and it requires grabbing multiple screenshots from a Bloomberg Terminal and I'd like to automate it.
This what I have so far:
Dim abc As Variant
Dim CUSIP As String
CUSIP = Range("A1")
ch = DDEInitiate("winblp", "bbk")
Call DDEExecute(abc, "<blp-1>" & CUSIP & " mtge<GO>")
Call DDEExecute(abc, "<blp-1> CFG<Go>")
Call DDEExecute (abc, "blp-1 <copy>")
Call DDETerminate(ch)
This correctly gets me to the graph I want (in this case the CFG, or Cash Flow Graph), but from this point, I am unable to figure out a screenshot method. In Bloomberg, there are a few commands, but they all require the use of a mouse. I've seen some do it before where they are able to get the requisite screenshots, but I can't figure out how.
So basically, I can use excel and VBA to get Bloomberg to pull up the correct screen, but now I just need to figure out a way to grab snipshot for the thing.
It's worth mentioning that the copy line just copies the data, not an image (which is what I was hoping for).
One option is to send the screenshot to your personal email address and download it from there:
Run GRAB in blp-1
Enter your personal email address
Download it manually from there or use an IMAP library to do so automatically
Another option is to use a 3rd party grabbing utility that has command line options. For example, Snagit can be started with an argument that creates a screenshot: http://informationworker.ru/snagit10.en/snagit_4_technical_reference.4.35.html

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

In batch file, how to get focus on a specific window (opened file)

A very simple question I suppose, but I reached a deadlock with this:
I have to use a .bat file to imput plain text data into the right cells an excel sheet with lots of graphics content, vba parts, macro that deactivate "normal" EXCEL buttons and functions, password to protect the pre-typed functions, sudden and unexpected changes in the version of the "taget file", and many other complications...
My need is to be absolutely sure that the .bat is sending the sequence into the right version of the .xlsm file.
To do that I want to store the last known filename (that include the file version) in the .bat file, and I want to take focus on the excel window in wich the data have to be written ONLY IF the title of the excel window is exactly the same.
So Here is the question: How to get the focus on a specific open file from a .bat file?
You can't. If you wanted to use vbscript or jscript you could do what you want in a command prompt in an unreliable way (but it will work most circumstances).
Excel has it's own forms.
Put column headers in a row. Put selection in same row. Alt + D, O.
Plus you can make Excel only allow entries on some cells, like a invoice form.
Right click cell, Properties, Protection, Unlock. Then Alt + T, P, P.
Word has it's own forms similar to Excel (Word is also a spreadsheet).
Excel VBA language (and VBScript too) has input box command.
Sub main()
Sheet1.Range("A1").Value2 = InputBox("enter Value")
End Sub

Send Ascii command in vba

I am fairly new to vba. Appologies if this is a simple question, but after 3 days on google im starting to feel dumb.
I am writing a very simple POS program to take stock in a bar. Part of the program is a Till point function. I am writing in excel VBA. I have a generic pos printer connected to a generic cash drawer. Printer is connected via usb to pc.
My question: i am unable to get the cash drawer to kick open when a receipt is printed. It is printing the reciepts fine, but i do not how how to send a ascii - esc/pos command to the printer.
I know that i should use "chr(27), chr(112)" , but how?!
As a last resort Ive tried pasting those chars in a cell and used cells("A1").printout function but that just sends it to the printer as text to be printed and not a command.
Any help would be greatly appreciated.
Marchant
This link suggests:
Option Explicit
Sub testme01()
Open "LPT1:" For Output As #1
Print #1, chr(27)+chr(112)
Close #1
End Sub