View previous topic :: View next topic |
Author |
Message |
xXx123 Expert Cheater
Reputation: 0
Joined: 27 Sep 2007 Posts: 118
|
Posted: Thu Dec 06, 2007 6:36 am Post subject: vb6 question |
|
|
yes i know i ask alot of questions but i only want to expand my knolage in vb XD
so this time my question is: how to input codes in the combo box
for example: i want to put 2 types of weapons in some some game and when i pick 1 of the weapons and press command1 it will change to the weapon i selected?
soooo what is the code? thank you XD
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Dec 06, 2007 7:23 am Post subject: Re: vb6 question |
|
|
xXx123 wrote: | yes i know i ask alot of questions but i only want to expand my knolage in vb XD
so this time my question is: how to input codes in the combo box
for example: i want to put 2 types of weapons in some some game and when i pick 1 of the weapons and press command1 it will change to the weapon i selected?
soooo what is the code? thank you XD |
Your code will be in the Command1_Click sub. You will want to obtain the index of the currently selected item in the listbox. For example, tossing together something real quick:
- Create a new project.
- Add 1 button and 1 combo box to it. (Leave names default for now.)
To start, we want to fill the combo with shit, lets do 5 items for now. So in Form_Load lets do:
Code: | Private Sub Form_Load()
Combo1.AddItem "Item 1"
Combo1.AddItem "Item 2"
Combo1.AddItem "Item 3"
Combo1.AddItem "Item 4"
Combo1.AddItem "Item 5"
Combo1.ListIndex = 0
End Sub |
This will add 5 items to the combo box, then select the first one as the default. Now we want to add code in the Command1_Click to obtain the currently selected item. In this example we will just make a messagebox return the value and display it when you click the button:
Code: | Private Sub Command1_Click()
MsgBox Combo1.List(Combo1.ListIndex)
End Sub |
So to explain a little.. Combo1.ListIndex holds the current item index, remember this number STARTS with 0. That means:
Item 1 = 0
Item 2 = 1
Item 3 = 2
And so on. Then Combo1.List(INDEX_HERE) obtains the given items text.
Then you would just need to alter the Command1 to do what you need with the item instead of a message box.
Good luck.
_________________
- Retired. |
|
Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Thu Dec 06, 2007 2:26 pm Post subject: |
|
|
@Wiccaan - I don't think he knows how to change that, since I gave him a basic code and he couldn't change it to fit so yea
Firstly edit the combobox you made and add the 2 items to it (can be done by properties > list or combo1.additem as Wiccaan
There are 2 ways I learned on some forum to do this, one way is to get the index and use that, or just simply use a If command to see if the combobox is on a current item with the correct text
For the index thing, try and look at Wiccaan's (No point in explaining it, Wiccaan already did it)
So pretend your combo list is:
weapon1
weapon2
So for your button:
Code: | If combo1.Text = "weapon1" then
Call shockwaveflash1.setvariable(whatever)
End If
If combo1.text = "weapon2" then
Call shockwaveflash1.setvariable(whatever)
End If |
You can use either method, I prefer the index one though
_________________
|
|
Back to top |
|
 |
xXx123 Expert Cheater
Reputation: 0
Joined: 27 Sep 2007 Posts: 118
|
Posted: Thu Dec 06, 2007 3:23 pm Post subject: |
|
|
wow thanks! you really helped me guys XD
trust me there will be more question
|
|
Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Thu Dec 06, 2007 3:36 pm Post subject: |
|
|
Try searching before you post, because these answers are out there, you have to search on what you need to find in general such as "How to use current combo box choice" or something
_________________
|
|
Back to top |
|
 |
xXx123 Expert Cheater
Reputation: 0
Joined: 27 Sep 2007 Posts: 118
|
Posted: Thu Dec 06, 2007 3:58 pm Post subject: |
|
|
i do that all the time... but still i cant find what i need...
|
|
Back to top |
|
 |
|