---
title: "VB Prevent negative integers"  
description: "VB Prevent negative integers"  
author: "marcel ethan"  
published: 2013-06-11  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1028/vb-prevent-negative-integers  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 3 minutes  

---

# VB Prevent negative integers

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
How to calculate 3 [text boxes](https://www.mindstick.com/forum/34261/how-to-split-data-to-text-boxes-when-read-qr-code-data) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) (only positive value) and display into single [label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better) . If user interned negative value it [display error](https://www.mindstick.com/forum/158286/how-to-display-error-messages-using-jquery-validation) message. However every time I run the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) it just calculates the text box with a negative number as 0 and completes the rest of the calculations. \
**My line of code as following**\

```
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click    Dim intPackA As Integer    Dim intPackB As Integer    Dim intPackC As Integer    Dim intCalc As Integer    Try        If txtPackA.Text Or txtPackB.Text Or txtPackC.Text <= 0 Then            lblCalc.Text = "Please enter positive numeric values"        End If        If txtPackA.Text >= 0 Then            intPackA = txtPackA.Text * 79.2        Else            lblCalc.Text = "Please enter positive numeric values"        End If        If txtPackB.Text >= 0 Then            intPackB = txtPackB.Text * 119.4        Else            lblCalc.Text = "Please enter positive numeric values"        End If        If intPackC >= 0 Then            intPackC = txtPackC.Text * 149.5        Else            lblCalc.Text = "Please enter positive numeric values"        End If        intCalc = intPackA + intPackB + intPackC        lblCalc.Text = "Package A:  " & intPackA.ToString("c") + vbCrLf & "Package B:  " & intPackB.ToString("c") + vbCrLf & "Package C:  " & intPackC.ToString("c") + vbCrLf + vbCrLf & "Grand Total: " & intCalc.ToString("c")    Catch        lblCalc.Text = "Please enter positive numeric values"    End TryEnd Sub
```

**\**Please [guide](https://www.mindstick.com/articles/44463/business-to-business-vat-reclaiming-a-guide-for-your-employees) me, where i'm [wrong](https://answers.mindstick.com/qa/48468/who-wrote-the-the-wrong-enemy-america-in-afghanistan-2001-2014-and-when)?\
Any help on above is really appreciated.

## Replies

### Reply by AVADHESH PATEL

Hi Marcel,\
In place of following line of code

```
  If txtPackA.Text Or txtPackB.Text Or txtPackC.Text <= 0 Then            lblCalc.Text = "Please enter positive numeric values"   End If
```

**\**Use this line of code**\**

```
If txtPackA.Text <= 0 Then    lblCalc.Text = "Please enter positive numeric values"    txtPackA.Focus()    Exit SubElseIf txtPackB.Text <= 0 Then    lblCalc.Text = "Please enter positive numeric values"    txtPackB.Focus()    Exit SubElseIf txtPackC.Text <= 0 Then    lblCalc.Text = "Please enter positive numeric values"    txtPackC.Focus()    Exit SubEnd If
```

**\**I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1028/vb-prevent-negative-integers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
