Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Chalma

VB functions you define yourself

This topic is 6018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 [u]THEORETICAL [/u] code, its how I would picture it looking. THanks -Chalma/Pspiro

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


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



-Chalma/Pspiro

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!