vb.net フォーム右上の閉じるボタンを無効にする

以下をフォームのコードに追加

' CreateParams プロパティをオーバーライドする
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
    Get
        Const CS_NOCLOSE As Integer = &H200

        Dim DcreateParams As System.Windows.Forms.CreateParams = MyBase.CreateParams
        DcreateParams .ClassStyle = DcreateParams .ClassStyle Or CS_NOCLOSE

        Return DcreateParams 
    End Get
End Property

ネタ元

jeanne.wankuma.com

C# VB.net フォームの位置とサイズを記憶させる

Form1_Load()で復元処理して、FormClosing()で保存処理する

以下はレジストリ使った例

Private Sub FormHoge_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim regkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\hoge\param")
        Dim size As Size
        size = New Size(regkey.GetValue("w", 1024), regkey.GetValue("h", 768))
        Me.ClientSize = size

        Dim point As Point
        point = New Point(regkey.GetValue("x", 0), regkey.GetValue("y", 0))
        Me.Location = point
End Sub
Private Sub FormHoge_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Dim regkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\hoge\param")
        regkey.SetValue("w", Me.ClientSize.Width)
        regkey.SetValue("h", Me.ClientSize.Height)

        regkey.SetValue("x", Me.Location.X)
        regkey.SetValue("y", Me.Location.Y)
End Sub

ApplicationSettingsを使ったやつだと
DLLで実装した場合、再起動するとすべて忘れてしまった。
あとClientSizeは思ったとおりにならない罠があるらしい。

ExcelVBA 拡張子を除く

Function RemoveExtension(aFilename As String) As String

    '--- 拡張子の位置 ---'
    Dim posExt As Long
    posExt = InStrRev(aFilename, ".")
    
    '--- 拡張子を除いたパス(ファイル名)を格納する変数 ---'
    Dim strFileExExt As String
    
    If (0 < posExt) Then
        RemoveExtension = Left(aFilename, posExt - 1)
    Else
        RemoveExtension = aFilename
    End If
    
End Function

Excel VBAでSqlite操作

・必要なものがExcelForSQLite3としてまとまってるのでありがたくダウンロード。
github.com

・zipDLして解凍した中にあるDLLをSqliteを利用するxlsmファイルと同じ場所におく。
32bitExcelならsqlite3.dll/SQLite3_StdCall.dllを
64bitExcelならx64フォルダにあるsqlite3.dllを使いましょう。

・SQLite3VBAModulesフォルダの中に標準モジュールがあるのでVBAのファイルのインポートで取り込む。
32bitExcelならSqlite3.bas / Sqlite3Demo.bas
64bitExcelならSqlite3_64.bas / Sqlite3Demo_64.bas

・Sqlite3Demoの中のAllTests()を呼び出して問題なく動いたらOK

ネタ元

pandanote.info

vb.netでJSONを分解 Json.NET Newtonsoft.Json

サンプルjson

{
    "14": [
        {
            "328": "1301",
            "332": "名前"
        },
        {
            "328": "1305",
            "332": "名前"
        }
    ],
    "173": "",
    "174": "0",
    "175": "2",
    "176": "2021.08.16-20:50:28.087",
    "177": "2021.08.16-20:50:28.217",
    "192": "hogeData"
}

分解サンプル

nugetから"Newtonsoft.Json"追加しとく

Imports Newtonsoft.Json.Linq

Dim jsonObject = JObject.Parse(jsonstr)

' ループでjson分解
Dim futureCodeArray As New ArrayList
Dim jsonObjectC1
For Each jsonObjectC1 In jsonObject("hogekey")
    Dim jsonObjectC2
    For Each jsonObjectC2 In jsonObjectC1.First
        Debug.WriteLine(jsonObjectC2.Value)
        futureCodeArray.Add(jsonObjectC2.Value)
    Next
Next