Results 1 to 5 of 5

Thread: Calculated Field in Visual Studio

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010

    Calculated Field in Visual Studio

    I can place 3 or more text boxes on a form, and in the "TextChanged" or "Lost Focus" call a subroutine to calculate the value of the last textbox.

    But is there anyway to do this a little more automatically - perhaps by specifying on my last text box that its value is reliant on selected controls - and having it autocalculate whenever the value of those fields change?

    I suspect that the answer is no - but just thought I would ask

  2. #2
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013

    Re: Calculated Field in Visual Studio

    Using the lost focus would work, you'd need to keep track of 2 boxes.
    Or you can just put a radiobutton on each box and the user will select the value to find.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2012

    Re: Calculated Field in Visual Studio

    You can use DataBindings in order to connect a Control to a particular data provider. So for example, you can bind a TextBox to a ComboBox like:
            Me.TextBox1.DataBindings.Add("Text", ComboBox1, "Text")
            With Me.ComboBox1.Items
            End With
    Note, too, that DataBinding like this is bi-directional... In my example above, just reading the line Me.TextBox1.DataBindings.Add("Text", ComboBox1, "Text") sounds like when I change the Text in the ComboBox (by selecting an item in the drop-down), the TextBox's Text would change to reflect that. Although that is true, it will also work "backwards" in that were I to type into the TextBox "World", it would in turn put "World" into the Text of the ComboBox (and if that item is in the ComboBox's Items collection, will select that item).

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002

    Re: Calculated Field in Visual Studio

    I'm beginning to wonder if I'm reading the post wrong...Both of the above replies feel like they are off base. By a lot.

    The key to the question in this post lies in the subject: "calculated field" ... as in a calculated field in a database, where you can't update it directly, but it displays a value based on other fields & values. For example, in the system I work on, we might have a StatusCode field, which has a range of value from 0 to 4 ... then right next to it, we have Status, a calculated field that looks at StatusCode and returns a human-friendly value, could be "New" (for a StatusCode of 0) or "Archived" (for a StatusCode of 4) ...

    What the OP is looking for is something similar... he changes a value in some other field (could be a text box, could be a combobox, could be a numeric up down control) and a "bound" ui field elsewhere on the form automatically updates, w/o having to actually do anything programatically...

    @Anthony - In short, no, there's no real direct way to do it. The way you're going about it is generally the accepted way to go about it. There is one possible way of going about it, but if the logic is more complicated than simple concatenation, it's not a good way to go.

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2010

    Re: Calculated Field in Visual Studio

    Thank you techgnome - I was beginning to wonder if I had not phrased my question clearly enough.
    Oh well, I will continue calling a subroutine whenever the various contributing objects changevalue or lose focus.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width