Jump to content

Visual basic help

Deathadder1999

I am far from an expert and barely a novice, but please stick through my lack of knowledge  :P.
 
I'm not sure of this is possible in visual basic, but essentially i need to turn this:
 

If Value = 1 Then   picPostion1.Image = picPlayer.ImageElse If Value = 2 Then picPostion2.Image = picPlayer.ImageElse If Value = 3 Then  picPostion3.Image = picPlayer.ImageEnd If 

 
Into something like this:
 

 x = ValuepicPostion(x).Image = picPlayer.Image 

 
If this is possible!, Then
plz teach me master!
 
else
Alternative help is welcome
End If
 
:D

Link to comment
Share on other sites

Link to post
Share on other sites

The first thing that you need to do is to sort your post out, read this and see if you can find out what you didn't do:

 

PZ20Fqo.png

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

 [...]

 

If Value = 1 Then

   picPostion1.Image = picPlayer.Image

Else If Value = 2 Then

 picPostion2.Image = picPlayer.Image

Else If Value = 3 Then

  picPostion3.Image = picPlayer.Image

....

....( This repeats alot in my program, hence why i wish to shorten it)

End If

 

Into something like this:

 

x = Value

picPostion(x).Image = picPlayer.Image

 

If this is possible!, Then

plz teach me master!

 

else

Alternative help is welcome

End If

 

:D

 

Uhm I guess what you are looking for is an Array or a List<T> .

Think of it like a box. Rather than storing each value in a named variable on it's own you could store every picposition in a series of values wich are accessible via an indexer.

 

That way you can access it via an Index in square Brackets.

Example with using List<T> (spoken: List Of T(ype)):

Dim myPicPositions As New List(Of myPicPositionType)()myPicPositions.Add(picPosition1)myPicPositions.Add(picPosition2)' etc... 'Dim myVar as IntegermyVar = 42picPlayer.Image = picPosition(myVar - 1).Image

I am pretty certain that indexing in VB starts with 0 instead of 1 aswell, that's why ther's the -1 part.

If I am wrong about that one, just use your myVar directly.

Link to comment
Share on other sites

Link to post
Share on other sites

What version of Visual Basic is this?

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to comment
Share on other sites

Link to post
Share on other sites

Sadly I don't think what you want to do is possible, the closest you can get to this is a switch case.

Select Case Value    Case 1        picPostion1.Image = picPlayer.Image        Exit Select    Case 2        picPostion2.Image = picPlayer.Image        Exit Select    Case 3        picPostion3.Image = picPlayer.Image        Exit SelectEnd Select 
It's a tad bit better than a if else tree but sadly I don't think you can do what you want :( Sorry if I am wrong

life();

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×