發表文章

[VB6]bit-shift operation

圖片
VB6/VBA不支援 "<<" & ">>"的位元操作 (C/C++/C#) a = b << n ;b左移n bits a = b >> n ;b右移n bits (VB/VBA) a = b * (2 ^ n) '左移, 乘以2的n次方 a = b / (2^ n) '右移, 除以2的n次方 Demo code Option Explicit Sub bit_shift() Dim reg As Byte reg = &H1 ' 1 Debug.Print "Before: 0x" & Hex(reg) ' 2 reg = reg * (2 ^ 5) Debug.Print "left-shift 5-bits: 0x" & Hex(reg) ' 3 reg = reg / (2 ^ 2) Debug.Print "right-shift 2-bits: 0x" & Hex(reg) End Sub Result

[VB6]only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions

圖片
自定義Type類型於module中, 無法傳入function/sub函數 因user-define type無法與variant相容 下面為error code Line 19, UC51 宣告為 DRIVER_INFO , 傳入 IsEmptyArray()的source為Variant-type 兩種type無法強制轉換 只能將 IsEmptyArray() 的 source 宣告為 REGISTER-type 但導致 IsEmptyArray() 只能接受 REGISTER-type , 無法接受其他data type Option Explicit Private Type REGISTER name As String addr As Byte bank As Integer End Type Type DRIVER_INFO strID As String reg() As REGISTER End Type Sub main() Dim UC51 As DRIVER_INFO Dim tmpBuf() As String Debug.Print IsEmptyArray(tmpBuf) Debug.Print IsEmptyArray(UC51.reg) ' error here End Sub Function IsEmptyArray(source As Variant) As Boolean On Error GoTo ERROR_HANDLER If UBound(source) >= 0 Then Exit Function End If ERROR_HANDLER: IsEmptyArray = True End Function

[VB6]強制轉換變數類型 Type conversion functions

圖片
Syntax CBool( expression ) CByte( expression ) CCur( expression ) CDate( expression ) CDbl( expression ) CDec( expression ) CInt( expression ) CLng( expression ) CLngLng( expression )  (Valid on 64-bit platforms only.) CLngPtr( expression ) CSng( expression ) CStr( expression ) CVar( expression ) Resource https://docs.microsoft.com/zh-tw/office/vba/language/concepts/getting-started/type-conversion-functions

Hard Code

- Wiki 寫死(英語:Hard Code或Hard Coding)是指在軟體實作上,將輸出或輸入的相關參數(例如:路徑、輸出的形式或格式)直接以常數的方式撰寫在原始碼中,而非在執行期間由外界指定的設定、資源、資料或格式做出適當回應。一般被認定是種反模式或不完美的實作,因為軟體受到輸入資料或輸出格式的改變就必須修改原始碼,對客戶而言,改變原始碼之外的小設定也許還比較容易。 https://zh.wikipedia.org/wiki/%E5%AF%AB%E6%AD%BB - 軟體開發必須面對的Dirty Code https://www.ithome.com.tw/node/83209 - 擁抱改變,遠離Hard Code http://teddy-chen-tw.blogspot.com/2018/09/hard-code.html

[VB6]Error accessing the system registry (Win7SP1)

圖片
於Windows 7 Sp1 x64安裝完VB6, 執行時出現Error accessing system registry的錯誤訊息 - Solution 以 相容模式 & 系統管理員身分執行 VB6.EXE 即可

關閉VirtualBox時間同步

圖片
Version: 5.2.22 VM上調整系統時間回到過去, 調整完後又馬上被同步回當前時間 - Step 1 欲修改專案點選右鍵, 點選 顯示在檔案總管 or C:\Users\<USERPROFILE>\VirtualBox VMs\<PROJECT>\<PROJECT>*.vbox - Step 2 使用Text Editor開啟 <PROJECT>.vbox 尋找<ExtraData>  element, 包含其ExtraDataItem  elements 增加GetHostTimeDisabled Item <ExtraDataItem name="VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" value="1"/> - Step 3 存檔, 關閉, VM重新啟動

cout formatted

Class ios_base flags Get/set format flags  (public member function ) setf Set specific format flags  (public member function ) unsetf Clear specific format flags  (public member function ) precision Get/Set floating-point decimal precision  (public member function ) width Get/set field width  (public member function ) iomanip.h setiosflags Set format flags  (function ) resetiosflags Reset format flags  (function ) setbase Set basefield flag  (function ) setfill Set fill character  (function ) setprecision Set decimal precision  (function ) setw Set field width  (function ) get_money  Get monetary value  (function ) put_money  Put monetary value  (function ) get_time  Get date and time  (function ) put_time  Put date and time  (function ) 使用插入運算子和控制格式 https://msdn.microsoft.com/zh-tw/library/420970az.aspx 字串和 I/O 格式化 (現代 C++) https://msdn.mi...