这是我的代码(所有内容都预先声明在整个表单的类中使用):
Private Sub Pokedex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
IntPokemonCounter = 0
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("TotalPokemonNames.txt")
While (IntPokemonCounter < 51)
PokémonName(IntPokemonCounter) = fileReader.ReadLine()
listPokemon.Items.Add(PokémonName(IntPokemonCounter))
ComboBox1.Items.Add(PokémonNumber(IntPokemonCounter) + "" + PokémonName(IntPokemonCounter))
'MsgBox("The " & IntPokemonCounter + 1 & "th pokemon is " & PokémonName(IntPokemonCounter))
IntPokemonCounter += 1
End While
IntPokemonCounter = 0
While (IntPokemonCounter < 51)
PokémonNumber(IntPokemonCounter) = IntPokemonCounter + 1
If PokémonNumber.Length = 1 Then
PokémonNumber(IntPokemonCounter) = "00" + (IntPokemonCounter + 1)
ElseIf PokémonNumber.Length = 2 Then
PokémonNumber(IntPokemonCounter) = "0" + (IntPokemonCounter + 1)
End If
IntPokemonCounter += 1
End While
IntPokemonCounter = 0
While (IntPokemonCounter < 51)
PokemonPics(IntPokemonCounter < 51) = My.Resources.(PokémonName(IntPokemonCounter) &".png")
listPokemon.Items.Add(PokémonNumber(IntPokemonCounter) + PokémonName(IntPokemonCounter))
'MsgBox("The " & IntPokemonCounter + 1 & "th pokemon is " & PokémonName(IntPokemonCounter))
IntPokemonCounter += 1
End While
End Sub
我遇到的问题是无法从.txt文件中加载的名称中选择一张图片。图片被加载到资源中,我不想为每个口袋妖怪制作151 if语句,这主要是基于大数据。 当我这样放置时,它会显示“Identifier expected”,而不是接受此行中使用的变量
PokemonPics(IntPokemonCounter < 51) = My.Resources.(PokémonName(IntPokemonCounter) &".png")
最初我打算将图片直接加载到图片框中,但我希望阵列可以解决问题,但事实并非如此。这是我的最终项目,我在Visual Basic 2008快递版中重新创建了口袋妖怪Red。非常感谢您提供的任何帮助。