使用下面的代码,我正在尝试制作一个将图像名称发送到 .TXT 文件的编译器,然后可以稍后由另一个程序读取该文件以制作世界地图(就像在旧的 NES Zelda 游戏中一样)。问题出在第 16 行(如果不计算空格,则为 15)当程序到达发送图像名称的那个位时会出现问题,它会返回此错误:
“未为字符串“Me.BackgroundImage = WindowsAppl”定义运算符 '&' 并键入 'Bitmap'。”
我该如何解决这个问题?似乎编译器在将代码写入文件之前正在读取代码。
谢谢!利亚姆·哈克特
'Saves the map into a .TXT file
Dim mydocpath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sb As New StringBuilder()
'Used to manage compiler
Dim MLN As Byte
Dim FC As Boolean = True
'Two "FOR" loops one for the Horizontal axis for the map and one for the Verticle axis
For x = 1 To 10
For y = 1 To 10
'On first loop
If FC = True Then
sb.AppendLine("If WorldHorizontal = " & x & "And WorldVerticle = " & y & " Then")
sb.AppendLine("")
MLN = MLN + 1
sb.AppendLine("Me.BackgroundImage = WindowsApplication1.My.Resources.Resources." & MapLayout(MLN).Image)
sb.AppendLine("")
FC = False
'Everyother loop
Else
sb.AppendLine("ElseIf WorldHorizontal = " & x & "And WorldVerticle = " & y & " Then")
sb.AppendLine("")
MLN = MLN + 1
sb.AppendLine("Me.BackgroundImage = WindowsApplication1.My.Resources.Resources." & MapLayout(MLN).Image)
sb.AppendLine("")
End If
Next
Next
' Saves file in MyDocuments
Using outfile As New StreamWriter(mydocpath & "\" & txtbFileName.Text & ".txt")
outfile.Write(sb.ToString())
End Using
MsgBox("Compile Finished")