VB.NET에서 자주 사용하는 방법

33225 단어
1. dll 라이브러리를 사용하는 방법:
dll 라이브러리는 동적 링크 라이브러리로 일반적으로 다른 사람이 제공하는 것으로 2차 개발에 사용된다. 다른 사람이 일부 함수를 dll에 포장한 것과 같다. 이미 링크 가능한 파일을 생성했기 때문에 호출만 할 수 있지만 방법의 실현을 볼 수 없다.그래서 당신에게 dll을 제공하는 사람은 일반적으로 dll의 라이브러리 함수 설명을 제공할 것입니다. 설명에서 안에 있는 함수의 반환값, 매개 변수 등 몇 가지를 알려 줍니다.
1、dll 라이브러리의 방법을 사용하려면 먼저 dll 복사를 붙여 넣으세요.net 프로젝트의\bin\Debug 경로 아래.
2. 프로젝트에 모듈 모듈을 새로 만들고 그 안에 사용할 함수를 설명합니다.예를 들어, API라는 모듈을 새로 만들고 다음 절차에 따라 함수를 선언합니다.
  
Imports System.Text
Module API

    '      
    Public Declare Function RDR_LoadReaderDrivers Lib "rfidlib_reader.dll" (ByVal path As String) As Integer
    Public Declare Function RDR_GetLoadedReaderDriverCount Lib "rfidlib_reader.dll" () As Integer

    '
    Public Declare Function RDR_Open Lib "rfidlib_reader.dll" (ByVal connstr As String, ByRef hr As UIntPtr) As Integer
    Public Declare Function RDR_Close Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As Integer

    '      
    Public Declare Function RDR_GetReaderLastReturnError Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As Integer

    '
    Public Declare Function RDR_GetTagDataReportCount Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As UInt32



    '             
    Public Declare Function RDR_GetReaderInfor Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal Type As Byte, ByRef buffer As StringBuilder, ByRef nSize As UInt32) As Integer

    '       
    Public Declare Function RDR_CreateInvenParamSpecList Lib "rfidlib_reader.dll" () As UIntPtr
    Public Declare Function ISO15693_CreateInvenParam Lib "rfidlib_aip_iso15693.dll" (ByVal hInvenParamSpecList As UIntPtr, ByVal AntennaID As Byte, ByVal en_afi As Byte, ByVal afi As Byte, ByVal slot_type As Byte) As UIntPtr
    Public Declare Function RDR_TagInventory Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal AIType As Byte, ByVal AntennaCount As Byte, ByRef AntennaIDs As Byte, ByVal InvenParamSpecList As UIntPtr) As Integer 'AntennaIDs            
    Public Declare Function RDR_GetTagDataReport Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal Seekpos As Byte) As UIntPtr
    Public Declare Function ISO15693_ParseTagDataReport Lib "rfidlib_aip_iso15693.dll" (ByVal hTagReport As UIntPtr, ByRef aip_id As UInt32, ByRef tag_id As UInt32, ByRef ant_id As UInt32, ByRef dsfid As Byte, ByRef uid As Byte) As Integer


    '           
    Public Declare Function DNODE_Destroy Lib "rfidlib_reader.dll" (ByVal dn As UIntPtr) As Integer

    '         
    Public Const RFID_SEEK_FIRST = 1
    Public Const RFID_SEEK_NEXT = 2

    '   
    Public Declare Function ISO15693_Connect Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal tagType As UInt32, ByVal address_mode As Byte, ByVal uid() As Byte, ByRef ht As UIntPtr) As Integer

    '  
    Public Declare Function ISO15693_ReadMultiBlocks Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal ht As UIntPtr, ByVal readSecSta As Byte, ByVal blkAddr As UInt32, ByVal numOfBlksToRead As UInt32, ByRef numOfBlksRead As UInt32, ByRef bufBlocks As Byte, ByVal nSize As UInt32, ByRef bytesBlkDatRead As UInt32) As Integer

    '  
    Public Declare Function ISO15693_WriteMultipleBlocks Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal ht As UIntPtr, ByVal blkAddr As UInt32, ByVal numOfBlks As UInt32, ByVal newBlksData() As Byte, ByVal bytesToWrite As UInt32) As Integer









    Public Declare Function LSG_CmdGetReports Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal Flag As Byte, ByVal recordsToGet As Byte) As Integer
    Public Declare Function LSG_ParseSCEventData Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal slData As String, ByVal nSize As Long, ByRef dir As Byte, ByRef m_time As Byte) As Integer
    Public Declare Function LSG_CmdGetCurrentFlowOfPeople Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByRef inFlow As Long, ByRef outFlow As Long) As Integer
    Public Declare Function LSG_CmdResetFlowOfPeople Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal mFlg As Byte) As Integer
    Public Declare Function LSG_CmdReverseDirection Lib "rfidlib_LSGate.dll" (ByVal hr As Long) As Integer
    Public Declare Function LSG_CmdGetSystemTime Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByRef year As Long, ByRef month As Byte, ByRef day As Byte, ByRef hour As Byte, ByRef minute As Byte, ByRef second As Byte) As Integer
    Public Declare Function LSG_CmdSetSystemTime Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal year As Long, ByVal month As Byte, ByVal day As Byte, ByVal hour As Byte, ByVal minute As Byte, ByVal second As Byte) As Integer


    Public Declare Function MultiByteToWideChar Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
    Public Declare Function WideCharToMultiByte Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
    Public Const CP_ACP = 0 ' default to ANSI code page
    Public Const CP_UTF8 = 65001 ' default to UTF-8 code page

