2023年8月31日 星期四

windows ms-dos 列印文件及圖

 print /d:COM1 'file path'

type d:\abc.txt > COM1

type d:\abc.txt > lpt1

--

share your network printer, even though you will use it yourself

then use this command

net use lpt1: \\ownpcname\printersharename

now use this command again:

type d:\abc.txt > lpt1

Printing to a network Thermal printer

         Public Sub SendViaTCP(ByVal whatIP As String, ByVal whatPort As Integer, ByVal whatToSend As String)

            Dim tcpSender As TcpClient = New TcpClient()

            tcpSender.SendBufferSize = 4096

            tcpSender.Connect(whatIP, whatPort)

            If tcpSender.Connected = False Then

                MessageBox.Show("Not connected")

                tcpSender.Close()

                Exit Sub

            End If


            Dim nStream As NetworkStream = tcpSender.GetStream()

            If nStream.CanWrite = True Then

                Dim SendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(whatToSend)

                nStream.Write(SendBytes, 0, SendBytes.Length)

                nStream.Flush()

            End If

            System.Threading.Thread.Sleep(500)


            nStream.Close()

            tcpSender.Close()

        End Sub


在 Visual Basic 中接收來自序列埠的字串

 如何:在 Visual Basic 中接收來自序列埠的字串

--

Function ReceiveSerialData() As String

    ' Receive strings from a serial port.

    Dim returnStr As String = ""


    Dim com1 As IO.Ports.SerialPort = Nothing

    Try

        com1 = My.Computer.Ports.OpenSerialPort("COM1")

        com1.ReadTimeout = 10000

        Do

            Dim Incoming As String = com1.ReadLine()

            If Incoming Is Nothing Then

                Exit Do

            Else

                returnStr &= Incoming & vbCrLf

            End If

        Loop

    Catch ex As TimeoutException

        returnStr = "Error: Serial Port read timed out."

    Finally

        If com1 IsNot Nothing Then com1.Close()

    End Try


    Return returnStr

End Function

SQL Server 中的 JSON 資料

要在 SQL Server 中應用 JSON 資料

必須 SQL Server 2016 (13.x) 以上版本

請參考:SQL Server 中的 JSON 資料


2023年8月2日 星期三

vbnet 判斷閏年

     Private Sub CheckLeapYear(ByVal Int_Year As Integer)

        Dim Boo_LeapYear As Boolean

        Boo_LeapYear = Date.IsLeapYear(Int_Year)

        If Boo_LeapYear Then

            MessageBox.Show(Int_Year & "閏年")

        Else

            MessageBox.Show(Int_Year & "不是閏年")

        End If

    End Sub