473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

if textbox value is negative then increment 1

ayakamacy
how to construct conditional statement if the textbox value is negative then it will increament 1

for example:

the textbox is: -2
then in database it will save by increamenting as 1.

it will become as: -3

can someone help me out for this problem. thanks
----
i have here a sample code for computing delays of date.
but then the computation if d2 is greater than d1 it will be a negative result. but the answer is not accurate (see the attach picture)

here is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim dt1 As DateTime = Convert.ToDateTime(Date.Now)
  3. Dim dt2 As DateTime = Convert.ToDateTime(txtDate2.Text)
  4. Dim ts As TimeSpan = dt1 - dt2
  5. If Convert.ToInt32(ts.Days) <> 0 Then
  6.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  7. ElseIf Convert.ToInt32(ts.Days) = 0 Then
  8.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  9. Else
  10.     Response.Write("Invalid Input")
  11. End If
  12.  
can someone tell me where did i get wrong in my coding?
Attached Images
File Type: jpg invalid.jpg (19.9 KB, 98 views)
May 23 '15 #1

✓ answered by computerfox

As mentioned, if the answer is -3 then that is decrement and you gave incorrect information.

Try this:
Expand|Select|Wrap|Line Numbers
  1. Dim dt1 As DateTime = Convert.ToDateTime(Date.Now)
  2. Dim dt2 As DateTime = Convert.ToDateTime(txtDate2.Text)
  3. Dim ts As TimeSpan = dt1 - dt2
  4. If Convert.ToInt32(ts.Days) < 0 Then
  5.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days)-1)
  6. Elseff Convert.ToInt32(ts.Days) > 0 Then
  7.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days))
  8. ElseIf Convert.ToInt32(ts.Days) == 0 Then
  9.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days))
  10. Else
  11.     Response.Write("Invalid Input")
  12. End If
  13.  

6 1497
computerfox
276 100+
By the looks of it, your conditional statements don't do anything.
The first set checks if it's greater or less than 0 and the second might not even be valid as it needs to be "==", but in both sets you do the same statement.

Try this:

Expand|Select|Wrap|Line Numbers
  1. Dim dt1 As DateTime = Convert.ToDateTime(Date.Now)
  2. Dim dt2 As DateTime = Convert.ToDateTime(txtDate2.Text)
  3. Dim ts As TimeSpan = dt1 - dt2
  4. If Convert.ToInt32(ts.Days) < 0 Then
  5.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)+1
  6. Elseff Convert.ToInt32(ts.Days) > 0 Then
  7.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  8. ElseIf Convert.ToInt32(ts.Days) == 0 Then
  9.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  10. Else
  11.     Response.Write("Invalid Input")
  12. End If
  13.  
Hope that helps!

For the record, "increment" means ++ so -2 would be -1.
Decrement would cause it to be -3.
May 23 '15 #2
Hello @ computerfox, the answer is still incorrect.
please see the attach picture.
Attached Images
File Type: jpg still incorrect.jpg (47.6 KB, 99 views)
May 23 '15 #3
computerfox
276 100+
As mentioned, if the answer is -3 then that is decrement and you gave incorrect information.

Try this:
Expand|Select|Wrap|Line Numbers
  1. Dim dt1 As DateTime = Convert.ToDateTime(Date.Now)
  2. Dim dt2 As DateTime = Convert.ToDateTime(txtDate2.Text)
  3. Dim ts As TimeSpan = dt1 - dt2
  4. If Convert.ToInt32(ts.Days) < 0 Then
  5.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days)-1)
  6. Elseff Convert.ToInt32(ts.Days) > 0 Then
  7.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days))
  8. ElseIf Convert.ToInt32(ts.Days) == 0 Then
  9.     txtTtlDelay.Text = (Convert.ToInt32(ts.Days))
  10. Else
  11.     Response.Write("Invalid Input")
  12. End If
  13.  
May 23 '15 #4
ok, i knew it. i just change the add value into negative.
So, I got the correct answer.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim dt1 As DateTime = Convert.ToDateTime(Date.Now)
  3. Dim dt2 As DateTime = Convert.ToDateTime(txtDate2.Text)
  4. Dim ts As TimeSpan = dt1 - dt2
  5. If Convert.ToInt32(ts.Days) < 0 Then
  6.     txtTtlDelay.Text = Convert.ToInt32(ts.Days) + -1
  7. ElseIf Convert.ToInt32(ts.Days) > 0 Then
  8.     txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  9. ElseIf Convert.ToInt32(ts.Days) = 0 Then
  10.      txtTtlDelay.Text = Convert.ToInt32(ts.Days)
  11. Else
  12.      Response.Write("Invalid Input")
  13. End If
  14.  
anyways, thanks @computerfox
May 23 '15 #5
computerfox
276 100+
Ehhh.... you should not do that, it's just not appealing.
Try the new code I provided and also keep in mind for the future that parenthesis help.
May 23 '15 #6
@computerfox, i already used your new code.
and the result now is accurate.
yeah right, i will now use parenthesis so that it can be look like a formal coding. hehe, thanks anyway =)
May 23 '15 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Raed Sawalha | last post by:
Hi, This is probably pretty simple but... I am dynamically adding rows to a HtmlTable that contain Textbox controls. (There may be more than one server control/textbox in a given cell) How...
2
by: Atreju | last post by:
Ok I got form within a c sharp page. Situation: On the form I have a drop downliwst and a textbox, the dropdownlist is populated with products and the textbox has a default vale of the product...
2
by: Nowezo | last post by:
Hi, Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of...
1
by: viral123 | last post by:
Hi all I am using Crystal report and I am running my report successfully for my query but I want to make my query for one specific date. I want to get the date value from the textbox value. ...
2
by: Archanak | last post by:
Hi, I have one common text box to get email id. I have 2 forms and both form action connects to different programs. I want to use this textbox value(i.e email id) only for both the forms. How...
10
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value...
1
by: visweswaran2830 | last post by:
Hi, I have datagrid control. In that I place textbox, insert link button in hearder template. When I click that Insert button the value from textbox should be loaded into grid. I am capturing at...
0
by: yogarajan | last post by:
Hi All I am create textbox and collect textbox value at runtime using c# my aspx code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> <!DOCTYPE html...
10
by: honar | last post by:
hi everybody in ms-access 2010, i have a form with some textbox one of my textbox is p_name textbox over the form a put to different fonts with radio buttons ... i want to change the font of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.