AI output coding for purebasic

Just starting out? Need help? Post your questions and find answers here.
moricode
User
User
Posts: 94
Joined: Thu May 25, 2023 3:55 am

AI output coding for purebasic

Post by moricode »

Will the output code work ?


ask: show me a simple example of purebasic GUI app

Anw:
Sure, here is a simple example of a GUI application written in PureBasic:

Code: Select all

#Include once /gui.incl.pbi

Procedure Main()
 ; Create the main window
  OpenWindow(0, "Hello, World!", 100, 100, 300, 200)

 ; Create a button
  CreateObject("PBGuiButton", button)
  button.Caption = "Click me!"
  button.Width = 100
  button.Height = 30
  button.Left = 120
  button.Top = 80
  button.OnClick = Procedure("ButtonClicked.pbi")
  AddGuiControl(WindowHandle(0), button)

  ; Run the message loop
  RunEventLoop()
EndProcedure

Procedure ButtonClicked()
  MessageRequester("Hello, World!", "You clicked the button!")
EndProcedure

This code creates a simple GUI application with a single button. When the button is clicked, it displays a message box with the text "You clicked the button!".To run this code, you will need to have PureBasic installed on your computer. You can then save the code to a file with a .pb extension, such as "hello_world.pb", and open it in PureBasic. When you run the code, it will display the GUI application.I hope this helps! Let me know if you have any questions.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: AI output coding for purebasic

Post by Rinzwind »

Of course not, as is the case frequently with its make up stuff and API's every time you ask something that's not readily answered on the inet.
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: AI output coding for purebasic

Post by STARGÅTE »

moricode wrote: Wed Feb 21, 2024 4:55 am Will the output code work ?
No, because it is no Pure Basic code, it is just trash.
  • "IncludeFile" has to be used to include files, not "#Include once"
  • OpenWindow() has a wrong oder of arguments (see documentation)
  • button.Caption, button.Width, etc. is no Pure Basic syntax. In Pure Basic it should be like button\Width
  • "Procedure" cannot be used in an assignment of a variable (button.OnClick).
  • WindowHandle(), RunEventLoop(), etc. don't exist
  • Main() is not executed
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
jacdelad
Addict
Addict
Posts: 1478
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: AI output coding for purebasic

Post by jacdelad »

Why did you not try to run it? Question answered.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
ricardo_sdl
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 21, 2019 4:24 pm

Re: AI output coding for purebasic

Post by ricardo_sdl »

Which model did you use to create the code? Chat-gpt 2.5?
You can check my games at:
https://ricardo-sdl.itch.io/
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

Re: AI output coding for purebasic

Post by BillBoard_67 »

Hi,

I think it's ChatGPT 0.0.1 :)
ricardo_sdl
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 21, 2019 4:24 pm

Re: AI output coding for purebasic

Post by ricardo_sdl »

:lol:
I meant chatgpt-3.5.
You can check my games at:
https://ricardo-sdl.itch.io/
moricode
User
User
Posts: 94
Joined: Thu May 25, 2023 3:55 am

Re: AI output coding for purebasic

Post by moricode »

This was using https://groq.com/
very fast response compare to ChatGPT 3.5

no matter which model , all social media was bla bla that "AI is very smart and going to replace human works" and all people worries about that , they claim AI generated code can be directly RUN/Compiled without errors , is it true ? i doubt it , event Copilot can get code direct compiled without error .
KosterNET
User
User
Posts: 30
Joined: Tue Mar 22, 2016 10:08 pm

Re: AI output coding for purebasic

Post by KosterNET »

This is exactly the same question for ChatGPT4:

Me : show me a simple example of purebasic GUI app

ChatGPT (4):
Here's a simple example of creating a graphical user interface (GUI) application in PureBasic. This example demonstrates how to create a window that lists file properties within a specified directory. It makes use of several GUI elements such as windows, text gadgets, and list icon gadgets to display the file information. The application also includes an event loop to handle user interactions, such as closing the window.

Code: Select all

; Define the structure for file information
Structure FILEITEM
  Name.s
  Attributes.i
  Size.q
  DateCreated.i
  DateAccessed.i
  DateModified.i
EndStructure

; Constants to identify the window and controls
Enumeration
  #WindowFiles
EndEnumeration

Enumeration
  #Folder
  #Files
EndEnumeration

; Define a list of files using the structure
NewList Files.FILEITEM()

; Define variables for GUI event handling
Define .s Access, Attrib, Create, Folder, Modify, Msg, Num, Size
Define .l Result, Flags
Define .l Event, EventWindow, EventGadget, EventType, EventMenu

; Get the home directory for the logged on user
Folder = GetHomeDirectory()

; Open the directory to enumerate its contents
Result = ExamineDirectory(0, Folder, "*.*")

