Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 29th, 2008, 07:46 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default Reuse Forms and part s of code

Hi all,
I am learning to program in Visual basic net 2005 after retirement as a hobby! As a start I am trying to write a maths, spelling and find words program all from a main part menu driven form to my grandson who is six.
After writing the maths part, I find I can reuse the same form with little modification and also reuse some functions in the other part ie spelling.
1)Is there any way I can reuse the form and modify slightly for use in the other part.
2) Will I be able to reuse the same code for the functions and how.
I would be greatful for any help and suggestions.
Thanks in advance.
thillai

Reply With Quote
  #2 (permalink)  
Old February 29th, 2008, 08:36 AM
Friend of Wrox
 
Join Date: Oct 2007
Location: , , .
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

It is very great to know that you are learning programming, otherwise people even hesitate to learn simple computer operation at your age.
On form you can use radio buttons,combo box & check box for choices.
for some repetitive code you can define one function which you can call from any form in your application. I think books will be more helpful in your case rather than any forum, If you find any problem then do post your problem.
Best of luck.


urt

Help yourself by helping someone.
Reply With Quote
  #3 (permalink)  
Old February 29th, 2008, 10:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Ya Thillai, Upendra said it there. It really is heartening to see what you are doing for your grandson, let me warn you though, you might soon find your grandson egging you on to learn game programming :). There are many ways to approach this task, you can define a class with all the logic in it and access its functions from the forms, dynamically add/remove controls, inhering your forms from ones you have already designed, all depends on how much programming you wanna do and how much you wanna learn. Do write back and let us know which approach you are taking, and if you are facing problems.

Regards
Ankur
Reply With Quote
  #4 (permalink)  
Old March 2nd, 2008, 01:26 PM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi all
Thanks for the replies and special thanks to Upendra and Ankur for your sentiments, I am happy to learn any amount as I am interested in programming and to keep myself occupied at the same time. So i thought this simple project to write so i can learn all along.
The form i have already made is one where there are textboxes, labels and buttons. Information on labels and textbox is for information to the user. The text in the textbox will change from one form to the other. Information collected from other textbox will also change from form to the other. I just thought without redrawing another similar form I may be able to reuse one with changes. So was my question.
Also some codes in functions like checking for validity of textbox entry can be reused, so was my second question.
Thanks for the replies but i do not seem to grasp what you have said there, may be my age! Can you please be more specific and help me. I am not able to grasp the class definition so far.
Thanks for further help and if you like i can write to you an email to correspond if you ok it only.
Thanks again
thillai

Reply With Quote
  #5 (permalink)  
Old March 2nd, 2008, 02:33 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Upendra and Ankur have alluded to this but you should definately pick up a book about programming with Visual Basic. To build on what Ankur said with regard to classes, this is where you will find alot of programmers place code that they call from various places throughout an application.

For example, let's say that in your application once the user has clicked a button you check that several textboxes do not contain an empty string. You could write an if statement for each of the textboxes:

If textbox1.Text = "" then 'do something
If textbox2.Text = "" then 'do something

Or you could create a class that does this for you:

Public Class foo
    Public Shared Function isValid(ByVal value As String) As Boolean
        If value = "" Then
            Return False
        Else
            Return True
        End If
    End Function
End Class

so now to check the value of each of your textboxes you would make a call similar to this:

if Not foo.isValid(textbox1.Text) then 'do something
if Not foo.isValid(textbox2.Text) then 'do something

Granted, this is an overly simplistic example but it demonstrates the methodology very well because now, through out your entire application, everytime you need to check if a textbox contains a value you can call this central class 'foo' which will do the evaluation for you; your application simply needs to handle the Boolean value coming back from the function.

In so far as not redrawing the form, that depends. If the form elements are the same for each form then you could add a combo box to the form that could change the 'mode' of the form. In your case the combo box would contain: Math, Spelling, and Word so, theoretically, when the user clicks the 'Complete' button your event handler could look something like this:

Protected Sub btn_Click(ByVal sender As Object, ByVal e As eventArgs) Handles btn.Click
     Select Case cmb.Text
         Case "Math"
           ProcessMathForm()
         Case "Spelling"
           ProcessSpellingForm()
         Case Else
           ProcessWordForm()
     End Select
End Sub

This should be enough material for you to continue working on your app but I emplore you to purchase a book that can address not merely HOW to do something but WHY you should be doing it.

Wrox has many books that address this topic:
http://www.wrox.com/WileyCDA/Section...&field=keyword

From that list I would suggest:
http://www.wrox.com/WileyCDA/WroxTit...764574019.html

Alternatively you can purchase a subscription to Wrox's online library which gives you access to a large portion of the Wrox Collection (the book mentioned above is in there as well): http://wrox.books24x7.com/ it costs 49.99 for a quarter or 175.00 for an entire year. You can get more information regrading this service here: http://www.wrox.com/WileyCDA/Section/id-130024.html

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #6 (permalink)  
Old March 4th, 2008, 10:40 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default

hello Doug,
Thanks for the explanation and guidance on class definition and I will persue this path and learn more.
Thanks again
thillai

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updated Wrox Code Reuse Policy jminatel Wrox Book Feedback 2 July 1st, 2013 08:30 AM
Help with php and this part of the code...? dekemcaffee Beginning PHP 2 September 29th, 2007 06:14 PM
How to get html code for the selected part of the suryasimha General .NET 2 August 27th, 2007 03:32 PM
Reuse of ASP Code hoffmann Classic ASP Databases 6 August 8th, 2003 11:20 AM



All times are GMT -4. The time now is 10:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.