質問編集履歴

5

追記しました。

2019/03/21 16:04

投稿

layla
layla

スコア14

test CHANGED
File without changes
test CHANGED
@@ -11,6 +11,12 @@
11
11
  そこで今度は逆に読み込みボタンを押してローカルに保存してあるcsvファイルを選択し、datagridviewに表示させる機能を付けたいのですが、どこのサイトを見てもやり方を見つけることが出来ませんでした。具体的なコードなどを教えていただけると幸いです。
12
12
 
13
13
 
14
+
15
+ 追記
16
+
17
+ http://bbs.wankuma.com/index.cgi?mode=al2&namber=90559
18
+
19
+ 時間がなかったため、こちらのサイトでも同時並行で同じアプリの質問をしていました。
14
20
 
15
21
 
16
22
 

4

修正しました

2019/03/21 16:04

投稿

layla
layla

スコア14

test CHANGED
File without changes
test CHANGED
@@ -12,11 +12,11 @@
12
12
 
13
13
 
14
14
 
15
- ```Form1.vb
16
15
 
17
16
 
18
17
 
19
18
 
19
+ ```
20
20
 
21
21
  Public Class Form1
22
22
 
@@ -180,4 +180,6 @@
180
180
 
181
181
  CsvFileSave(FileName)
182
182
 
183
- ```End Sub
183
+ End Sub
184
+
185
+ ```

3

修正しました

2019/03/20 15:53

投稿

layla
layla

スコア14

test CHANGED
File without changes
test CHANGED
@@ -12,135 +12,101 @@
12
12
 
13
13
 
14
14
 
15
- Form1.vb
15
+ ```Form1.vb
16
+
17
+
16
18
 
17
19
 
18
20
 
19
21
  Public Class Form1
20
22
 
21
- ``` Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click```
23
+ Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
22
24
 
23
- ```Me.Close()```
25
+ Me.Close()
24
26
 
25
- ```End Sub```
27
+ End Sub
28
+
29
+ Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click
26
30
 
27
31
 
28
32
 
29
- ```Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click```
33
+ Dim Height As Double = txtHeight.Text
34
+
35
+ Dim Weight As Double = txtWeight.Text
36
+
37
+ Dim Name As String = txtName.Text
30
38
 
31
39
 
32
40
 
33
- ```Dim Height As Double = txtHeight.Text```
41
+ Dim BMI As Double
34
42
 
43
+ If Height > 0 AndAlso Weight > 0 Then
35
44
 
45
+ lblerror.Text = "" BMI = Weight / ((Height / 100) * (Height / 100))
36
46
 
37
- ```Dim Weight As Double = txtWeight.Text```
38
-
39
-
40
-
41
- ```Dim Name As String = txtName.Text```
42
-
43
-
44
-
45
- ```Dim BMI As Double```
46
-
47
-
48
-
49
- ```If Height > 0 AndAlso Weight > 0 Then
50
-
51
- lblerror.Text = ""```
52
-
53
- ```BMI = Weight / ((Height / 100) * (Height / 100))```
54
-
55
-
56
-
57
- ```txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
47
+ txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
58
48
 
59
49
 
60
50
 
61
51
  '肥満度判定
62
52
 
63
- ```If txtBMI.Text >= 25 Then```
53
+ If txtBMI.Text >= 25 Then
64
54
 
65
- ```lblHimando.Text = "肥満"```
55
+ lblHimando.Text = "肥満" ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
66
56
 
67
- ```ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
57
+ lblHimando.Text = "普通"
68
58
 
69
- lblHimando.Text = "普通"```
59
+ ElseIf txtBMI.Text < 18.5 Then
70
60
 
71
- ```ElseIf txtBMI.Text < 18.5 Then
61
+ lblHimando.Text = "痩せ"
72
62
 
73
- lblHimando.Text = "痩せ"```
74
-
75
- ```End If
63
+ End If
76
64
 
77
65
 
78
66
 
79
67
  '肥満度によって文字の色を変更
80
68
 
81
- ```If lblHimando.Text = "肥満" Then
69
+ If lblHimando.Text = "肥満" Then
82
70
 
83
- lblHimando.ForeColor = Color.Red```
71
+ lblHimando.ForeColor = Color.Red ElseIf lblHimando.Text = "痩せ" Then
84
72
 
85
- ```ElseIf lblHimando.Text = "痩せ" Then
73
+ lblHimando.ForeColor = Color.Blue
86
74
 
