473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Generelized Code

How same functionality can be given to mulitiple forms in a VB.Net
project?
e.g. Suppose on each form, toolbar is present. If we click on New
button then Add, Edit button gets disabled and Save, Cancel button is
enabled. If we click on Save button, records gets saved.
In short how the generelized code can be written?

Feb 22 '06 #1
3 1157
Anil,

If it's something that appears on multiple forms, I'd either create a User
Control composed of the constituent controls and plonk it on each form
required, or I'd create the toolbar on a 'master' form and use visual
inheritance to have it appear on your child forms.

HTH,

Adam
--
Adam May
Sydney, Australia
MCSD.Net
"Anil" wrote:
How same functionality can be given to mulitiple forms in a VB.Net
project?
e.g. Suppose on each form, toolbar is present. If we click on New
button then Add, Edit button gets disabled and Save, Cancel button is
enabled. If we click on Save button, records gets saved.
In short how the generelized code can be written?

Feb 22 '06 #2
Thank you sir, What idea U have gievn will be definitely helpful for
me.

But my second problem is how (outline) modules can be written to
provide functionality e.g. saving,updating of records throu various
forms.

I tried to implement shared methods in modules to access those without
instance creation. Then pass argument to recognize which form is
calling that shared method. But I feel its not the right way.

So please give me proper direction.
once aggain Thanks a lot sir.

Feb 22 '06 #3
Hi Anil,

Let me see if I understand you correctly - you're asking how top create a
method that can be used across multiple forms?

If the forms are all similar, I'd use visual inheritence. For this example,
I've created three forms - one parent form (ParentForm.vb) and two inheriting
child forms (ChildForm1.vb and ChildForm2.vb).

The parent form has the data save method (SaveData). This can be called from
any of the three forms, but for ease of use, I've created a button on the
parent form that calls the code. This would then be inherited by the children
forms.

Here's the code:

ParentForm.vb
-----------------
Public Class ParentForm
Inherits System.Windows.Forms.Form

' Removed Windows generated code for brevity

Protected Sub SaveData()
'Save your data here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SaveData()
End Sub
End Class

ChildForm1.vb:
-----------------
Public Class ChildForm1
Inherits WindowsApplication2.ParentForm

' Removed Windows generated code for brevity

End Class

ChildForm2.vb:
-----------------
Public Class ChildForm2
Inherits WindowsApplication2.ParentForm

' Removed Windows generated code for brevity
End Class

As you can see, there's no code in either of the children forms to do the
save data - that's all inherited from the parent (base) class. If you need
need to call the parent's SaveData method from the children, it's still
possible by using MyBase.SaveData().

Hope this example helps you along your way.

Adam

--
Adam May
Sydney, Australia
MCSD.Net
"Anil" wrote:
Thank you sir, What idea U have gievn will be definitely helpful for
me.

But my second problem is how (outline) modules can be written to
provide functionality e.g. saving,updating of records throu various
forms.

I tried to implement shared methods in modules to access those without
instance creation. Then pass argument to recognize which form is
calling that shared method. But I feel its not the right way.

So please give me proper direction.
once aggain Thanks a lot sir.

Feb 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.