Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FUNCTION Event(x AS DOUBLE) AS DOUBLE
#1
Before creating a function I normally would Dimension x as Double BEFORE I actually call the function. For example

Dim x as Double
...code..
...code..

x = Event
...
Function Event(x)
...code...
End Function

But, dimensioning on an "as needed basis" or "on the run" what is the correct syntax

Function Event (x as Double) as Double or Function Event(x) as Double or Function Event (x as Double)??

It's hard to give up on the old ways, if they worked, to learn a new more efficient way. (by efficient I mean to reduce all those Dim Shared variables I have at the beginning of my code to only creating them when they are actually called for service.
Reply
#2
(01-26-2024, 04:17 PM)Dimster Wrote: . . .
Function Event (x as Double) as Double or Function Event(x) as Double or Function Event (x as Double)??

It's hard to give up on the old ways, if they worked, to learn a new more efficient way. (by efficient I mean to reduce all those Dim Shared variables I have at the beginning of my code to only creating them when they are actually called for service.
I don't really understand what you actually want. . .  Huh

Code: (Select All)

'Declaration
Declare Function Endpreis(kaufpreis, mehrwertSteuer As Double) As Double

. . . Code

'Definition
Function Endpreis (kaufpreis, mehrwertSteuer As Double)

  Dim As Double gesamtpreis

  gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
  Endpreis = gesamtpreis
End Function
Reply
#3
Are you looking for:

FUNCTION Event# (x AS DOUBLE)

The # after the name Event denotes it as returning a double value back to us.  Wink
Reply
#4
Code: (Select All)
PRINT Event

FUNCTION Event# (x AS DOUBLE)

    'code here
    Event = 1000

END FUNCTION
.
You can't declare a function AS DOUBLE, you must instead use the type identifier as shown above.

Update: Steve beat me to it my mere seconds Smile
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#5
That where I've  missed the boat - the correct syntax is 
FUNCTION Event#(x as double)
Thank you
Reply




Users browsing this thread: 1 Guest(s)