No.1ベストアンサー
- 回答日時:
田吾作7です。
Nullの扱いですが、それはあくまでCの記述であって、CのNullとVBのNullは意味が違います。
GetPrivateProfileStringではvbNullStringを使用します。
Public Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
'ウィンドウズディレクトリを返す
Public Function GetWinDir() As String
Dim lpBuffer As String * 260
Call GetWindowsDirectory(lpBuffer, Len(lpBuffer))
GetWinDir = Left(lpBuffer, InStr(lpBuffer, Chr$(0)) - 1)
If Right(GetWinDir, 1) <> "\" Then GetWinDir = GetWinDir & "\"
End Function
'INIファイルからセクションを列挙する
Private Sub Main()
Dim lngRetValue As Long 'ステータス
Dim strIniFileName As String '設定ファイル名
Dim strSectionName As String 'セクション名
Dim strKeyName As String 'キー名
Dim strDefault As String 'デフォルト値
Dim strReturned As String * 1023 '値を返す文字列
Dim wkVal As Variant
Dim i As Long
'イニシャルファイルの指定
strIniFileName = GetWinDir & "System.ini"
'セクションにNULLをセット
strSectionName = vbNullString
'キーにNULLセット
strKeyName = vbNullString
'見つからないときに返す文字列
strDefault = "キーが見つからない"
'キーが帰る文字列に領域をセット
strReturned = String(Len(strReturned), vbNullChar)
'キーの取得
lngRetValue = GetPrivateProfileString _
(ByVal strSectionName _
, ByVal strKeyName _
, ByVal strDefault _
, strReturned _
, ByVal Len(strReturned) _
, ByVal (strIniFileName & vbNullChar))
'キーの取得成功
If lngRetValue >= 0 Then
'結果の出力
wkVal = Split(strReturned, vbNullChar)
For i = LBound(wkVal) To UBound(wkVal)
Debug.Print wkVal(i)
If wkVal(i) = "" Then
Exit For
End If
Next i
'キーの取得失敗
Else
Debug.Print "失敗しました"
End If
End Sub
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
プラス(足す)キーはどうやっ...
-
キーボードがCtrlキーが押され...
-
「か」を数字で表すとどうなり...
-
あさぎーにょちゃんの『別の人...
-
(word) 文字列の上に線を引く方法
-
プーリーのキーが外れない
-
ノートPC起動中のエラーメッセ...
-
パソコンの青い線枠が消えませ...
-
「(アクサングラーブ)キー」と...
-
バイクキーシャッターがあかない
-
キーボードの上部にあるランプ...
-
Wordで繰り返しのショートカッ...
-
パソコン素人です。 NECのノー...
-
キーボードにキーをつけるため...
-
Scroll Lockが勝手に有効になる...
-
Fnキーが効かない
-
VSCodeで上書きモードにならない
-
BackSpaceキーを押しても・・・...
-
hpのelitebook使ってますが最近...
-
BIOSが起動しない
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
プラス(足す)キーはどうやっ...
-
キーボードがCtrlキーが押され...
-
「か」を数字で表すとどうなり...
-
Scroll Lockが勝手に有効になる...
-
メールアドレスの作成の際上バ...
-
「(アクサングラーブ)キー」と...
-
パソコンの青い線枠が消えませ...
-
IMEパッドがショートカットキー...
-
PgDn、PgUpの設定が急に変わっ...
-
プーリーのキーが外れない
-
Ctrlキー+HomeキーでセルA1へ移...
-
あさぎーにょちゃんの『別の人...
-
VSCodeで上書きモードにならない
-
PDF-XChange Viewer 全画面表示...
-
BackSpaceキーを押しても・・・...
-
パソコンをネットに繋いでいな...
-
矢印キーのロック解除方法
-
Excelでカーソルの移動が...
-
キーボードの上部にあるランプ...
-
Access2010 Enterで次テキスト...
おすすめ情報