Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,399 VB.NET Programmers. There are 1,467 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

reduce the same code

 
Reply to this topicStart new topic

reduce the same code

shee_dee86
post 5 May, 2008 - 06:39 PM
Post #1


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 5



i'm very new to vb.net
here i have a problem.. how can i reduce the same code in my vb.net?
i have to write the same code each time i want that code repeat again..
is there any solution.. and i want to make a program for example after user input the name in textbox he/she do not need to press the button, but just enter it.. i've heard about subroutine, i've search but i do not what actually is subroutine coz it confusing me.. anyone can help about reduce the same code..
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


kyrotomia
post 5 May, 2008 - 08:51 PM
Post #2


New D.I.C Head

*
Joined: 5 May, 2007
Posts: 25

Hi,
I am not quite sure I understood 100% of the question, but I think you are asking how to use procedures.
First of all, you need to define that procedure. I am considering that you only want to execute code, and do not need data that gets in or out of your procedure.

Defining a procedure :
CODE

   Private Sub myProcedure()
        'Put some code here...
        MessageBox.Show("Hello world!")
    End Sub


And then, whenever you want to execute your procedure, you can simply call it this way :

CODE

'Some code before calling the procedure
myProcedure()
'Some code after calling the procedure


This way, you can easily "reuse" code that has to be executed multiple times without copy/pasting it back every time. You can also add parameters to this procedure. This way, the code can be used, for example, for managing texts from a textbox.

Procedure :
CODE

Private Sub myCode(ByVal myTextBox As TextBox)

        myTextBox.Text = "Hello world!"

End Sub


Using it in your form :
CODE

myCode(TextBox1) 'Inserting text into textbox1 by using a procedure
'you can do this for any textbox in your form
myCode(TextBox2)


I really hope that may help you. Good luck getting started with Visual Basic.net
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

shee_dee86
post 6 May, 2008 - 06:24 PM
Post #3


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 5

thanx for ur help and i'm sorry for confusing u with my question... ur guide really good for me.. but, i'm have that same problem.. here is my sample code for button1 click event
CODE

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim textOne As String
      
        textOne= TextBox1.Text
        MessageBox.Show(textOne)
  
    End Sub


and what should i put for my textbox1_enter event code here..
i put a code here but it has error where it said argument not specified for parameter ....
here is my dummy code to do again button1_click event:
CODE

Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
        Dim textinf As New WindowsApplication1.Form1
        textinf.Button3_Click()
    End Sub

ermm.. can u tell me what is wrong here..
i'm make vb windows application now..
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

kyrotomia
post 7 May, 2008 - 05:32 AM
Post #4


New D.I.C Head

*
Joined: 5 May, 2007
Posts: 25

I am sorry, but I do not understand what is your question. Are you trying to execute Sub Button1_Click for Button3?

As for your error "argument not specified for parameter ....", you would need to call your button3_click this way :
CODE

Button3_Click(sender,e)
.

Please explain further your problem, because I am not able to understand.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:16AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month