; Begin enumeration of entries if successful
If Result
  While NextDirectoryEntry(0)
    If DirectoryEntryType(0) = #PB_DirectoryEntry_File
      AddElement(Files())
      Files()\Name = DirectoryEntryName(0)
      Files()\Size = DirectoryEntrySize(0)
      Files()\Attributes = DirectoryEntryAttributes(0)
      Files()\DateCreated = DirectoryEntryDate(0, #PB_Date_Created)
      Files()\DateAccessed = DirectoryEntryDate(0, #PB_Date_Accessed)
      Files()\DateModified = DirectoryEntryDate(0, #PB_Date_Modified)
    EndIf
  Wend
  FinishDirectory(0)
EndIf

; Sort the list into ascending alphabetical order of file name
SortStructuredList(Files(), #PB_Sort_Ascending, OffsetOf(FILEITEM\Name), #PB_String)

; Define flags for the window attributes
Flags = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar

; Open a GUI window
OpenWindow(#WindowFiles, 50, 50, 450, 400, "File Properties", Flags)

; Create a text gadget to show the name of the folder
TextGadget(#Folder, 5, 40, 440, 25, Folder)

; Create a list icon gadget to hold the file list and properties
ListIconGadget(#Files, 5, 70, 440, 326, "#", 35)

; Add columns to the ListIconGadget for each property
AddGadgetColumn(#Files, 1, "Name", 200)
AddGadgetColumn(#Files, 2, "Created", 100)
AddGadgetColumn(#Files, 3, "Accessed", 100)
AddGadgetColumn(#Files, 4, "Modified", 100)
AddGadgetColumn(#Files, 5, "Attributes", 150)
AddGadgetColumn(#Files, 6, "Size", 100)

; Load the files into the list view
ForEach Files()
  Num = StrU(ListIndex(Files()) + 1)
  Create = FormatDate("%dd/%mm/%yyyy", Files()\DateCreated)
  Access = FormatDate("%dd/%mm/%yyyy", Files()\DateAccessed)
  Modify = FormatDate("%dd/%mm/%yyyy", Files()\DateModified)
  Size = StrU(Files()\Size)
  Attrib = StrU(Files()\Attributes)
  Msg = Num + Chr(10) + Files()\Name + Chr(10) + Create + Chr(10) + Access + Chr(10) + Modify + Chr(10) + Attrib + Chr(10) + Size
  AddGadgetItem(#Files, -1, Msg)
Next Files()

; Event loop to handle user interactions
Repeat
  Event = WaitWindowEvent()
  EventWindow = EventWindow()
  EventGadget = EventGadget()
  EventType = EventType()
  Select Event
    Case #PB_Event_Gadget
      If EventGadget = #Folder Or EventGadget = #Files
        ; Handle gadget events here
      EndIf
    Case #PB_Event_CloseWindow
      If EventWindow = #WindowFiles
        CloseWindow(#WindowFiles)
        Break
      EndIf
  EndSelect
ForEver
This code sets up a basic GUI application structure, defining a window with gadgets to display a list of file properties such as name, size, and dates related to creation, access, and modification. It demonstrates how to use structures, lists, and various GUI elements in PureBasic to create an interactive application​​.


=====================================================================================================================
Extra info : I have created a GPT with the Purebasic manual in PDF and the following instructions:

Code: Select all

Purebasic Code Navigator is an expert in Purebasic programming and Azure AD, offering technical assistance with a focus on correct Purebasic syntax and Azure AD support. It provides guidance on Purebasic code structure and syntax, such as using '.s' for string-returning procedures, and detailed advice on Azure AD. The GPT adopts a professional, technical approach, using appropriate jargon. When users request code examples, it always proposes Purebasic code, drawing from the official Purebasic website (https://www.purebasic.fr/english/) and its extensive knowledge source, including a comprehensive Purebasic guide. This ensures that the provided code examples are relevant and accurate. The GPT aims to resolve complex queries with precise and relevant information.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: AI output coding for purebasic

Post by Rinzwind »

Every single time I asked it a solution to something I couldn't find a solution for (yet), it comes up with made up api's or ignores important points. And my reply was sigh and its reply was o sorry you are right, here is another way blablabla and again nonsense pops up. Sometimes you can use a part of its nonsense to get an idea for a solution.

But yeah, those free wheely type of commands It can frequently answer decently based on many examples of source and it knowing the order and grammar. Show example of x. What is x. How to open x.

It stays infuriating polite, just like o so professional help desk, but not helpful. :evil: :o
Bitblazer
Enthusiast
Enthusiast
Posts: 736
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: AI output coding for purebasic

Post by Bitblazer »

Rinzwind wrote: Sat Feb 24, 2024 4:12 am...
+1

But at some point an AI will be able to do small c/c++ snippets and some company will make a huge fuss about it :D

The (currently) unsolved challenge remains, when the first lawyer asks in front of a court "what made the ai come to that suggestion / result / opinion?".

It did probably already happen.

ps: lawyer's are also on a steep AI learning curve
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: AI output coding for purebasic

Post by STARGÅTE »

KosterNET wrote: Fri Feb 23, 2024 8:52 pm This is exactly the same question for ChatGPT4:

Code: Select all

; Define variables for GUI event handling
Define .s Access, Attrib, Create, Folder, Modify, Msg, Num, Size
Define .l Result, Flags
Define .l Event, EventWindow, EventGadget, EventType, EventMenu
This code is good, but still has a major issue: It uses the "old" variable type Long (.i) for some values which are actually Integers (.i)

For example, ExamineDirectory(0, Folder, "*.*") returns a value such as 1738778610688 much larger than a 32-bit Long value, which leads to a truncation to 3611823104.
This will raise bugs and crashing programs, when using ExamineDirectory(#PB_Any) etc.
Similar, the return of EventGadget() can be larger than a 32 bit Long, when creating Gadgets with #PB_Any.

Please correct the code, otherwise the next generation of AI will learn incorrect code from this forum post again.
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
Post Reply