带有字符串的VB.net基本错误<-&燃气轮机;字符转换
我正在编写一个小游戏来练习自己,但我犯了一个无法纠正的错误:S。这是一个悬而未决的游戏的开始。(不知道它的英文名称是否正确:)我需要从一个文件中提取一个单词,每行1个,让玩家用有限的次数来猜这个单词 我认为我的错误与字符串/字符比较和操作有关,或者与我在文本标签中写的内容有关。我试着在互联网上找到一些已经解决的教程或问题,但没有一个是真的和这个一样的…:( 我多次更改变量的类型,逐行阅读调试器,但我从未发现错误所在:S如果你擅长VB,请帮助我修复:O(你也可以给出评论/改进) Thx,火焰 代码:带有字符串的VB.net基本错误<-&燃气轮机;字符转换,vb.net,string,variables,char,type-conversion,Vb.net,String,Variables,Char,Type Conversion,我正在编写一个小游戏来练习自己,但我犯了一个无法纠正的错误:S。这是一个悬而未决的游戏的开始。(不知道它的英文名称是否正确:)我需要从一个文件中提取一个单词,每行1个,让玩家用有限的次数来猜这个单词 我认为我的错误与字符串/字符比较和操作有关,或者与我在文本标签中写的内容有关。我试着在互联网上找到一些已经解决的教程或问题,但没有一个是真的和这个一样的…:( 我多次更改变量的类型,逐行阅读调试器,但我从未发现错误所在:S如果你擅长VB,请帮助我修复:O(你也可以给出评论/改进) Thx,火焰 代码
Mot.LettreDecouverte
可以是Nothing
,即未初始化,因为您没有为其设置任何值
这可能会导致错误发生在Mot.LettreDecouverte(j)=Mot.MotSecret(j)
行中,如果Mot.LettreDecouverte(j).Equals(“”),则也会发生在代码的行中
更改按钮单击事件处理程序代码,如下所示:
i = i + 1
ActiveControl.Visible = False
PictureBox1.Image = ImageList1.Images(i - 1)
Dim j As Integer = 0
If Mot.LettreDecouverte Is Nothing OrElse Mot.LettreDecouverte.Length < Mot.MotSecret.Length Then
Mot.LettreDecouverte = Space(Mot.MotSecret.Length) '* initiate it by enough number of space chars
End If
For j = 0 To Mot.MotSecret.Length - 1
If ActiveControl.Text = Mot.MotSecret(j) Then
Mot.LettreDecouverte(j) = Mot.MotSecret(j)
End If
Next j
Label1.Text = ""
For j = 0 To Mot.MotSecret.Length - 1
Label1.Text = Label1.Text + " "
If Mot.LettreDecouverte(j).Equals(" "c) Then '*Note: i use space char, not empty string
Label1.Text = Label1.Text + "_"
Else
Label1.Text = Label1.Text + Mot.LettreDecouverte(j)
End If
Next j
i=i+1
ActiveControl.Visible=False
PictureBox1.Image=ImageList1.Images(i-1)
尺寸j为整数=0
如果Mot.LettreDecouverte为空或lse Mot.LettreDecouverte.Length
请注意,Mot.LettreDecouverte(j)
的值始终是一个字符,当您在Mot.LettreDeciouverte(j).Equals(“”)
中键入时,字符不能是空字符串。我使用一个空格字符数组启动LettreDeciouverte,以便我们可以对照检查其元素。”c
char.实际的错误信息和行号是什么?为什么要比较基于char数组而不是字符串的单词?法语命名使理解您的算法有点困难。Ce Pas Grave但mon Fracais Ce Pas Esceptionel。如果您能将完整的代码发布在github或gist.github.com上,我愿意接受他们说错误在这一行:如果Mot.LettreDecouverte(j).Equals(“”),那么结构中的MotSecret()
应该是字符串而不是字符。。。
i = i + 1
ActiveControl.Visible = False
PictureBox1.Image = ImageList1.Images(i - 1)
Dim j As Integer = 0
If Mot.LettreDecouverte Is Nothing OrElse Mot.LettreDecouverte.Length < Mot.MotSecret.Length Then
Mot.LettreDecouverte = Space(Mot.MotSecret.Length) '* initiate it by enough number of space chars
End If
For j = 0 To Mot.MotSecret.Length - 1
If ActiveControl.Text = Mot.MotSecret(j) Then
Mot.LettreDecouverte(j) = Mot.MotSecret(j)
End If
Next j
Label1.Text = ""
For j = 0 To Mot.MotSecret.Length - 1
Label1.Text = Label1.Text + " "
If Mot.LettreDecouverte(j).Equals(" "c) Then '*Note: i use space char, not empty string
Label1.Text = Label1.Text + "_"
Else
Label1.Text = Label1.Text + Mot.LettreDecouverte(j)
End If
Next j