How can I write a common function for increasing and decreasing the value in the textbox?)

Posted on 2012-08-17
Medium Priority
Last Modified: 2012-08-21
Hi everyone,

I am creating an application (WPf with vb.net) which has increase and decrease button. I got the functionality working. As, I have multiple buttons with the same functions so I want to write a common function for all the events.

Current code is :
     Dim value As Integer

        If Integer.TryParse(TextBox7.Text, value) Then
            TextBox7.Text = (value + 1).ToString()
        End If

Thank you for your help.
Question by:developer2012
LVL 75

Accepted Solution

käµfm³d   👽 earned 1500 total points
ID: 38307282
Sub IncrementBox(ByVal sender As TextBox)
    Dim value As Integer

    If Integer.TryParse(sender.Text, value) Then
        sender.Text = (value + 1).ToString()
    End If
End Sub

Open in new window

...and then in your event handlers:

IncrementBox(DirectCast(sender, TextBox))

Open in new window


Expert Comment

ID: 38307566
You need to create a function having parameter of which textbox value should be incremented/decrement.
And second parameter is may be increment/decrement like 1 for increment and 0 for decrement suppose.

now for each button click u need to call this function with textbox name which value increment/decrement depend on second parameter 1/0.

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question