無限不可能性ドライブ

『ニューラルネットワーク自作入門』に刺激されてExcelVBAでニューラルネットワークを作ってみたものの、やっぱり数学やらなきゃと思い少しずつやってきたのもあって、自分の知識の整理とかそういった感じです。

【VBA】文字色やセル色に文字を埋め込む(埋め込み編)

f:id:celaeno42:20210312231256p:plain

Option Explicit

Public Sub 文字列を埋め込む()
    Dim txt As String
    Dim ch As String
    Dim i As Long, r As Long
    Dim lngR As Long, lngG As Long, lngB As Long
    Dim sw As Long
    Dim ascCode As Long
    
    txt = "Hello" & vbNewLine & "World !"
    
    r = 1
    Columns(1).Clear
    
    For i = 1 To Len(txt)
        ch = Mid(txt, i, 1)
        ascCode = Asc(ch)
    
        sw = i Mod 6
        Select Case sw
            Case 1, 4
                lngR = ascCode
                If sw = 1 Then
                    Cells(r, 1).Font.Color = rgb(lngR, 0, 0)
                Else
                    Cells(r, 1).Interior.Color = rgb(lngR, 255, 255)
                End If
            Case 2, 5
                lngG = ascCode
                If sw = 2 Then
                    Cells(r, 1).Font.Color = rgb(lngR, lngG, 0)
                Else
                    Cells(r, 1).Interior.Color = rgb(lngR, lngG, 255)
                End If
            Case 3, 0
                lngB = ascCode
                If sw = 3 Then
                    Cells(r, 1).Font.Color = rgb(lngR, lngG, lngB)
                Else
                    Cells(r, 1).Interior.Color = rgb(lngR, lngG, lngB)
                    r = r + 1
                End If
        End Select
    
    Next
    
End Sub