0

这是我的代码(所有内容都预先声明用于整个表单的类):

 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 语句,这主要是基于大数据。当我这样放置它时,它会显示“预期标识符”,而不是接受此行中使用的变量

PokemonPics(IntPokemonCounter < 51) = My.Resources.(PokémonName(IntPokemonCounter) &".png")

最初我打算将图片直接加载到图片框,但我希望数组可以解决问题,但它没有。这是我的最终项目,我正在 Visual basic 2008 速成版中重新创建 pokemon Red。非常感谢您提供的任何帮助。

4

0 回答 0