アプリ版:「スタンプのみでお礼する」機能のリリースについて

リストボックスに追加されたテキストを名前を付けて保存をしたいのですがどんなコードを書いたらいいのかわからなかったので質問させていただきました。
開発環境はVisualStudio2008です。

A 回答 (1件)

実行キッカケをボタンクリックとして


Imports System.IO

Public Class Form1の前(外)に入れて
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim i As Integer
Me.ListBox1.Items.Add("東京")
Me.ListBox1.Items.Add("神奈川")
Me.ListBox1.Items.Add("千葉")
Me.ListBox1.Items.Add("埼玉")
MsgBox(Me.ListBox1.Items.Count)
'--
Dim writer As StreamWriter
writer = New StreamWriter("C:\Documents and Settings\XXXX\My Documents\NETTEXT.txt")
For i = 0 To Me.ListBox1.Items.Count - 1
MsgBox(Me.ListBox1.Items(i))
writer.WriteLine(Me.ListBox1.Items(i))
Next i
writer.Close()
End Sub
XXXXの箇所などは修正のこと。前半Items.Addの部分はテストのため
入れたもの。
結果はNETTEXT.txtをメモ帳で開いて確認する。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!