Lord Lord - 7 months ago 22
Vb.net Question

Need More Help Shortening Repetitive VB Code

I've reached another annoying roadblock in my simulator.

So, my simulator has two userforms that transfer information back and forth between each other (one is MainForm, and the other is CreatureFinder). When one of the deck slot buttons on MainForm is pushed (all 20 of which correspond to a creature in either yours or the enemy's deck), it opens CreatureFinder so that you can choose which creature goes in the slot (and it also lets you edit certain parameters, like the creature's level). The code goes like this (shortened, for simplicity's sake):

If CreatureNumberLabel.Text = "1" Then
MainForm.YourCreature1Skill1Label.Text = Skill1Label.Text
MainForm.YourCreature1Skill2Label.Text = Skill2Label.Text
MainForm.YourCreature1Skill3Label.Text = Skill3Label.Text
End If

What I want to do is completely remove the If Then statement, and be able to change "YourCreature1" to "YourCreature" & whatever value CreatureNumberLabel.Text is set to. This will VASTLY shorten my code, but I can't figure out how to accomplish this.


Should it be VBA, you can skip the

If CreatureNumberLabel.Text = "1" Then

And just type:

MainForm.Controls("YourCreature" & CreatureNumberLabel.Text & "Skill1Label").Text = Skill1Label.Text

And so on with Skill2Label.Text, Skill3Label.Text, etc...