Function questions

Started by Frank Brübach, February 27, 2024, 08:38:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Tested this function type Yesterday but Second example doesn't Work


'function fu( a=20 as long, b=22 as long ) as long 'dont go
'function f( byval a=20 as long, byval b=22 as long ) as long ' dont go

'1) go
function fu( byval a as long, byval b as long ) as long 'go
a=20
b=22
function=a+b
end function

print fu(1,2) ' result 42 ok
print "ok1"

'2) dont go
function fu2( byval a=20 as long, byval b=22 as long ) as long 'no go?
function=a+b
end function

'print fu2(1,2) 'not ok
print "ok2"

'fu2(b=4)
' dim byref a ' works some years ago too ;)

Now I am Off ;)
  •  

Johan Klassen

try
'2) dont go
function fu2( byval a as long=20, byval b as long=22 ) as long 'no go?
  •  

Charles Pegge

Yes, extending the old QuickBasic function syntax is problematic! Too many words and combinations.

Frank Brübach

#3
Thanks Johan and Charles for Feedback

Charles If you Change a little in programming structure for a Second variable in a function all is working fine

Function fu(Long a=20, Long b=22) AS Long is working nearly correct

See my examples I Had Made five different ways

' oxygen function test new by frank bruebach
'
'function fu(byval a as long=20, byval b as long=22 ) as long 'no go
'function fu( byval a=20 as long, byval b=22 as long ) as long 'no go


' if you are using a function with one variable all is ok
' if you are using a function with two variables there are wrong results
' but code is running ;)
'
'-- 1) ok
function fu( byval a as long, byval b as long ) as long 'go
a=20
b=22
function=a+b
end function

print fu(1,2) '42

'-- 2) go ! but wrong result
function fu( long a=20, long b=22 as long ) as long 'go
function=a+b
end function

'print fu(1,2) '42 ' ok
print fu(2,4) '42 'wrong result

'-- 3)
function xy( byval x as long, byval y as long) as long 'go
x=2024 : y = 365
function = x*y
end function

print xy(2,4) '738760

'-- 4)
function xy(long x=2024, long y=365) as integer ' not really go
function = 100+x*y
end function

print xy(1,2) '102 'wrong result: should be 738760


'-- 4)
function abc(long d=20) as integer 'go
function = d*100
end function

print abc(4) '400 ok

'-- 5)
function abc(long d=20, long e=40) as integer 'not really go
function = d*e+100
end function

print abc(4,8) '132 wrong result


  •  

Charles Pegge

Hi Frank,

Your last example works correctly, I use this format a lot :)

function abc(long d=20, long e=40) as integer 'not really go
function = d*e+100
end function

print abc(4,8) '132
print abc(4) '260
print abc() '900