使用下面的代码我正在尝试制作一个将图像名称发送到.TXT文件的编译器,然后可以由另一个程序读取,以制作一个世界地图(就像在旧的NES Zelda游戏中一样)。问题是在第16行(15,如果你不计算空格)当程序到达那个发送图像名称的位时会出现问题,它会返回此错误:
“运营商”&'没有为字符串“Me.BackgroundImage = WindowsAppl”定义并键入“Bitmap”。“
如何解决此问题?因为好像编译器在将代码传入文件之前正在读取代码。
谢谢! Liam Hackett
'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")
答案 0 :(得分:0)
显然MapLayout(MLN).Image
是Bitmap
,位图没有覆盖&
- 运算符(C#中的+
)。所以你不能用这种方式连接字符串:
Dim doesNotCompile = "Path of this Bitmap: " & bitmap
我假设您想要连接图像路径。但是Bitmap不会在某处存储它的路径。所以你必须自己将它保存在你的班级或方法中。