🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

VB functions you define yourself

Started by
3 comments, last by Chalma 22 years, 6 months ago
Private Sub Form_Load() cboCharRace.AddItem "Human", 0 cboCharRace.AddItem "Half-Elf", 1 cboCharRace.AddItem "Elf", 2 cboCharRace.AddItem "Dwarf", 3 cboCharType.AddItem "Hunter", 0 cboCharType.AddItem "Warrior", 1 cboCharType.AddItem "Wizard", 2 cboCharType.AddItem "Priest", 3 End Sub Ok I''m a real nit picker for neat code I don''t like this at all. Is there any way I can make a function that loads in the on on load so that it does this I can do this in C but not in VB or maybe I''m doing it wrong. an example of what I would like to do is......
quote: Private Sub Form_Load() LoadCharRace() LoadCharType() End Sub /////////////////////////////////////////////////// Private Function LoadCharRace() cboCharRace.AddItem "Human", 0 cboCharRace.AddItem "Half-Elf", 1 cboCharRace.AddItem "Elf", 2 cboCharRace.AddItem "Dwarf", 3 End Function ///////////////////////////////////////////////// Private Function LoadCharType() cboCharType.AddItem "Hunter", 0 cboCharType.AddItem "Warrior", 1 cboCharType.AddItem "Wizard", 2 cboCharType.AddItem "Priest", 3 End Function
VB just will not let me do this. It wants me to make a return type but I don''t want a friggin'' return type this is easibly doable in C++ and I really want to get better with VB so any help is appreciated. I know the code is not right the second way that is THEORETICAL </b> code, its how I would picture it looking. THanks -Chalma/Pspiro
-Chalma/Pspiro
Advertisement
If you dont want it to return a type, why not just make it a Sub? That way you wont have to return a value.

Invader X
Invader''s Realm
Yes, you would use subs. Subs are basically sements of code that don''t return a value. You would do something like this.

Private Sub Form_Load()
Call DoStuff
End Sub

Sub DoStuff()
Blah.Additem "Whatever."
End Sub

LOL that was such a simple solution. Thank you guys very much. As you can tell I am new to VB =0)



-Chalma/Pspiro
-Chalma/Pspiro
If you are just hardcoding those items in, then you might as well do it at design time.

Select the list box, go to its properties and find the List property. Click the down arrow, then type the first item, then press Ctrl+Enter, second item ctrl+enter etc until you type the last, when you just press enter.

Trying is the first step towards failure.
Trying is the first step towards failure.

This topic is closed to new replies.

Advertisement