塵芥回顧録

掃き溜めのようなブログ(?)

ひらがなをローマ字に変えるユーザー定義関数

力技だが変に複雑に作るよりは修正し易い気がする(言い訳)

現状の問題点:"っ"が続くと正確な変換が行えないと思われる
2021-08-31:"っ"が2回続いた場合xxtuで処理するよう変更
      "ふぅ","くぅ","ゎ","ヶ","ゖ","!","?","、","。"を追加
      "っ"の次がな行だった場合xtuにするよう変更
      "じぃ"の処理をzyiからjyiに変更
2021-09-10:"ん"の次が"n","n","N","N"だった場合nnになるよう変更

Function ROMAJI(word As String) As String
 
  Dim SEARCH As String
  Dim SEARCH2 As String
  Dim SEARCH3 As String
  Dim RESULT As String
  
  For i = 1 To LEN(word)
  
	SEARCH = MID(word,i,1)
    
	Select Case SEARCH
	Case "あ" 
	RESULT = RESULT & "a"
	Case "い" 
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぇ"
		RESULT = RESULT & "ye"
		i=i+1
		Case Else
		RESULT = RESULT & "i"
		End Select
	Case "う" 
 		SEARCH2 = MID(word,i+1,1)
 		Select Case SEARCH2
 		Case "ぁ"
 		RESULT = RESULT & "wha"
 		i=i+1
		Case "ぃ"
		RESULT = RESULT & "wi"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "we"
		i=i+1
 		Case "ぉ"
 		RESULT = RESULT & "who"
 		i=i+1
		Case Else
		RESULT = RESULT & "u"
		End Select
	Case "え" 
	RESULT = RESULT & "e"
	Case "お" 
	RESULT = RESULT & "o"
	Case "か"
	RESULT = RESULT & "ka"
	Case "き"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "kya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "kyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "kyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "kye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "kyo"
		i=i+1
		Case Else
		RESULT = RESULT & "ki"
		End Select
	Case "く"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "qa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "qi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "qwu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "qe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "qo"
		i=i+1
		Case "ゃ"
		RESULT = RESULT & "qya"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "qyu"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "qyo"
		i=i+1
		Case Else
		RESULT = RESULT & "ku"
		End Select
	Case "け"
	RESULT = RESULT & "ke"
	Case "こ"
	RESULT = RESULT & "ko"
	Case "さ"
	RESULT = RESULT & "sa"
	Case "し"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "sya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "syi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "syu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "sye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "syo"
		i=i+1
		Case Else
		RESULT = RESULT & "si"
		End Select
	Case "す"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "swa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "swi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "swu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "swe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "swo"
		i=i+1
		Case Else
		RESULT = RESULT & "su"
		End Select
	Case "せ"
	RESULT = RESULT & "se"
	Case "そ"
	RESULT = RESULT & "so"
	Case "た"
	RESULT = RESULT & "ta"
	Case "ち"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "tya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "tyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "tyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "tye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "tyo"
		i=i+1
		Case Else
		RESULT = RESULT & "ti"
		End Select
	Case "つ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "tsa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "tsi"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "tse"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "tso"
		i=i+1
		Case Else
		RESULT = RESULT & "tu"
		End Select
	Case "て"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "tha"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "thi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "thu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "the"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "tho"
		i=i+1
		Case Else
		RESULT = RESULT & "te"
		End Select
	Case "と"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "twa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "twi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "twu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "twe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "two"
		i=i+1
		Case Else
		RESULT = RESULT & "to"
		End Select
	Case "な"
	RESULT = RESULT & "na"
	Case "に"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "nya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "nyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "nyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "nye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "nyo"
		i=i+1
		Case Else
		RESULT = RESULT & "ni"
		End Select
	Case "ぬ"
	RESULT = RESULT & "nu"
	Case "ね"
	RESULT = RESULT & "ne"
	Case "の"
	RESULT = RESULT & "no"
	Case "は"
	RESULT = RESULT & "ha"
	Case "ひ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "hya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "hyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "hyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "hye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "hyo"
		i=i+1
		Case Else
		RESULT = RESULT & "hi"
		End Select
	Case "ふ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "fa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "fi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "fwu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "fe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "fo"
		i=i+1
		Case "ゃ"
		RESULT = RESULT & "fya"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "fyu"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "fyo"
		i=i+1
		Case Else
		RESULT = RESULT & "hu"
		End Select
	Case "へ"
	RESULT = RESULT & "he"
	Case "ほ"
	RESULT = RESULT & "ho"
	Case "ま"
	RESULT = RESULT & "ma"
	Case "み"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "mya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "myi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "myu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "mye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "myo"
		i=i+1
		Case Else
		RESULT = RESULT & "mi"
		End Select
	Case "む"
	RESULT = RESULT & "mu"
	Case "め"
	RESULT = RESULT & "me"
	Case "も"
	RESULT = RESULT & "mo"
	Case "や"
	RESULT = RESULT & "ya"
	Case "ゆ"
	RESULT = RESULT & "yu"
	Case "よ"
	RESULT = RESULT & "yo"
	Case "ら"
	RESULT = RESULT & "ra"
	Case "り"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "rya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "ryi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "ryu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "rye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "ryo"
		i=i+1
		Case Else
		RESULT = RESULT & "ri"
		End Select
	Case "る"
	RESULT = RESULT & "ru"
	Case "れ"
	RESULT = RESULT & "re"
	Case "ろ"
	RESULT = RESULT & "ro"
	Case "わ"
	RESULT = RESULT & "wa"
	Case "を"
	RESULT = RESULT & "wo"
	Case "ん"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "あ","い","う","え","お","な","に","ぬ","ね","の","や","ゆ","よ",""," "," ","n","n","N","N"
		RESULT = RESULT & "nn"
		Case Else
		RESULT = RESULT & "n"
		End Select
	

	Case "が"
	RESULT = RESULT & "ga"
	Case "ぎ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "gya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "gyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "gyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "gye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "gyo"
		i=i+1
		Case Else
		RESULT = RESULT & "gi"
		End Select
	Case "ぐ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "gwa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "gwi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "gwu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "gwe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "gwo"
		i=i+1
		Case Else
		RESULT = RESULT & "gu"
		End Select
	Case "げ"
	RESULT = RESULT & "ge"
	Case "ご"
	RESULT = RESULT & "go"
	Case "ざ"
	RESULT = RESULT & "za"
	Case "じ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "ja"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "jyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "ju"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "je"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "jo"
		i=i+1
		Case Else
		RESULT = RESULT & "zi"
		End Select
	Case "ず"
	RESULT = RESULT & "zu"
	Case "ぜ"
	RESULT = RESULT & "ze"
	Case "ぞ"
	RESULT = RESULT & "zo"
	Case "だ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "dha"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "dhi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "dhu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "dhe"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "dho"
		i=i+1
		Case Else
		RESULT = RESULT & "da"
		End Select
	Case "ぢ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "dya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "dyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "dyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "dye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "dyo"
		i=i+1
		Case Else
		RESULT = RESULT & "di"
		End Select
	Case "づ"
	RESULT = RESULT & "du"
	Case "で"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "dha"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "dhi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "dhu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "dhe"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "dho"
		i=i+1
		Case Else
		RESULT = RESULT & "de"
		End Select
	Case "ど"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "dwa"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "dwi"
		i=i+1
		Case "ぅ"
		RESULT = RESULT & "dwu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "dwe"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "dwo"
		i=i+1
		Case Else
		RESULT = RESULT & "do"
		End Select
	Case "ば"
	RESULT = RESULT & "ba"
	Case "び"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "bya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "byi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "byu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "bye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "byo"
		i=i+1
		Case Else
		RESULT = RESULT & "bi"
		End Select
	Case "ぶ"
	RESULT = RESULT & "bu"
	Case "べ"
	RESULT = RESULT & "be"
	Case "ぼ"
	RESULT = RESULT & "bo"
	Case "ぱ"
	RESULT = RESULT & "pa"
	Case "ぴ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ"
		RESULT = RESULT & "pya"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "pyi"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "pyu"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "pye"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "pyo"
		i=i+1
		Case Else
		RESULT = RESULT & "pi"
		End Select
	Case "ぷ"
	RESULT = RESULT & "pu"
	Case "ぺ"
	RESULT = RESULT & "pe"
	Case "ぽ"
	RESULT = RESULT & "po"
	
	Case "ぁ"
	RESULT = RESULT & "xa"
	Case "ぃ"
	RESULT = RESULT & "xi"
	Case "ぅ"
	RESULT = RESULT & "xu"
	Case "ぇ"
	RESULT = RESULT & "xe"
	Case "ぉ"
	RESULT = RESULT & "xo"
	Case "っ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "い"
			SEARCH3 = MID(word,i+2,1)
			Select Case SEARCH3
			Case "ぇ"
			RESULT = RESULT & "y"
			Case Else
			RESULT = RESULT & "yy"
			End Select
		Case "う"
			SEARCH3 = MID(word,i+2,1)
			Select Case SEARCH3
			Case "ぁ","ぃ","ぇ","ぉ"
			RESULT = RESULT & "w"
			Case Else
			RESULT = RESULT & "ww"
			End Select
		Case "か","き","け","こ"
		RESULT = RESULT & "k"
		Case "く"
			SEARCH3 = MID(word,i+2,1)
			Select Case SEARCH3
			Case "ぁ","ぃ","ぅ","ぇ","ぉ","ゃ","ゅ","ょ"
			RESULT = RESULT & "q"
			Case Else
			RESULT = RESULT & "k"
			End Select
		Case "さ","し","す","せ","そ"
		RESULT = RESULT & "s"
		Case "た","ち","つ","て","と"
		RESULT = RESULT & "t"
		Case "は","ひ","へ","ほ"
		RESULT = RESULT & "h"
		Case "ふ"
			SEARCH3 = MID(word,i+2,1)
			Select Case SEARCH3
			Case "ぁ","ぃ","ぅ","ぇ","ぉ","ゃ","ゅ","ょ"
			RESULT = RESULT & "f"
			Case Else
			RESULT = RESULT & "h"
			End Select
		Case "ま","み","む","め","も"
		RESULT = RESULT & "m"
		Case "や","ゆ","よ"
		RESULT = RESULT & "y"
		Case "ら","り","る","れ","ろ"
		RESULT = RESULT & "r"
		Case "わ","を"
		RESULT = RESULT & "w"
		
		Case "が","ぎ","ぐ","げ","ご"
		RESULT = RESULT & "g"
		Case "ざ","ず","ぜ","ぞ"
		RESULT = RESULT & "z"
		Case "じ"
			SEARCH3 = MID(word,i+2,1)
			Select Case SEARCH3
			Case "ゃ","ぃ","ゅ","ぇ","ょ"
			RESULT = RESULT & "j"
			Case Else
			RESULT = RESULT & "z"
			End Select
		Case "だ","ぢ","づ","で","ど"
		RESULT = RESULT & "d"
		Case "ば","び","ぶ","べ","ぼ"
		RESULT = RESULT & "b"
		Case "ぱ","ぴ","ぷ","ぺ","ぽ"
		RESULT = RESULT & "p"
		
		Case "ヴ","ゔ"
		RESULT = RESULT & "v"
		Case "ぁ","ぃ","ぅ","ぇ","ぉ","ゃ","ゅ","ょ","ゎ","ゖ","ヶ"
		RESULT = RESULT & "x"
		Case "っ"
		RESULT = RESULT & "xxtu"
		i=i+1
		Case "ゐ","ゑ"
		RESULT = RESULT & "w"
		Case Else
		RESULT = RESULT & "xtu"
		End Select
	Case "ゃ"
	RESULT = RESULT & "xya"
	Case "ゅ"
	RESULT = RESULT & "xyu"
	Case "ょ"
	RESULT = RESULT & "xyo"
	Case "ゎ"
	RESULT = RESULT & "xwa"
	Case "ヶ","ゖ"
	RESULT = RESULT & "xke"
	
	Case "ヴ","ゔ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ぁ"
		RESULT = RESULT & "va"
		i=i+1
		Case "ぃ"
		RESULT = RESULT & "vi"
		i=i+1
		Case "ぇ"
		RESULT = RESULT & "ve"
		i=i+1
		Case "ぉ"
		RESULT = RESULT & "vo"
		i=i+1
		Case "ゃ"
		RESULT = RESULT & "vya"
		i=i+1
		Case "ゅ"
		RESULT = RESULT & "vyu"
		i=i+1
		Case "ょ"
		RESULT = RESULT & "vyo"
		i=i+1
		Case Else
		RESULT = RESULT & "vu"
		End Select
		
	Case "ゐ"
	RESULT = RESULT & "wyi"
	Case "ゑ"
	RESULT = RESULT & "wye"
	Case "ー"
	RESULT = RESULT & "-"
	Case "!"
	RESULT = RESULT & "!"
	Case "?"
	RESULT = RESULT & "?"
	Case "、"
	RESULT = RESULT & ","
	Case "。"
	RESULT = RESULT & "."

	Case Else
	RESULT = RESULT & SEARCH
	End select
  
  Next i
	
  ROMAJI = RESULT
 
End Function