Forum Discussion
Hi Pakema
Unfortunately, I still don't fully understand what it is you are trying to do. Each of your three functions F1, F2 & F3 essentially do the same thing, they just use different values for the variables a and b. I've just replicated that in a way that works. It looks like your codein F4 is trying to build up a string of code that can be executed by each of the routines, but I can see no reason for you adopting this approach - what am I missing?
Do you know beforehand what the values will be? if so, are you looking to do something like this:
sub F5 dim i dim a, b dim numbers numbers = array(5,6,3,0,4,4) for i = 0 to ubound(numbers) step 2 a = numbers(i) b = numbers(i + 1) call F4(a, b) next end sub
This will essentially replace the F1, F2 & F3 routines as it contains all the values. I've changed the last 2 values so that you can see the final test passes. This example only tests 3 sets of values, but you can add as many sets of values to the array as is necessary.
Again, if this isn't what you're after, please give specific details rather than vague pointers. It's so much easier trying to solve a problem when we know exactly what it is, but hopefully what I've provided above will be of some assistance.
Finally, just looking at your supplied code, you seem to be using 'Exit Function' in each of the three routines F1, F2 and F3, but this isn't necessary since they are not doing any further processing, i.e. they will come to and end anyway. Your routines also only print out an error message to the log if the tests fail, butif a test passes, nothing will be output. My routine simply adds this functionality by stating that the values are equal if ther indeed are. If you don't require this, simply remove the else clause in my F4 routine.
Regards
Stephen.
sbkeenan, oh god
Ok, I try to explain what I want and what I mean
1. I have three function with parameters a, b, c
function f1 (a, b, c) end function ' f1 function f2 (a, b, c) end function ' f2 function f3 (a, b, c) end function ' f3
2. I what check params a, b, c
3, If one of them will be empty I must execute from function, and I check it with another function that has a return value
function f4 (a, b, c) Dim LocalVar_CheckArr Dim LocalVar_IterationCheckArr Dim LocalVar_TmpTxt LocalVar_CheckArr = Array(a, b, c) For LocalVar_IterationCheckArr = 0 To UBound(LocalVar_CheckArr ) LocalVar_TmpTxt = LocalVar_CheckArr(LocalVar_IterationCheckArr) If LocalVar_TmpTxt = "" or IsNull(LocalVar_TmpTxt ) or IsEmpty(LocalVar_TmpTxt ) Then f4 = False Exit function Next f4 = True end function ' f4
4. And in your idea I must dublicate condition THEREE times
function f1 (a, b, c)
If Not f4(a, b, c) Then
Log.Error("Some param was empty")
Exit Function
End If
end function ' f1
function f2 (a, b, c)
If Not f4(a, b, c) Then
Log.Error("Some param was empty")
Exit Function
End If
end function ' f2
function f3 (a, b, c)
If Not f4(a, b, c) Then
Log.Error("Some param was empty")
Exit Function
End If
end function ' f3
function f4 (a, b, c)
Dim LocalVar_CheckArr
Dim LocalVar_IterationCheckArr
Dim LocalVar_TmpTxt
LocalVar_CheckArr = Array(a, b, c)
For LocalVar_IterationCheckArr = 0 To UBound(LocalVar_CheckArr )
LocalVar_TmpTxt = LocalVar_CheckArr(LocalVar_IterationCheckArr)
If LocalVar_TmpTxt = "" or IsNull(LocalVar_TmpTxt ) or IsEmpty(LocalVar_TmpTxt ) Then
f4 = False
Exit function
Next
f4 = True
end function ' f45. But my question is - What I must wrote and do some other that I write just one string?
function f1 (a, b, c)
Execute (f5)
end function ' f1
function f2 (a, b, c)
Execute (f5)
end function ' f2
function f3 (a, b, c)
Execute (f5)
end function ' f3
function f4 (a, b, c)
Dim LocalVar_CheckArr
Dim LocalVar_IterationCheckArr
Dim LocalVar_TmpTxt
LocalVar_CheckArr = Array(a, b, c)
For LocalVar_IterationCheckArr = 0 To UBound(LocalVar_CheckArr )
LocalVar_TmpTxt = LocalVar_CheckArr(LocalVar_IterationCheckArr)
If LocalVar_TmpTxt = "" or IsNull(LocalVar_TmpTxt ) or IsEmpty(LocalVar_TmpTxt ) Then
f4 = False
Exit function
Next
f4 = True
end function ' f4
function f5
dim LocalVar_TmpTxt
dim LocalVar_CharEnter
LocalVar_CharEnter = Chr(13) & Chr(10)
LocalVar_TmpTxt = LocalVar_TmpTxt &_
"If Not f4(a, b, c) Then" & LocalVar_CharEnter &_
"Log.Error(""Some param was empty"")" & LocalVar_CharEnter &_
"Exit Function" & LocalVar_CharEnter &_
"End If"
f5 = LocalVar_TmpTxt
end function ' f5
- sbkeenan10 years agoFrequent Contributor
Hi Pakema
Before attempting to go any further with this one, let's see if I understand what you are trying to do.
You have three variables and you need to check if they all contain a value other than "" or null. Is this correct?
If so, ideally what you want is a single routine that passes these variables to a function, which will test for any of them being "" or null. If any of them are equal to "" or null, then this function returns a boolean false, otherwise, it returns a boolean true. Or, alternatively, it returns a message stating that they all contain values or specifies which ones are "" or null.
Is this what you need?
Regards
Stephen.
- Pakema10 years agoContributor
Hi sbkeenan
You're absolutely right
- sbkeenan10 years agoFrequent Contributor
Hi Pakema
OK! Now that I understand what you are trying to do, how does this look:
sub F5 dim i dim a, b, c dim myArray 'all no a no b no c no b&c no a&c no a&b myArray = array(1,2,3 ,,2,3 ,1,,3 ,1,2, ,1,,, ,2,, ,,3) for i = 0 to ubound(myArray) step 3 a = myArray(i) if i + 1 <= ubound(myArray) then b = myArray(i + 1) else b = null end if if i + 2 <= ubound(myArray) then c = myArray(i + 2) else c = null end if if (F4(a, b, c)) = true then log.Message("All values are present") end if next end sub function F4(a, b, c) dim result result = true if varType(a) = 10 or isNull(a) then log.message("A has no value.") result = false end if if varType(b) = 10 or isNull(b) then log.message("B has no value.") result = false end if if varType(c) = 10 or isNull(c) then log.message("C has no value.") result = false end if F4 = result end functionI must admit I had some difficulty in determining whether an array index is blank, but essentially what this does is reads 3 elements at a time from the array and passed them to the F4 function. Thsi determines whether any of them is missing and reports on that. It also returns a true or false value to the calling routine depending on whether all the elements were present or not.
Hope this helps!!
Regards
Stephen.