Solved

Need help figuring out a code for the numericUpDown min and maximum

Posted on 2011-03-23
11
406 Views
Last Modified: 2013-11-27
Ok so I got the main part of the assignment done and my teacher added a part to the assiment seperate from the book. Ok I have to add a starting rate NumericUpDown control and a Ending Rate NumericUpDown control. So I figured out how to get the Starting Rate minimum to be set at 2 and the maximum to be set at 20 because you can do that in the properties box on the right side but now for the EndingRate NumericUpDown I have to make the minimum to always be 2 more than the StartingRate current value and the EndingRate Maximum to always be 10 more than the Starting Rate current value and I cant figure out how to write a code for that and its starting to become a bit frustrating. Any help would be greatly appriciated.
0
Comment
Question by:goldfingerpunk
  • 6
  • 5
11 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35202525
Handle the ValueChanged() event of the starting rate NumericUpDown and change the ending rate min/max values accordingly:
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.valuechanged.aspx
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        ' ... do something in here to change the min/max values of NumericUpDown2 ...
    End Sub

Open in new window

0
 

Author Comment

by:goldfingerpunk
ID: 35203222
right I got that far but the book i have doesnt even explain what to do and Im clueless on what to put in there to make it work here is what i put in sofar and it doesnt work....
For EndingRateNumericUpDown1.Minimum = StartingRateNumericUpDown1.Value To EndingRateNumericUpDown1.Value Step 2
        Next
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35203244
NO for loops are needed here...   ;)

To get the CURRENT number in the first NumericUpDown you would use the .Value() property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.value.aspx

Now add 2 to that and set the Minimum() property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.minimum.aspx

...and add 10 to it and set the Maximum() property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.maximum.aspx

YOU CAN DO IT!  Go forth and code...  =)
0
 

Author Comment

by:goldfingerpunk
ID: 35203320
ok ill try it  is this even close ...
StartingRateNumericUpDown1.Value() = EndingRateNumericUpDown1.Value.MinValue(+2)
0
 

Author Comment

by:goldfingerpunk
ID: 35203339
wait is this better...
 StartingRateNumericUpDown1.Value = (StartingRateNumericUpDown1.Value)
        EndingRateNumericUpDown1.Minimum = +2
        EndingRateNumericUpDown1.Maximum = +10
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35203416
Getting MUCH closer!

*Your first line isn't actually doing anything.

Start with this:

    Dim currentValue As Integer = StartingRateNumericUpDown1.Value

Now what can you do with "currentValue"?
0
 

Author Comment

by:goldfingerpunk
ID: 35203441
Dim currentvalue As Integer = StartingRateNumericUpDown1.Value
        EndingRateNumericUpDown1.Minimum = (currentvalue + 2)
        EndingRateNumericUpDown1.Maximum = (currentvalue + 10)

my teacher says that it has to automatically update the EndingRateNumericUpDown every time I adjust the StartingRateNumericUpDown
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35203451
Beautiful!...

"my teacher says that it has to automatically update the EndingRateNumericUpDown every time I adjust the StartingRateNumericUpDown"

Now WHERE, read that as "which EVENT", can we place that code?
0
 

Author Comment

by:goldfingerpunk
ID: 35203464
Ok I got that part to work finally now the problem is getting it into the multiline text box the first column is Rate(%) the second column is Amount after 5 years and the third column is Amount after 10 years. Now before I did the addendum that the teacher added I did the part in the textbook first so here is what I got so far. I gotta figure out how to get this to appear right.

 ' Declare Variables
        Dim Principal As Decimal
        Dim Amount1 As Decimal
        Dim Rate As Decimal
        Dim Output As String

        ' Retrieve User Input
        Principal = Val(principalTextBox.Text)
        Output = ResultTextBox.Text

        ' Set Output Header
        Output = Output & "Rate(%)" & ControlChars.Tab & "Amount after 5 years" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

        ' Calculate Amount
        For rate As Decimal = 5 To 10 Step 1
            Amount1 = _
            Principal * ((1 + rate / 100) ^ 10)
            Output = Output & (rate & ControlChars.Tab & ControlChars.Tab & _
                       String.Format("{0:C}", Amount1) & ControlChars.CrLf)
        Next
       



        ResultTextBox.Text = Output

    End Sub
0
 

Author Comment

by:goldfingerpunk
ID: 35203515
ok I Figured most of it out im just getting lost on the part on how to get the second column (amount after 5 years) and the third column (amount after 10 years) to have the calculations to appear. Because When I try to do two strings it just gives me an error message.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35203524
Show me what you've got now...

...and how is StartingRateNumericUpDown1 and EndingRateNumericUpDown1 being incorporated into the code?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

758 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

19 Experts available now in Live!

Get 1:1 Help Now