Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Simple Calculation


Hi,

becouse I newbie this question might sound little stupid :)

In VBA I created UserForm where I inserted three TextBoxes:
- TextSkupajDDV
- TextBrezDDV
- TextSkupajZDDV

I created formula that would check if the statemant is right:

Private Function IzracunDDV()

If (TextSkupajDDV + TextBrezDDV= TextSkupajZDDV) Then
IzracunDDV = False
Exit Function
End If

Application.ScreenUpdating = True
IzracunDDV = True
End Function


Can you please tell me what I did wrong, becouse it is not currect :(


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Simple Calculation

Hi,

what are you trying to test?

In your code you basically are saying this:

If textbox1 + textbox 2 = textbox1 then ...

this test will only return true if either textbox 1 or textbox 2 are empty
(of it they're numeric, equal to zero)

are you trying to see if one is empty?

HTH

Philip

"Lucifix" wrote:


Hi,

becouse I newbie this question might sound little stupid :)

In VBA I created UserForm where I inserted three TextBoxes:
- TextSkupajDDV
- TextBrezDDV
- TextSkupajZDDV

I created formula that would check if the statemant is right:

Private Function IzracunDDV()

If (TextSkupajDDV + TextBrezDDV= TextSkupajZDDV) Then
IzracunDDV = False
Exit Function
End If

Application.ScreenUpdating = True
IzracunDDV = True
End Function


Can you please tell me what I did wrong, becouse it is not currect :(


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Simple Calculation


I would like check if formula is correct:
If textbox1 + textbox 2 = textbox1 then ...
If 2 + 1 = 3 then...

Thank you.


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Simple Calculation

Hi,

Well, then you need code like this:

if textbox1 + textbox2 = textbox3 then ...

NOT

if textbox1+textbox2=textbox1

you were testing the values of 2 textboxes againts one of them - this will
NEVER be correct unless one of the textboxes is empty or =0 !

HTH

Philip

"Lucifix" wrote:


I would like check if formula is correct:
If textbox1 + textbox 2 = textbox1 then ...
If 2 + 1 = 3 then...

Thank you.


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Simple Calculation


But what is different then this:

Private Function IzracunDDV() As Boolean

If TextSkupajDDV + TextBrezDDV = TextSkupajZDDV Then
IzracunDDV = False
Exit Function
End If

Application.ScreenUpdating = True
IzracunDDV = True
End Function

Lets say that I would like to insert in fields:
TextSkupajDDV - 2
TextBrezDDV - 1
TextSkupajZDDV - 3

This function will say that this is not correct, which isn't true.
2 + 1 = 3

What would be right function then?

Thank you for helping me.
Lucifi

--
Lucifi
-----------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...fo&userid=2917
View this thread: http://www.excelforum.com/showthread.php?threadid=49545



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Simple Calculation

Try
CODE
Private Function IzracunDDV() As Boolean

If VBA.CInt(TextSkupajDDV.Value) _
+ VBA.CInt(TextBrezDDV.Value) = VBA.CInt(TextSkupajZDDV.Value) Then
IzracunDDV = True
Exit Function
End If

Application.ScreenUpdating = True
IzracunDDV = False
End Function
<<<< END CODE

to check that 3 numbers are the same you need to force them to be numbers.

The default property of a textbox is the Text property, so in fact, if you
don't get the Value property explicitly, then the test you are performing is
like this:

text1 + text2 = "12"

is "12" = "3"

answer, FALSE

But if you take the textbox value property (which is still a string BTW)
then cast it to an integer using CINT then you get this test:

1 +3 = 3

One more thing, you are returning "IzracunDDV = False" if the condition is
found to be true - is that correct?

HTH

Philip
"Lucifix" wrote:


But what is different then this:

Private Function IzracunDDV() As Boolean

If TextSkupajDDV + TextBrezDDV = TextSkupajZDDV Then
IzracunDDV = False
Exit Function
End If

Application.ScreenUpdating = True
IzracunDDV = True
End Function

Lets say that I would like to insert in fields:
TextSkupajDDV - 2
TextBrezDDV - 1
TextSkupajZDDV - 3

This function will say that this is not correct, which isn't true.
2 + 1 = 3

What would be right function then?

Thank you for helping me.
Lucifix


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Calculation Not Working JDM Excel Discussion (Misc queries) 2 August 30th 07 04:02 PM
PLEASE HELP--going crazy with a simple calculation diane Excel Worksheet Functions 3 November 14th 05 06:42 PM
Need help with a simple Time calculation Bjarne Hansen Excel Worksheet Functions 3 August 1st 05 03:21 PM
Need help with a simple Time calculation Bjarne Hansen Excel Discussion (Misc queries) 3 August 1st 05 08:22 AM
error in simple calculation? Tobias Excel Discussion (Misc queries) 4 March 4th 05 01:27 PM


All times are GMT +1. The time now is 05:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"