我正在使用Visual Studio 2010 Express,对于我的计算机科学课,我需要让VB.NET程序的一部分将标题为id
的变量中保存的单个整数写入文本文件中的新行循环经过的时间。到目前为止,我已使用StreamWriter
和" InsertNameHere" .WriteLine(id)完成了文件创建。但是,我的id
变量应该根据我的表单上特定图片框中的图像而改变。为了尝试实现这一点,我使用Dim pic(14) As Image
创建了一个数组,然后我将每个图片框中的图像设置为存储在数组每个部分中的图像。
我的代码:
Tile1a.Image = pic(0)
Tile1b.Image = pic(1)
Tile1c.Image = pic(2)
Tile1d.Image = pic(3)
Tile1e.Image = pic(4)
Tile1f.Image = pic(5)
Tile1g.Image = pic(6)
Tile1h.Image = pic(7)
Tile1i.Image = pic(8)
Tile1j.Image = pic(9)
Tile1k.Image = pic(10)
Tile1l.Image = pic(11)
Tile1m.Image = pic(12)
Tile1n.Image = pic(13)
Tile1o.Image = pic(14)
之后,我使用for循环遍历数组的内容并检查图像的名称。根据图像," id"变量被赋予不同的值,然后使用streamwriter打开文件并写入" id"的值。它。 Dim fs As FileStream = File.Create(FilePath) fs.Close() Dim writer = New StreamWriter(FilePath)
For terrainimage As Integer = 0 To 44
If pic(num) Is My.Resources.Tile_Grass Then
id = 0
ElseIf pic(num) Is My.Resources.Tile_Sand Then
id = 1
ElseIf pic(num) Is My.Resources.Tile_Water Then
id = 2
ElseIf pic(num) Is My.Resources.Tile_Pond_Corner_BLeft Then
id = 3
ElseIf pic(num) Is My.Resources.Tile_Pond_Corner_BRight Then
id = 4
ElseIf pic(num) Is My.Resources.Tile_Pond_Corner_TLeft Then
id = 5
ElseIf pic(num) Is My.Resources.Tile_Pond_Corner_TRight Then
id = 6
ElseIf pic(num) Is My.Resources.Tile_Pond_Down Then
id = 7
ElseIf pic(num) Is My.Resources.Tile_Pond_Up Then
id = 8
ElseIf pic(num) Is My.Resources.Tile_Pond_Left Then
id = 9
ElseIf pic(num) Is My.Resources.Tile_Pond_Right Then
id = 10
ElseIf pic(num) Is My.Resources.Tile_River_Horizontal Then
id = 11
ElseIf pic(num) Is My.Resources.Tile_River_Vertical Then
id = 12
ElseIf pic(num) Is My.Resources.Tile_RiverEntrance_Down Then
id = 13
ElseIf pic(num) Is My.Resources.Tile_RiverEntrance_Up Then
id = 14
ElseIf pic(num) Is My.Resources.Tile_RiverEntrance_Left Then
id = 15
ElseIf pic(num) Is My.Resources.Tile_RiverEntrance_Right Then
id = 16
ElseIf pic(num) Is My.Resources.Tile_Beach_Up Then
id = 17
ElseIf pic(num) Is My.Resources.Tile_Beach_Down Then
id = 18
ElseIf pic(num) Is My.Resources.Tile_Beach_Left Then
id = 19
ElseIf pic(num) Is My.Resources.Tile_Beach_Right Then
id = 20
ElseIf pic(num) Is My.Resources.Tile_Beach_BL_CornerDot Then
id = 21
ElseIf pic(num) Is My.Resources.Tile_Beach_BR_CornerDot Then
id = 22
ElseIf pic(num) Is My.Resources.Tile_Beach_TL_CornerDot Then
id = 23
ElseIf pic(num) Is My.Resources.Tile_Beach_TR_CornerDot Then
id = 24
ElseIf pic(num) Is My.Resources.Tile_Beach_TL_DualCDot Then
id = 25
ElseIf pic(num) Is My.Resources.Tile_Beach_TR_DualCDot Then
id = 26
ElseIf pic(num) Is My.Resources.Tile_Beach_Corner_BottomLeft Then
id = 27
ElseIf pic(num) Is My.Resources.Tile_Beach_Corner_BottomRight Then
id = 28
ElseIf pic(num) Is My.Resources.Tile_Beach_Corner_TopLeft Then
id = 29
ElseIf pic(num) Is My.Resources.Tile_Beach_Corner_TopRight Then
id = 30
End If
writer.WriteLine(id)
num += 1
Next
writer.Close()
任何帮助表示赞赏!在我放弃之前,我找了一个半小时左右的答案,最后决定自问!如果您需要任何进一步的解释或者希望看到我的所有代码都没有问题,我是VB的新手,所以请不要太苛刻!