-
Aug 30th, 2009, 12:37 PM
#1
Thread Starter
Lively Member
[RESOLVED] Datetimepicker Calculation
-
Aug 30th, 2009, 01:04 PM
#2
Hyperactive Member
Re: Datetimepicker Calculation
I think that you must calculate with Value part of DateTimePickerControl and not Text while Text will give you string representation and with strings you can not add or substract numbers.
Try to change "DateTimePicker2.Text" => "DateTimePicker2.Value"... etc
EDIT: And Date1 is also VALUE and not TEXT
-
Aug 30th, 2009, 01:51 PM
#3
Thread Starter
Lively Member
Re: Datetimepicker Calculation
-
Aug 30th, 2009, 03:22 PM
#4
Hyperactive Member
Re: Datetimepicker Calculation
Originally Posted by HOTFIX
THANKS Zeljko
N.P.
Originally Posted by HOTFIX
Do you have any idea how to validate the input selection(for case adding & Subtracting) in the textbox so the Calculation will be in correct range of min and max date of the Datetimepicker control dynamically...
If I understand you corectly:
You wannt to limit Textbox number so that the User can not acidentaly substract 25 days from sunday 14 august 2008 (if is 25 in TextBox, days => 25-14=-11 days)?
You can do that with:
VB.Net Code:
'1 - It's easyer to change TextBox to Numeric UpDown control '2 - Numeric UpDown can limit Min and max number :) '3 - Use OnChange event of Numeric UpDown control to limit min max number inside control...
But if you do not want that, and you want to substract 25 from 14 and go to previous month then it's a bit more math included. huh. You must first calculate Days and then add extra to Months. Then calculete Months and add extra to Years and so on and on.
But be carefull: Each Month is not equal in number of Days so I strongly sugest for easynes that you take 1 Month = 30 Days (offcourse, if you can do that with posible little error )!
-
Aug 30th, 2009, 04:20 PM
#5
Thread Starter
Lively Member
-
Aug 30th, 2009, 06:04 PM
#6
Hyperactive Member
Re: Datetimepicker Calculation
The maximum year you can have is 9998. Thus the year is outside the max & min allowed.
It was much easier in VB6, but I am now liking Vb.Net alot more.
-
Aug 30th, 2009, 10:13 PM
#7
Hyperactive Member
Re: Datetimepicker Calculation
I'm confused,
Try On TExtBox Change event:
If TExtBox is > 7989 then
TExtBox.Text = 7989
'and maybe some kind of MsgBox to inform user
...
But I will still replace TextBox with Numeric control (while then its limited to only recive numbers)
-
Aug 31st, 2009, 04:19 AM
#8
Thread Starter
Lively Member
Re: Datetimepicker Calculation
Originally Posted by computerman
The maximum year you can have is 9998. Thus the year is outside the max & min allowed.
What I’m looking for is validation code to inform the user when the numeric value in the textbox (for all cases days, weeks...etc) is outside of the max & min Calculation allowed by warning message…
Regards...
-
Aug 31st, 2009, 04:53 AM
#9
Thread Starter
Lively Member
Re: Datetimepicker Calculation
Originally Posted by Zeljko
I'm confused,
Try On TExtBox Change event:
If TExtBox is > 7989 then
TExtBox.Text = 7989
'and maybe some kind of MsgBox to inform user
...
But I will still replace TextBox with Numeric control (while then its limited to only recive numbers)
Thanks Zeljko for your support...
I've got the code to allow user limiting the input of the textbox to receive numbers only by using keypress event:
Code:
Private Sub TBxValue_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TBxValue.KeyPress
If (Char.IsControl(e.KeyChar) = False) Then
If (Char.IsDigit(e.KeyChar)) Then
'do nothing
Else
e.Handled = True
MsgBox("Sorry Only Digits Allowed!!")
TBxValue.Focus()
End If
End If
End Sub
Unfortunately I'm looking for validation code to inform the user when the numeric value in the textbox is out of range Datetimepicker MIN and MAX date Calculation...
Any idea PLZ ...
-
Aug 31st, 2009, 05:26 AM
#10
Hyperactive Member
Re: Datetimepicker Calculation
This is from one of my progies for TextBox but it can easily be applied to NumericUpDown if you wanna:
VB:Net Code:
Friend Sub txtboxQs_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtboxQs.Leave
'...
'limit beetwen 0.05 and 0.1
If CDbl(txtboxQs.Text) < 0.05 Or CDbl(txtboxQs.Text) > 0.1 Then
'so if its "out of range" set it to zero or you can call msgbox or something else
txtboxQs.Text = 0.0
MessageBox.Show("Out of Range (<0.05 or > 0.1)", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0)
End If
'...
End Sub
-
Aug 31st, 2009, 06:25 AM
#11
Thread Starter
Lively Member
-
Aug 31st, 2009, 06:33 AM
#12
Hyperactive Member
Re: Datetimepicker Calculation
Np.
With your way of learning and trying it was such an easy way to guide you.
Good luck with programing...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|