發表文章

目前顯示的是 4月, 2019的文章

Silicon Laboratories IDE加入lib文件步驟

圖片
Silicon Laboratories IDE加入lib文件步驟 Project > Target Build Configuration > Customize > Files to Link > Add External OBJ

[VBA]如何藉由使用 Excel 中的 Visual Basic 程序選取儲存格/範圍

https://support.microsoft.com/zh-tw/help/291308/how-to-select-cells-ranges-by-using-visual-basic-procedures-in-excel Microsoft 僅提供示範性的程式設計範例,不做任何明示或默示的保證。 其中包括 (但不限於) 其適售性與適合某特定用途之默示擔保。 本文將假設您已相當熟悉示範所使用的程式設計語言,以及用於建立和偵錯程序的工具。 Microsoft 技術支援工程師可以協助說明特定程序的功能,但無法修改這些範例以提供附加功能或建構程序來滿足您的特定需求。  本文中的範例會使用下表中所列的 Visual Basic 方法。 方法 引數 ------------------------------------------ Activate none Cells rowIndex, columnIndex Application.Goto reference, scroll Offset rowOffset, columnOffset Range cell1 cell1, cell2 Resize rowSize, columnSize Select none Sheets index (or sheetName) Workbooks index (or bookName) End direction CurrentRegion none 本文中的範例會使用下表中的屬性。 屬性 用途 --------------------------------------------------------------------- ActiveSheet 指定使用中的工作表 ActiveWorkbook 指定使用中的活頁簿

[VB6]Optional parameters for function declares

Private Sub SomeSub(Optional SomeParam As Integer = 0) ' user code End Sub Ref https://docs.microsoft.com/zh-tw/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters https://stackoverflow.com/questions/4071820/default-value-for-function-parameters-in-vb6

[VB6]Random Seed

圖片
初始化亂數產生器 只呼叫Randomize()後面不加參數, 以系統時間做為亂數種子 如果沒呼叫Randomize(), 則每次產生的亂數都一樣 Ref https://docs.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/randomize-statement

[VB6]Select Case - multiple expressions or ranges in each Case

圖片
Dim Number Number = 8 ' Initialize variable. Select Case Number ' Evaluate Number. Case 1 To 5 ' Number between 1 and 5, inclusive. Debug.Print "Between 1 and 5" ' The following is the only Case clause that evaluates to True. Case 6, 7, 8 ' Number between 6 and 8. Debug.Print "Between 6 and 8" Case 9 To 10 ' Number is 9 or 10. Debug.Print "Greater than 8" Case Else ' Other values. Debug.Print "Not between 1 and 10" End Select Ref https://docs.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/select-case-statement

[VB6]Invalid procedure call or argument (Error 5)

圖片
在win7 on VM的環境上執行VB6 Enterprise 呼叫DataAdd func會產生Error 5 原以為是參數填錯, 再三確認後, 並在Excel VBA執行無誤 最後在stackOverflow看到是VB6設定相容性的問題 將相容模式取消即可 錯誤訊息 取消相容模式 原先的相容模式 Ref https://stackoverflow.com/questions/30043195/error-calling-dateadd-function

[VB6]使用Load / Unload呼叫Form

在一般情況下使用 Show Method 呼叫表單只有在第一次呼叫時會產生 Form_Load 事件 , 爾後使用 Show Method 呼叫不會產生 Form_Load 事件 , 因 Form 已被載入至 Memory 中 . 當如果有情況是需要每次執行 Form 都 Initialization, 則使用 Show Method 就不適合 . 解決辦法 使用 Load 則每次呼叫會發出 Form_Load 事件 , 執行 Form_Load 裡面的 Code. 使用 Load 將 Form 載入記憶體後 , 並不會顯示Form , 再呼叫一次 Show 即可顯示 Form. 離開 Form 使用 Unload 將 Form 從 Memory 卸載 , 常用的 Hide Method 僅隱藏表單 , 相關資料還是在 Memory 中 Load Statement https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa445825(v%3dvs.60) Unload Statement https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa445829(v%3dvs.60)

[VB6]使用File Dialog選擇檔案

圖片
加入 Common Dialog 的控件 , 成功加入後出現紅框的 Icon 表示成功 Microsoft Common Dialog Control 6.0 Control Object of Form 先在 Form 上建立 CommonDialog 的控件 , 如未建立使用控件會跳出 Variable not defined. Button 呼叫 CommonDialog, 顯示 FileDialog Private Sub CTL_BTN_SEL_FILE_Click() With CommonDialog1 .DialogTitle = "Select the Report File" .Filter = "Custom Format (*.xls)|*.xls" .Flags = .Flags + cdlOFNHideReadOnly .InitDir = specialPath("Desktop") .ShowOpen CTL_BTN_SEL_FILE.Caption = .fileName End With End Sub Property DialogTitle As String 設定 Dialog 的 Title Property Filter As String 設定檔案類型 https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa238813(v=vs.60) Property Flags As Long 設定屬性 https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa238842(v=vs.60) Property InitDir As String 設定初始位置 Sub ShowOpen () 顯示 File Dia

[VB6]MSFlexGrid使用記錄

圖片
- 設定 於 Components 加入 MSFlexGrid Microsoft FlexGrid Control 6.0 (SP6) C:\Windows\SysWow64\MSFLXGRD.OCX 加入後即在 Component Panel 上出現 MSFlexGrid 的控件 ( 紅框處 ) 在 Form 上建立 MSFlexGrid 控件 ,  對控件按右鍵可設置其 Property Common Property Style Property   Font Property   Color Property   Picture Property 在 Code 中設置 Property 較有彈性 , 故於選單中的屬性怒不設定 - 記錄 ' configuration property of MSFLESGRID1 With MSFlexGrid1 .AllowBigSelection = False .ColAlignment(-1) = flexAlignCenterCenter .FixedCols = 0 .FixedRows = 1 .HighLight = flexHighlightNever .ScrollBars = flexScrollBarVertical .ScrollTrack = True End With Property AllowBigSelection As Boolean 在 Row / Column 點選 Header 時 , 全選該 Rows 或 Columns Property ColAlignment (index As Long) As Integer 指定 Columns 的文字對齊 , -1 表設置全部 Columns Property FixedCols As Long Property FixedRows As Long 指定 Header 的數量 Property HighLight As HighLightSettings 設定圈選欄位時是