Jump to content
  • Advertisement

Archived

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

Wizzy

VERY simple VB question

This topic is 5472 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

i''ll look in help too - but i thought if i asked here people might also let me know any tips, or do not''s... ok - very simple i have a large string of code for a command - and i have more than one form using it - but i don''t want to have to have it in each form what sort of thing do i add to my "project" window - so that i can make it a class or whatever it''s called i believe i can make a "class" or "object" or something in the project window that just holds that code, and then call it in the form with just the name, yes? for instance i have 10 forms needing a simple command, say x=x+y(2-3)/5+2 can''t i make it a class or object or something - and just make the form call it by name - such as "Special Math Thing"?

Share this post


Link to post
Share on other sites
Advertisement
What you need is a module. Add a module to your project (Project -> Add Module). Put your code in the module, in the form of a global (use the Public keyword) function or procedure. Now, you can call that function from any form you have, either explicitly or not, like so:
modFooBar.MeaningOfLife(42)
MeaningOfLife(42)
You can create classes and derive objects using VB, but it doesn't sound like you need it...

[Insert witty signature here]

[edited by - iNsAn1tY on October 23, 2003 11:31:40 AM]

Share this post


Link to post
Share on other sites
ok i figured it out - kind of

i made a Module - then inside it put "Public Function LoadGrid()"

then put all the code in - and it works (Call LoadGrid)

but two quick questions

-is that the best way to do it?
-the (), that''s for variables right?

so if i have it doing a math function (which it''s not - but it''s the easiest way to show it) - then i could do something like

Public Function LoadGrid(x,y)

v=x+y

end function

then in the form do "Call LoadGrid(2,3) - yes?

and the v is so that it can return some sort of answer... to another variable, so i can see it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What you need is a module. Add a module to your project (Project -> Add Module). Put your code in the module, in the form of a global (use the Public keyword) function or procedure. Now, you can call that function from any form you have, either explicitly or not, like so:
modFooBar.MeaningOfLife(42)
MeaningOfLife(42)
You can create classes and derive objects using VB, but it doesn''t sound like you need it...

Share this post


Link to post
Share on other sites
quote:
Original post by iNsAn1tY
What you need is a module. Add a module to your project (Project -> Add Module). Put your code in the module, in the form of a global (use the Public keyword) function or procedure. Now, you can call that function from any form you have, either explicitly or not, like so:
modFooBar.MeaningOfLife(42)
MeaningOfLife(42)
. You can create classes and derive objects using VB, but it doesn''t sound like you need it...


[Insert witty signature here]



thanks. i wasn''t exactly sure what the class was...

i pretty much just need the function to do some simple searching through a very large array, and putting the results into a grid i just didn''t want to have a ton of code in each form.

Share this post


Link to post
Share on other sites
Yeah, that''s exactly how to do it (slipped with the browser button above, my bad)...

[Insert witty signature here]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!