calculation help

linger

New Member
Joined
Mar 26, 2003
Messages
21
hi

is this C++ logic possible in access and if so, how do i implement it without having to code in VB (i haven't figured out how to code in VB and assimilate it into the database yet)

int test,test1,test2;

if(test!=Null & test1!=Null)
test2=test+test1;

else if(test=Null &test1!=Null)
test2=test1;

else if(test1=Null & test!=Null)
test2=test;
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I don't know what the ! (exclamation) means in C++ but the syntax below should work



Private Sub Test()



Dim Test As Integer
Dim test1 As Integer
Dim test2 As Integer


If Test = "" And test1 = "" Then

test2 = Test + test1

ElseIf test1 = "" And Test = "" Then

test2 = test1

ElseIf test1 = "" And Test = "" Then

test2 = Test

End If

End Sub




Ziggy
 
Upvote 0
!= in C++ means not equal to.

uhhmm...so do I just copy and paste this into the macro or do i have to use a VB editor?

thanks
 
Upvote 0
you would paste it into the vb editor, but correct the code where you have the ! exclamation. In VB/sql it is:

<> not equal to
>= greater than or equal to
<= less than or equal to
< less than
> greater than

Dim declares the variable, which in my example is available only to the procedure. to use the variable out side and retain the value declare the procedure as public.

You would want the code to be triggered by an event.




You can also use nested If statement in a query expression (IIF in Access)


iif(test<>Null & test1<>Null,test2=test+test1,iif(test=Null &test1<>Null,
test2=test1,iif(test1=Null & test<>Null,test2=test)))


I didn't test it but it should look something like that.

Ziggy
 
Upvote 0

Forum statistics

Threads
1,221,537
Messages
6,160,401
Members
451,645
Latest member
hglymph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top