75
+ End If
76
+
77
+ '0以下が入力された時にエラーメッセージを表示
78
+
79
+ Else lblerror.Text = "正しい値を入力してください"
80
+
87
- lblHimando.ForeColor = Color.Blue```
81
+ lblHimando.Text = ""
82
+
83
+ End If
84
+
85
+ End Sub
86
+
87
+ Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
88
88
 
89
89
 
90
90
 
91
- ```End If```
91
+ End Sub
92
92
 
93
+ Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click
93
94
 
95
+ If txtBMI.Text = "" Then
94
96
 
95
- '0以下が入力れた時にエラーメッセージを表示
97
+ lblerror.Text = "計算してくだい"
96
98
 
97
- ```Else```
99
+ Else
98
100
 
99
- ```lblerror.Text = "正しい値を入力してください"
101
+ Dim idx As Integer = DataGridView1.Rows.Add() DataGridView1.Rows(idx).Cells(0).Value = idx
100
102
 
101
- lblHimando.Text = ""```
103
+ DataGridView1.Rows(idx).Cells(1).Value = txtName.Text
102
104
 
103
- ```End If```
105
+ DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text
104
106
 
107
+ DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text
105
108
 
106
-
107
- ```End Sub```
108
-
109
-
110
-
111
- ```Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick```
112
-
113
-
114
-
115
- ```End Sub```
116
-
117
-
118
-
119
- ```Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click```
120
-
121
-
122
-
123
- ```If txtBMI.Text = "" Then
124
-
125
- lblerror.Text = "計算してください"```
126
-
127
-
128
-
129
- ```Else```
130
-
131
-
132
-
133
- ```Dim idx As Integer = DataGridView1.Rows.Add()```
134
-
135
- ```DataGridView1.Rows(idx).Cells(0).Value = idx```
136
-
137
- ```DataGridView1.Rows(idx).Cells(1).Value = txtName.Text```
138
-
139
- ```DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text```
140
-
141
- ```DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text```
142
-
143
- ```DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text```
109
+ DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text
144
110
 
145
111
 
146
112
 
@@ -150,70 +116,68 @@
150
116
 
151
117
 
152
118
 
153
- ```End If```
119
+ End If
154
120
 
155
- ```End Sub```
121
+ End Sub
156
122
 
157
123
 
158
124
 
159
- ```Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged```
125
+ Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
160
126
 
161
127
 
162
128
 
163
- ```End Sub```
129
+ End Sub
164
130
 
165
131
 
166
132
 
167
- ```Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load```
133
+ Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
168
134
 
169
135
 
170
136
 
171
- ```End Sub```
137
+ End Sub
172
138
 
173
- ```Private Sub Button2_Click(ByVal sender As System.Object,
139
+ Private Sub Button2_Click(ByVal sender As System.Object,
174
140
 
175
- ByVal e As System.EventArgs) Handles Button2.Click```
141
+ ByVal e As System.EventArgs) Handles Button2.Click
176
142
 
177
143
 
178
144
 
179
- ```CsvFileSave("BMIデータ.csv")```
145
+ CsvFileSave("BMIデータ.csv")
180
146
 
181
- ```End Sub```
147
+ End Sub
148
+
149
+ Dim FileName As String
150
+
151
+ Public Property OpenFileDialog1 As Object
182
152
 
183
153
 
184
154
 
185
- ```Dim FileName As String```
186
-
187
- ```Public Property OpenFileDialog1 As Object```
188
-
189
-
190
-
191
- ```Private Sub CsvFileSave(ByVal SaveFileName As String)```
155
+ Private Sub CsvFileSave(ByVal SaveFileName As String)
192
156
 
193
157
 
194
158
 
195
159
  ' 「名前を付けて保存」ダイアログを使う方法
196
160
 
197
- ```Using sfd As New SaveFileDialog```
161
+ Using sfd As New SaveFileDialog
198
162
 
199
- ```sfd.FileName = "BMIデータ.csv"```
163
+ sfd.FileName = "BMIデータ.csv"
200
164
 
201
- ```sfd.Filter = "CSV(*.csv)|*.csv"```
165
+ sfd.Filter = "CSV(*.csv)|*.csv"
202
166
 
203
- ```sfd.CheckPathExists = True```
167
+ sfd.CheckPathExists = True
204
168
 
205
- ```sfd.OverwritePrompt = True```
169
+ sfd.OverwritePrompt = True
206
170
 
207
- ```If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
171
+ If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
208
172
 
209
- Exit Sub```
173
+ Exit Sub
210
174
 
211
- ```End If```
175
+ End If
212
176
 
213
- ```FileName = sfd.FileName```
177
+ FileName = sfd.FileName
214
178
 
215
- ```End Using```
179
+ End Using
216
180
 
217
- ```CsvFileSave(FileName)```
181
+ CsvFileSave(FileName)
218
182
 
219
- ```End Sub```
183
+ ```End Sub

2

```で囲いました

2019/03/19 15:42

投稿

layla
layla

スコア14

test CHANGED
File without changes
test CHANGED
@@ -18,202 +18,202 @@
18
18
 
19
19
  Public Class Form1
20
20
 
21
- Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
21
+ ``` Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click```
22
-
22
+
23
- Me.Close()
23
+ ```Me.Close()```
24
-
24
+
25
- End Sub
25
+ ```End Sub```
26
-
27
-
28
-
26
+
27
+
28
+
29
- Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click
29
+ ```Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click```
30
-
31
-
32
-
30
+
31
+
32
+
33
- Dim Height As Double = txtHeight.Text
33
+ ```Dim Height As Double = txtHeight.Text```
34
-
35
-
36
-
34
+
35
+
36
+
37
- Dim Weight As Double = txtWeight.Text
37
+ ```Dim Weight As Double = txtWeight.Text```
38
-
39
-
40
-
38
+
39
+
40
+
41
- Dim Name As String = txtName.Text
41
+ ```Dim Name As String = txtName.Text```
42
-
43
-
44
-
42
+
43
+
44
+
45
- Dim BMI As Double
45
+ ```Dim BMI As Double```
46
-
47
-
48
-
46
+
47
+
48
+
49
- If Height > 0 AndAlso Weight > 0 Then
49
+ ```If Height > 0 AndAlso Weight > 0 Then
50
-
50
+
51
- lblerror.Text = ""
51
+ lblerror.Text = ""```
52
-
52
+
53
- BMI = Weight / ((Height / 100) * (Height / 100))
53
+ ```BMI = Weight / ((Height / 100) * (Height / 100))```
54
-
55
-
56
-
54
+
55
+
56
+
57
- txtBMI.Text = BMI.ToString("0.0") '有効数字以下は四捨五入される
57
+ ```txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
58
58
 
59
59
 
60
60
 
61
61
  '肥満度判定
62
62
 
63
- If txtBMI.Text >= 25 Then
63
+ ```If txtBMI.Text >= 25 Then```
64
-
64
+
65
- lblHimando.Text = "肥満"
65
+ ```lblHimando.Text = "肥満"```
66
-
66
+
67
- ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
67
+ ```ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
68
-
68
+
69
- lblHimando.Text = "普通"
69
+ lblHimando.Text = "普通"```
70
-
70
+
71
- ElseIf txtBMI.Text < 18.5 Then
71
+ ```ElseIf txtBMI.Text < 18.5 Then
72
-
72
+
73
- lblHimando.Text = "痩せ"
73
+ lblHimando.Text = "痩せ"```
74
-
74
+
75
- End If
75
+ ```End If
76
76
 
77
77
 
78
78
 
79
79
  '肥満度によって文字の色を変更
80
80
 
81
- If lblHimando.Text = "肥満" Then
81
+ ```If lblHimando.Text = "肥満" Then
82
-
82
+
83
- lblHimando.ForeColor = Color.Red
83
+ lblHimando.ForeColor = Color.Red```
84
-
84
+
85
- ElseIf lblHimando.Text = "痩せ" Then
85
+ ```ElseIf lblHimando.Text = "痩せ" Then
86
-
86
+
87
- lblHimando.ForeColor = Color.Blue
87
+ lblHimando.ForeColor = Color.Blue```
88
-
89
-
90
-
88
+
89
+
90
+
91
- End If
91
+ ```End If```
92
92
 
93
93
 
94
94
 
95
95
  '0以下が入力された時にエラーメッセージを表示
96
96
 
97
- Else
98
-
99
- lblerror.Text = "正しい値を入力してください"
100
-
101
- lblHimando.Text = ""
102
-
103
- End If
104
-
105
-
106
-
107
- End Sub
108
-
109
-
110
-
111
- Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
112
-
113
-
114
-
115
- End Sub
116
-
117
-
118
-
119
- Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click
120
-
121
-
122
-
123
- If txtBMI.Text = "" Then
124
-
125
- lblerror.Text = "計算してください"
126
-
127
-
128
-
129
- Else
130
-
131
-
132
-
133
- Dim idx As Integer = DataGridView1.Rows.Add()
134
-
135
- DataGridView1.Rows(idx).Cells(0).Value = idx
136
-
137
- DataGridView1.Rows(idx).Cells(1).Value = txtName.Text
138
-
139
- DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text
140
-
141
- DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text
142
-
143
- DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
- End If
154
-
155
- End Sub
156
-
157
-
158
-
159
- Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
160
-
161
-
162
-
163
- End Sub
164
-
165
-
166
-
167
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
168
-
169
-
170
-
171
- End Sub
172
-
173
- Private Sub Button2_Click(ByVal sender As System.Object,
174
-
175
- ByVal e As System.EventArgs) Handles Button2.Click
176
-
177
-
178
-
179
- CsvFileSave("BMIデータ.csv")
180
-
181
- End Sub
182
-
183
-
184
-
185
- Dim FileName As String
186
-
187
- Public Property OpenFileDialog1 As Object
188
-
189
-
190
-
191
- Private Sub CsvFileSave(ByVal SaveFileName As String)
97
+ ```Else```
98
+
99
+ ```lblerror.Text = "正しい値を入力してください"
100
+
101
+ lblHimando.Text = ""```
102
+
103
+ ```End If```
104
+
105
+
106
+
107
+ ```End Sub```
108
+
109
+
110
+
111
+ ```Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick```
112
+
113
+
114
+
115
+ ```End Sub```
116
+
117
+
118
+
119
+ ```Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click```
120
+
121
+
122
+
123
+ ```If txtBMI.Text = "" Then
124
+
125
+ lblerror.Text = "計算してください"```
126
+
127
+
128
+
129
+ ```Else```
130
+
131
+
132
+
133
+ ```Dim idx As Integer = DataGridView1.Rows.Add()```
134
+
135
+ ```DataGridView1.Rows(idx).Cells(0).Value = idx```
136
+
137
+ ```DataGridView1.Rows(idx).Cells(1).Value = txtName.Text```
138
+
139
+ ```DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text```
140
+
141
+ ```DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text```
142
+
143
+ ```DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text```
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+ ```End If```
154
+
155
+ ```End Sub```
156
+
157
+
158
+
159
+ ```Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged```
160
+
161
+
162
+
163
+ ```End Sub```
164
+
165
+
166
+
167
+ ```Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load```
168
+
169
+
170
+
171
+ ```End Sub```
172
+
173
+ ```Private Sub Button2_Click(ByVal sender As System.Object,
174
+
175
+ ByVal e As System.EventArgs) Handles Button2.Click```
176
+
177
+
178
+
179
+ ```CsvFileSave("BMIデータ.csv")```
180
+
181
+ ```End Sub```
182
+
183
+
184
+
185
+ ```Dim FileName As String```
186
+
187
+ ```Public Property OpenFileDialog1 As Object```
188
+
189
+
190
+
191
+ ```Private Sub CsvFileSave(ByVal SaveFileName As String)```
192
192
 
193
193
 
194
194
 
195
195
  ' 「名前を付けて保存」ダイアログを使う方法
196
196
 
197
- Using sfd As New SaveFileDialog
197
+ ```Using sfd As New SaveFileDialog```
198
-
198
+
199
- sfd.FileName = "BMIデータ.csv"
199
+ ```sfd.FileName = "BMIデータ.csv"```
200
-
200
+
201
- sfd.Filter = "CSV(*.csv)|*.csv"
201
+ ```sfd.Filter = "CSV(*.csv)|*.csv"```
202
-
202
+
203
- sfd.CheckPathExists = True
203
+ ```sfd.CheckPathExists = True```
204
-
204
+
205
- sfd.OverwritePrompt = True
205
+ ```sfd.OverwritePrompt = True```
206
-
206
+
207
- If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
207
+ ```If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
208
-
208
+
209
- Exit Sub
209
+ Exit Sub```
210
-
210
+
211
- End If
211
+ ```End If```
212
-
212
+
213
- FileName = sfd.FileName
213
+ ```FileName = sfd.FileName```
214
-
214
+
215
- End Using
215
+ ```End Using```
216
-
216
+
217
- CsvFileSave(FileName)
217
+ ```CsvFileSave(FileName)```
218
-
218
+
219
- End Sub
219
+ ```End Sub```

1

特になし

2019/03/19 15:28

投稿

layla
layla

スコア14

test CHANGED
File without changes
test CHANGED
@@ -217,13 +217,3 @@
217
217
  CsvFileSave(FileName)
218
218
 
219
219
  End Sub
220
-
221
- ### 試したこと
222
-
223
-
224
-
225
- ここに問題に対して試したことを記載してください。
226
-
227
-
228
-
229
- ### 補足情報(FW/ツールのバージョンなど)