Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,180 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,042 people online right now. Registration is fast and FREE... Join Now!




code to remove negative numbers

 
Reply to this topicStart new topic

code to remove negative numbers

dol0rean2o03
23 Aug, 2007 - 07:30 AM
Post #1

New D.I.C Head
*

Joined: 23 Aug, 2007
Posts: 1


My Contributions
CODE
Sub Scrape()
    
    Olesetup
    x% = ExtraObj.OleSendKey(handle, "@C") '--- Clear Extra Screen ---'
    x% = ExtraObj.CheckClockStatus(handle) '--- Send screen name to Extra ---'
    x% = ExtraObj.OleSendKey(handle, "itmsls 09/829/00103@E")
    x% = ExtraObj.CheckClockStatus(handle)
    'x% = ExtraObj.OleSendKey(handle, "@t")
    'x% = ExtraObj.OleSendKey(handle, ID)
    'x% = ExtraObj.OleSendKey(handle, "@e")
    'x% = ExtraObj.CheckClockStatus(handle)
        For index% = 6 To 19 '--- get screen start ---'
            scrapedata$(index%) = ExtraObj.OleGetString(handle, index%, 1, 80)
            ActiveCell.Value = scrapedata$(index%)
            ActiveCell.Offset(1, 0).Select
        Next index
    x% = ExtraObj.OleSendKey(handle, "@e")
    x% = ExtraObj.CheckClockStatus(handle)
    'CurrLine = scrapedata$(1) '--- get screen end ---'
    Shutdown
End Sub

how can I input a code here that would make sure that it doesnt allow any negative numbers to come thru
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Code To Remove Negative Numbers
23 Aug, 2007 - 09:12 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,199



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You just need to test the value using an if statement and put whatever you want to execute inside it if its greater than or equal to zero. Something like...

CODE


if number >= 0 then
    ' Do something here
else
    ' You can do something here if its negative
end if


Here we assume "number" is variable that holds the number you want to test. Notice how you test if it is greater than or equal to zero. Negative numbers will fail this test. You can put in an else statement to handle the negative numbers if you like, but that is optional.

Hope this helps. smile.gif
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Code To Remove Negative Numbers
25 Aug, 2007 - 02:09 AM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
The Sgn() function can also be used.
If you're writing a large project, I'd recommend using Sgn() over the (If number>=0) as it makes the code more readable when you refer to it later.

In the future when you are having a brief look at the code, if you see the IF Construct, you will need to read the rest of the code to figure out that the number was being checked for being a positive number ONLY. (Remember, that same condition is used to check for many other conditions as well and not just its sign.)

But when you come across the Sgn() function, you can directly see that the number is checked for its sign.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Code To Remove Negative Numbers
25 Aug, 2007 - 06:30 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
And lastly you could always use Regular Expressions as such

CODE

Dim objRegExp As RegExp
Set objRegExp = New RegExp
'Set the pattern by using the Pattern property.
   objRegExp.Pattern = "^-\d+$"

   ' Set Case Insensitivity.
   objRegExp.IgnoreCase = True

   'Set global applicability.
   objRegExp.Global = True

If Not objRegExp.Test(myNumber) Then 'Passed, no negatve number
'do your processing here

Else
'Do your processing here

End If


Hope this helps smile.gif

Happy Coding!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:09AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month