dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] Problems with IF's

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    2

    Resolved [RESOLVED] Problems with IF's

    Okay, I'm working on an OpenOffice macro and I think I've outstayed my welcome posting n00b questions over in the OpenOffice forum so I'll try here.

    Code:
    Sub LogicTest
    	Dim Balance as Double
    	Dim ConstantCheck as Double
    	ConstantCheck = 0
    	ConstantCheck = ConstantCheck - 0.01 
    	Balance = 419.11
    	BalanceInterim = 100
    	TransactionAmnt = 64702
    	
    	if CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt) < 0.01 And CheckWithdrawal(Balance, BalanceInterim, TransacctionAmnt) > ConstantCheck then	
    		msgBox CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt)
    		msgBox "True"
    		msgBox ConstantCheck
    		else 
    		Msgbox "False"
    		msgBox ConstantCheck
    	end if	
    		
    End Sub
    The process call for CheckWithdrawal appears to work perfectly is here:

    Code:
    Function CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt) as Double
    	CheckWithdrawal = Balance - BalanceInterim - TransactionAmnt	
    End Function
    Now I can confirm that Checkwithdrawal returns -64702 which is CLEARLY less than -0.01 but the program continues to return True. I've tried stating -0.01 explicitly rather than the crazy variable method I'm using here...

    Nothing I can think of seems to get this code recognizing that -64702 is WAY outside the range this function should be triggering 'true' msg boxes.
    Last edited by dday9; Apr 21st, 2015 at 01:22 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Problems with IF's

    Planck,

    The best place that I can think of for these types of questions would be the Office Development forum as this appears to be a variant of VBA.

    You have a typo in the code
    Code:
    if CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt) < 0.01 And CheckWithdrawal(Balance, BalanceInterim, TransacctionAmnt) > ConstantCheck then
    I'm also assuming that "TransacctionAmnt" should have been "TransactionAmnt".

    Let's rewrite this a bit to improve its maintainability a bit.

    Code:
    Dim checkBalance as Double
    checkBalance = CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt)
     if (checkBalance < 0.01) And (checkBalance > ConstantCheck) Then

  3. #3
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Problems with IF's

    First thing that you should always do... Set Option Strict to On. Were you to have done this, you'd have seen the error... It is on the line:
    Code:
    if CheckWithdrawal(Balance, BalanceInterim, TransactionAmnt) < 0.01 And CheckWithdrawal(Balance, BalanceInterim, TransacctionAmnt) > ConstantCheck then
    The second call to CheckWithdrawal uses "TransacctionAmnt" which has not been defined (the name has an extra 'c' in it), so without Option Strict, this variable will be declared and initialized to 0 causing the function to evaluate to 319.11 > 0.01 which makes both parts of the condition to be true.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    2

    Re: Problems with IF's

    The best place that I can think of for these types of questions would be the Office Development forum as this appears to be a variant of VBA.
    Probably, I wasn't sure because Open Office's VB is based on the OpenOffice API rather than being strictly VBA.

    I'm also assuming that "TransacctionAmnt" should have been "TransactionAmnt".
    Kremmit. I'm going to go ahead and blame this on working off a 14" CRT monitor.

    First thing that you should always do... Set Option Strict to On. Were you to have done this, you'd have seen the error... It is on the line:
    I'll definitely look into this, though since it is through OpenOffice I'm not sure if it's available/supported.

    Thanks for the proof-read though, I don't know how I missed that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width