473,611 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to tell if a number is positive or negative?

12 New Member
Hi guys

Im new to visual basic, and I am 14 yrs old, so I beg you to bear with me.

I want to make a simple program that tells you whether the input is a positive number or a negative number. I have tried everything i know, but to no avail.

Please help me

Thanks
Mar 10 '07 #1
5 35947
devonknows
137 New Member
Good afternoon, if the number you are trying to determine is negative or positive is in a text box control then you have to turn it into a long or and integer. (will not work normally as it is determined as a string). So instead of using

Expand|Select|Wrap|Line Numbers
  1. If Text1.Text < 0 Then
  2.     MsgBox "Negative"
  3. ElseIf Text1.Text > 0 Then
  4.     MsgBox "Positive"
  5. Else
  6.     MsgBox "Is not a number or is 0"
  7. End If
  8.  
you have to turn them into Longs or Integers with either Clng or Cint for example

Expand|Select|Wrap|Line Numbers
  1. If CInt(Text1.Text) < 0 Then
  2.     MsgBox "Negative"
  3. ElseIf CInt(Text1.Text) > 0 Then
  4.     MsgBox "Positive"
  5. Else
  6.     MsgBox "is not a number or is 0"
  7. End If
  8.  
The above code is tried and tested my friend. (ps. you can change it from an Integer to A Long by changing: -

If CInt(Text1.Text ) < 0 Then

to

If CLng(Text1.Text ) < 0 Then

Hope this helps you
Kind regards
Devon.
Mar 10 '07 #2
willakawill
1,646 Top Contributor
Hi. so this will be part of an assignment. Is it the entire assignment or just a part of it?
Mar 10 '07 #3
markmcgookin
648 Recognized Expert Contributor
Hi guys

Im new to visual basic, and I am 14 yrs old, so I beg you to bear with me.

I want to make a simple program that tells you whether the input is a positive number or a negative number. I have tried everything i know, but to no avail.

Please help me

Thanks
So if you are reading in from txtBox1

Expand|Select|Wrap|Line Numbers
  1.  
  2. value=ToDouble(txtBox1.Text) 'convert an input into numerical form
  3.  
  4. IF value > 0 'check to see if it is greater than 0
  5. msgbox "Value Entered is positive"
  6.  
  7. ELSE
  8. msgbox "value Entered is negative" 'If it isn't then...
  9.  
  10.  
Mar 10 '07 #4
Bl00dFox
12 New Member
Thanks for your reply! I really appreciate your help.

No, this is not part of an assignment, I am trying to make a program that helps you to sketch a parabola by finding concavity, vertex, etc. to help my friends.

I am so stupid! I tried all wierd things like diving by -a, -1 and all random stuff. Thankyou sincererely!
Mar 10 '07 #5
Killer42
8,435 Recognized Expert Expert
...I am so stupid! I tried all wierd things like diving by -a, -1 and all random stuff. Thankyou sincererely!
Jumping around trying out lots of ideas can be a good way to not only solve a problem, but learn stuff along the way. But you do need to keep in mind some idea of where you're going, or you could be thrashing around forever.
Mar 12 '07 #6

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

Similar topics

10
2993
by: KathyB | last post by:
Hi, I just can't get this quite right. I use the following function to validate a user entry. I need to allow negative numbers including those with decimals (e.g., -.5). The following allows the decimals but not the negative. Any help appreciated...as always. Thanks -- Kathy function ValidateSave(formRef,fieldName,min,max) { var formField = formRef.elements; if (!/^\d+(\.\d+)?$/.test(formField.value)) {
3
3558
by: Dig314 | last post by:
I need to Total the amounts for each Property ID in a table. All the amounts are stored as positive in the database. Based on a transaction code, the amount should be added or subtracted. There are about 14 transaction codes, but here is an example: Transaction Code "Addition" - - add the amount Transaction Code "Disposal" - - subtract the amount Can this be done in single select statement ?
7
5374
by: hasanainf | last post by:
Hi all, I have two querys QueryPurchased ProductID Location TotPcs Prod1 Loc1 100 Prod2 Loc1 50 Prod3 Loc1 150 Prod3 Loc3 150
19
11531
by: Johs | last post by:
I need to make some special action if 'a' and 'b' are both positive or both negative. Is there some inbuilt function to check this? Johs
29
2328
AccessIdiot
by: AccessIdiot | last post by:
I'm sure this must be possible but I'm still a newbie and not sure how to do it. Part One: Using the good 'ol customers and orders tables and forms example - how would I go about putting a little text box on the customers form that shows, for any given record (customer), the number of related orders that customer has? In pseudocode its something like count the number of records in Orders where Customer_ID = X. Would the code go in the...
2
15837
by: STEPHENSS | last post by:
Hi, New to SQL. I need to reverse the signs, for example I have an amount of -1,500.00 and I need to change the the Amount to 1,500.00 and all positives amount to a negative amount also. Thank you Stephen
5
2303
by: vbgunz | last post by:
/* * BEGIN EXAMPLES */ var text = 'A Cats Catalog of Cat Catastrophes and Calamities'; /*** * EXAMPLE 1: negative lookahead assertion logic ***/
0
8149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8596
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8561
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8240
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.