473,327 Members | 2,118 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,327 software developers and data experts.

How to tell if a number is positive or negative?

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 35792
devonknows
137 100+
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 1GB
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 Expert 512MB
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
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 Expert 8TB
...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
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...
3
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...
7
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
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
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...
2
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. ...
5
by: vbgunz | last post by:
/* * BEGIN EXAMPLES */ var text = 'A Cats Catalog of Cat Catastrophes and Calamities'; /*** * EXAMPLE 1: negative lookahead assertion logic ***/
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.