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

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

I am creating an application (WPf with 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 74

    Accepted Solution

    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

    LVL 9

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now