howto with function, if possible.

Just starting out? Need help? Post your questions and find answers here.
hugblue
New User
New User
Posts: 6
Joined: Tue Oct 11, 2022 12:24 pm

howto with function, if possible.

Post by hugblue »

Hi ..

this :

Code: Select all

; Define the function
Function Multiply(x.i, y.i)
  Multiply = x * y
EndFunction

; Define a result variable
Define result.i

; Call the function
result = Multiply(5, 6)
Debug result
is not working.

Are there anyway to make it work in a equal way.

Thanks
ebs
Enthusiast
Enthusiast
Posts: 556
Joined: Fri Apr 25, 2003 11:08 pm

Re: howto with function, if possible.

Post by ebs »

You need to get some of the PureBasic "basics" down:

1. PB has Procedures, not Functions.
2. If you want to return a value from a Procedure, you need a ProcedureReturn statement.

Code: Select all

; Define the function
Procedure Multiply(x.i, y.i)
  Multiply = x * y
  ProcedureReturn Multiply
EndProcedure
ebs
Enthusiast
Enthusiast
Posts: 556
Joined: Fri Apr 25, 2003 11:08 pm

Re: howto with function, if possible.

Post by ebs »

Is this a real post or a bot???
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: howto with function, if possible.

Post by juergenkulow »

Code: Select all

; .d for 8 Byte double - .f for 4 Byte float 
Procedure.d Multiply(x.d, y.d) : ProcedureReturn x*y : EndProcedure
Debug Multiply(47.11,47.12)
; 2219.8231999999998151906765997
Documentation Procedures
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: howto with function, if possible.

Post by Tenaja »

ebs wrote: Thu Dec 22, 2022 3:41 pm Is this a real post or a bot???
Probably a bot, since it was the first post.
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Re: howto with function, if possible.

Post by Saboteur »

I told ChatGPT, three times, purebasic has no functions. Perhaps it is here to confirm it. xD
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: howto with function, if possible.

Post by STARGÅTE »

To run this code in an equal way, you need to define two macros, Function and EndFunction:

Code: Select all

Macro Function
	Procedure
EndMacro
Macro EndFunction
	ProcedureReturn Multiply
	EndProcedure
EndMacro

; Define the function
Function Multiply(x.i, y.i)
  Multiply = x * y
EndFunction

; Define a result variable
Define result.i

; Call the function
result = Multiply(5, 6)
Debug result
In this age, our job is to prevent AI become too smart. Otherwise, Skynet, V.I.K.I. or Ava are not far away ...
... the technological singularity will come, we should delay them as long as we can.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: howto with function, if possible.

Post by mk-soft »

n this age, our job is to prevent AI become too smart. Otherwise, Skynet, V.I.K.I. or Ava are not far away ...
... the technological singularity will come, we should delay them as long as we can.

Destroy Commander Data
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: howto with function, if possible.

Post by skywalk »

Embrace the benevolent AI.
It is illogical for it to bring much harm.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
hugblue
New User
New User
Posts: 6
Joined: Tue Oct 11, 2022 12:24 pm

Re: howto with function, if possible.

Post by hugblue »

Hi all ..

Yep. Its my first post.
And im not a bot.

And yes i use ChatGPT.
It kept saying there are functions.

So i just wanted to be sure.
Looked in the manual first.
Then i came here.

And i do know about procedures.

Thanks all.
Last edited by hugblue on Thu Dec 22, 2022 10:15 pm, edited 1 time in total.
hugblue
New User
New User
Posts: 6
Joined: Tue Oct 11, 2022 12:24 pm

Re: howto with function, if possible.

Post by hugblue »

STARGÅTE wrote: Thu Dec 22, 2022 6:11 pm To run this code in an equal way, you need to define two macros, Function and EndFunction:

Code: Select all

Macro Function
	Procedure
EndMacro
Macro EndFunction
	ProcedureReturn Multiply
	EndProcedure
EndMacro

; Define the function
Function Multiply(x.i, y.i)
  Multiply = x * y
EndFunction

; Define a result variable
Define result.i

; Call the function
result = Multiply(5, 6)
Debug result
In this age, our job is to prevent AI become too smart. Otherwise, Skynet, V.I.K.I. or Ava are not far away ...
... the technological singularity will come, we should delay them as long as we can.
Thanks alot. :-)
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: howto with function, if possible.

Post by BarryG »

hugblue wrote: Thu Dec 22, 2022 10:11 pmAnd yes i use ChatGPT.
It kept saying there are functions.
ChatGPT is not tech support for PureBasic. Don't believe what it says; it's not always correct.

I asked ChatGPT to tell me about one of my own apps, and it was 100% wrong. Said it was Registry cleaner, which I assume is because my website mentions the word Registry on it. It also said my app runs on all versions of Windows, when my website clearly says Win 7 and later. I could go on about its other errors, but won't.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: howto with function, if possible.

Post by idle »

I feel like I ate one to many cookies reading this thread.
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: howto with function, if possible.

Post by jacdelad »

Why are people so obsessed with these "AIs" anyway? Until now it's almost all fraud and hidden google search. Alexa is not an AI, ChatGPT is not an AI all other products that claim to be an AI aren't.
There may be real AIs, but these are definitely locked behind lab doors. All others are toys.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Little John
Addict
Addict
Posts: 4773
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: howto with function, if possible.

Post by Little John »

hugblue wrote: Thu Dec 22, 2022 10:11 pm Looked in the manual first.
Then i came here.

And i do know about procedures.
You know about procedures?
And what did you read in the manual about functions?
Post Reply