PDA

View Full Version : VB Question


GoldenEagle
09-29-2004, 10:04 AM
I have to write code that will make a program have a sales commission for a certian percentage of what the salesperson sales.

So if I had to write that if a guy sold between 100,000 and 200,000 how would I code that? Like this?

If intSales <= 100,000 && >= 200,000 Then
intSales *.75
End If

Is tthat right?

hukarez
09-29-2004, 10:08 AM
Early in the morning for me, but maybe this? :confused:

If intSales <= 100,000 AND intSales >= 200,000 Then
intSales = intSales *.75
End If

GoldenEagle
09-29-2004, 10:11 AM
Is AND a key wiord in VB?

hukarez
09-29-2004, 10:18 AM
Is AND a key wiord in VB?Actually, it's an operator that can be used in SQL statements too.

For the most part, I think if you use the & sign, it'll append your statements into 1, as opposed as to treating them separately. For example, say you have two string variables (X and Y), with X = Hello and Y = World. If you use something like:

If X = Hello And Y = World Then
Z = X & Y
End If

...which would result in: HelloWorld.

Erg...my explanation of these things is a bit off, I know - most likely I'm getting confused (do a whole lot of VB and SQL here at work with 'And' and '&' signs in If...Then statements), but try this out:

If (intSales <= 100,000) And (intSales >= 200,000) Then
intSales = intSales *.75
End If

So if your intSales is less than or equal to 100,000, and your intSales is greater than or equal to 200,000 then your intSales will equal the present amount it is, multiplied by .75 and what not. Hmm...wait a minute.

Try:

If (intSales >= 100,000) And (intSales <= 200,000) Then
intSales = intSales * .75
End If

Essentially, the 'And' operator here will run through if both instances are true.
In this case, if your intsales is greater than or equal to 100,000 *and* is also less than or equal to 200,000 then your intSales will equal your present amount times .75 and what not. Otherwise, it'll fall out of the statement.

Mr. Wednesday
09-29-2004, 01:23 PM
'&' is the string concatenation operator in VB
'&&' is the logical and operator in C, C++, and Java (possibly others as well)
And is the bitwise and operator
Or is the bitwise or operator
VB classic does not have logical operators, all of the boolean logic is handled bitwise (with True being all bits on and False being all bits off, VB does not adhere to the [IMO unfortunate] C legacy of True as one bit on).

Also, I don't think the comma will work. I think you'll have to enter the numbers without it.

Finally, I doubt this:
intSales = intSales * 0.75
is what you want.

Maybe something like this instead:
dblComm = intSales * 0.75
(if fractional cents are important to you, beware the inexactness of FP math and consider using scaled integers instead)

hukarez
09-29-2004, 01:32 PM
Finally, I doubt this:
intSales = intSales * 0.75
is what you want.

Maybe something like this instead:
dblComm = intSales * 0.75
(if fractional cents are important to you, beware the inexactness of FP math and consider using scaled integers instead)
Well, unless he's using another variable for the end result of the If...Then statement. dblComm, or X, or something else. I'm assuming he's retaining the same intSales variable for a finalized result. The commas probably won't work - thanks for bringing that to light. 100000 and 200000 being the alternative, I'm wondering how the input for the initial intSales values are being handled, if they're including commas or not?

Mr. Wednesday
09-29-2004, 01:38 PM
He should be using a different variable for the result, among other things the result will not necessarily be an integer. If the commission is supposed to be in even dollars, then I guess it would work, but the code would be misleading (intSales would only actually represent sales up until the point where you calculate the commission).

Dunno about input, if it's done right I think VB will translate correctly from text to a numeric variable with the commas.

hukarez
09-29-2004, 01:45 PM
The wonders of object oriented programming. ;) Well, to an extent with VB I suppose.

Well, it's not much information to really ride on. Perhaps it's just a minor sub-routine by which another event calls forth the results? Speculation here at this point. I'm assuming things are going well regardless.

I am curious about the end result though. So GoldenEagle, if you've managed to succeed, care to share what you came up with that worked? More so to satiate curiousity on my part really.

Joe
09-29-2004, 01:50 PM
this thread makes my head hurt

Daimyo
09-29-2004, 02:22 PM
I've been using vbscript a lot more than real vb lately, but I think you'd want something like (assuming that since you don't care about cents for the sales that you also don't care about cents for the commision):


function getCommision (iSales as integer) as integer

if (iSales >= 100000) AND (iSales <= 200000) then
getCommision = cInt (0.75 * iSales)
else
'... other code goes here ...
end if

end function

Mr. Wednesday
09-29-2004, 03:07 PM
The wonders of object oriented programming. ;) Well, to an extent with VB I suppose.I don't see that OO has anything to do with this example, which is purely procedural.

:confused:

John Galt
09-29-2004, 03:10 PM
2/3?

hukarez
09-29-2004, 04:25 PM
I don't see that OO has anything to do with this example, which is purely procedural.

:confused:It was a joke. :)

EDIT: Apparently, a bad one!

The Afoci
09-29-2004, 05:15 PM
2/3 my way to Fargo

Time to grease the goat.