adding a module to a project
hi i am new to VB programming.
i want to add my own module to my project cud please anybody tell me how to define and declare ,call a module in VB
Well... There are 2 types of modules . The first one ( .bas extension) you simply just add to you r project. All members of this modules is available to all other forms, classes of your projects unless you have declared them as private . You can also pass variables byref directly in and out of this module, without haveing to pass the pointer by value and then use RtlMoveMemory (risking memory leaks etc) . So it is the easiest module to start working with. But also the most powerful one, so not to be overused.
The other type you add by choosing , Add\Class Module. The .cls file . This is a module i guess is trying to simulate the class type of c++ or sth, but lacking inheritance. Anyway. Within this you cannot have public constants or arrays or declare statements. U can have public variables tho . While you if u wish , may actually run your whole program from the other module. Creating a default window process and similar things, the class module is quite restrictive. I assume it is more used for 'gathering' stuff, in the spirit of classes . It is often used to gather similar functions and properties that goes along. Like bancaccount. Properties like interest rents, stock market return etc may be gathered along with some functions to calculate account value after interests and so on .
So if u want to call these functions in the .cls from you main form , you must first have declared them as Public from within the class module. In contrast to the .bas module, wich implicit consider all its functions as public unless you declare them private.
You must also initiate the class from within your main form. Lets say u have called it cBanking. Then u initiate it by declaring a type like.. "Dim myBanking as new cBanking"
if u use the new keyword you will not have to explicitly start a new instance each time you call a function from cBanking. You may also well use "Dim myBanking as cBanking" , but when later on calling the "calculate_interest() " function wich belongs to cBanking, u must use the new kword. If you go by the first way, you may start using the functions , or setting , getting values from the class module like you call other functions. Expect you must remenber the declared type .
dim fortune as double
fortune=myBanking.caculate_interest + myBanking.totalvalue
Theres other differences too between the two type of modules. But this may give u a start idea. Another thing you may want to look a bit into sooner, is the raiseevent function that is internalized in the .cls module. (you can use it from .bas too but must use the SetEvent Win32 api then )
By Gary Nelson in forum .NET
Last Post: 10-01-2003, 12:00 AM
By Robert G in forum .NET
Last Post: 02-08-2001, 02:38 PM
By Todd B - Agendum Software in forum vb.announcements
Last Post: 09-13-2000, 10:18 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center