End Module

 
선언된 함수를 프로젝트에서 호출할 수 있습니다. 예를 들면 다음과 같습니다.
     '     
        Dim connStr = "RDType=RD201;CommType=COM;COMName=" + CmboxcommCanBeUse.SelectedItem + ";BaudRate=38400;Frame=8E1;BusAddr=255"
        Dim connectOK As Integer = 99
        connectOK = RDR_Open(connStr, hr)

위 코드의 RDROpen () 함수는 API 모듈에서 명시된 것으로 함수가 있는 위치는 rfidlibreader.dll 중.
 
2. 자주 사용하는 방법:
Now()가 현재 날짜와 시간을 가져옵니다.
Format() 포맷 날짜 시간 함수:
 Format(Now(), "yyyy-MM-dd-hh-mm-ss")

 
DataGridView 사용법:
GoodDataGridView.Rows.Add()     

GoodDataGridView.Rows.RemoveAt(1)

GoodDataGridView(0, 0).Value = " " 。 (0,0) , 。
     GoodDataGridView.Rows.Add()
        GoodDataGridView(0, 0).Value = "  "
        GoodDataGridView(1, 0).Value = "    "
        GoodDataGridView(2, 0).Value = "    "
        GoodDataGridView(3, 0).Value = "    "

 
배열을 정의하고 초기화하려면 다음과 같이 하십시오.
      '
        Dim goodsNumb() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim goodsName() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim goodsPric() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

 
UTF8 인코딩 및 디코딩:
Imports System.Text

Module UTF8

    'UTF8    
    Public Function StringToUTF8Bytes(ByVal strData As String) As Byte()

        Dim bytes() As Byte
        bytes = Encoding.UTF8.GetBytes(strData)
        Return bytes

    End Function

    'UTF8    
    Public Function UTF8BytesToString(ByVal strData() As Byte) As String

        Dim retstring As String
        retstring = Encoding.UTF8.GetString(strData)
        Return retstring

    End Function

End Module

 
데이터 gridview 칸막이 색상:
datagridview1.RowsDefaultCellStyle.BackColor = Color.Bisque

datagridview1.AlternatingRowsDefaultCellStyle.BackColor =Color.Beige

 
데이터gridview 제목 글꼴 스타일 설정:
  ColumnHeaderDefaultCellStyle Font  
    
datagridview.Columns[index].DefaultCellStyle.Font.Size=size

 
전재 대상:https://www.cnblogs.com/jiwangbujiu/p/5555850.html

좋은 웹페이지 즐겨찾기