QB64 Phoenix Edition
has anyone had ChatGPT write QB64 code yet? - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2)
+--- Thread: has anyone had ChatGPT write QB64 code yet? (/showthread.php?tid=1281)



has anyone had ChatGPT write QB64 code yet? - madscijr - 12-15-2022

Apparently somebody tried to get it to write a game for the Atari VCS, so why not try BASIC? The results could be amusing! LoL

https://www.reddit.com/r/Atari2600/comments/zm4ryu/i_asked_chatgpt_to_write_a_game_for_the_atari/


RE: has anyone had ChatGPT write QB64 code yet? - vince - 12-15-2022

I've heard team official got a hold of this tech, "I demand qb64pe but better!"


RE: has anyone had ChatGPT write QB64 code yet? - SpriggsySpriggs - 12-15-2022

ChatGPT scares me. That thing was built too well.


RE: has anyone had ChatGPT write QB64 code yet? - madscijr - 12-16-2022

(12-15-2022, 09:54 PM)Spriggsy Wrote: ChatGPT scares me. That thing was built too well.

I gave it a try! 

If you ask: 

Code: (Select All)
Can you write a program in QuickBasic that implements an associative array?


It outputs:

Code: (Select All)
Sure! Here is a simple program in QuickBasic that implements an associative array:

' Declare a type for the associative array
TYPE AssociativeArray
    Key AS STRING * 10
    Value AS STRING * 10
END TYPE

' Declare an array of the associative array type
DIM AssociativeArrayList(1 TO 10) AS AssociativeArray

' Set some key-value pairs in the array
AssociativeArrayList(1).Key = "Key1"
AssociativeArrayList(1).Value = "Value1"

AssociativeArrayList(2).Key = "Key2"
AssociativeArrayList(2).Value = "Value2"

AssociativeArrayList(3).Key = "Key3"
AssociativeArrayList(3).Value = "Value3"

' Print the value for a given key
PRINT GetValueForKey("Key2", AssociativeArrayList)

SUB GetValueForKey(Key AS STRING, AssociativeArrayList() AS AssociativeArray) AS STRING
    ' Loop through the array and return the value for the given key
    FOR i = 1 TO 10
        IF AssociativeArrayList(i).Key = Key THEN
            GetValueForKey = AssociativeArrayList(i).Value
            EXIT SUB
        END IF
    NEXT
END SUB

This program declares a type called AssociativeArray that has two fields: Key and Value. It then declares an array of this type called AssociativeArrayList. The array is initialized with three key-value pairs, and a function called GetValueForKey is defined to search the array and return the value for a given key.

To use the associative array, you can call the GetValueForKey function and pass in the key that you want to look up, along with the array. In this example, calling GetValueForKey("Key2", AssociativeArrayList) will return the string "Value2".

This is just a simple example of how an associative array can be implemented in QuickBasic. There are many other ways to implement this type of data structure, and you may want to modify the code to suit your specific needs.

Next might be to ask it to optimize performance with hashing, or add functions for insert/update/delete/sort, etc. 

Maybe it will choke, maybe it will surprise us! Maybe it will answer differently in a month or a year, having learned more stuff from people and off the Internet.


RE: has anyone had ChatGPT write QB64 code yet? - madscijr - 12-16-2022

(12-16-2022, 05:53 AM)madscijr Wrote:
(12-15-2022, 09:23 PM)vince Wrote: I've heard team official got a hold of this tech, "I demand qb64pe but better!"
(12-15-2022, 09:54 PM)Spriggsy Wrote: ChatGPT scares me. That thing was built too well.
...
Next might be to ask it to optimize performance with hashing, or add functions for insert/update/delete/sort, etc. 
Maybe it will choke, maybe it will surprise us! Maybe it will answer differently in a month or a year, having learned more stuff from people and off the Internet.

I went ahead and asked:

Code: (Select All)
Can you do that again, but also optimize performance with hashing, and add functions for insert / update / delete / exists / sort?

And lo! It did just that!

Code: (Select All)
Sure! Here is a revised version of the QuickBasic program that implements an associative array using hashing to optimize performance, and includes functions for inserting, updating, deleting, and checking the existence of key-value pairs, as well as a function for sorting the array:

' Declare a type for the associative array
TYPE AssociativeArray
    Key AS STRING * 10
    Value AS STRING * 10
    Hash AS INTEGER
END TYPE

' Declare an array of the associative array type
DIM AssociativeArrayList(1 TO 10) AS AssociativeArray

' Set the size of the array (the number of key-value pairs it can hold)
DIM ArraySize AS INTEGER
ArraySize = 10

' Insert a new key-value pair into the array
SUB InsertKeyValuePair(Key AS STRING, Value AS STRING, AssociativeArrayList() AS AssociativeArray)
    ' Calculate the hash for the key
    Hash = GetHash(Key)

    ' Find an empty slot in the array
    FOR i = 1 TO ArraySize
        IF AssociativeArrayList(i).Key = "" THEN
            ' Insert the key-value pair into the array
            AssociativeArrayList(i).Key = Key
            AssociativeArrayList(i).Value = Value
            AssociativeArrayList(i).Hash = Hash
            EXIT SUB
        END IF
    NEXT
END SUB

' Update the value for a given key in the array
SUB UpdateKeyValuePair(Key AS STRING, Value AS STRING, AssociativeArrayList() AS AssociativeArray)
    ' Calculate the hash for the key
    Hash = GetHash(Key)

    ' Find the key-value pair with the matching key
    FOR i = 1 TO ArraySize
        IF AssociativeArrayList(i).Key = Key THEN
            ' Update the value for the key
            AssociativeArrayList(i).Value = Value
            EXIT SUB
        END IF
    NEXT
END SUB

' Delete a key-value pair from the array
SUB DeleteKeyValuePair(Key AS STRING, AssociativeArrayList() AS AssociativeArray)
    ' Find the key-value pair with the matching key
    FOR i = 1 TO ArraySize
        IF AssociativeArrayList(i).Key = Key THEN
            ' Delete the key-value pair by clearing its fields
            AssociativeArrayList(i).Key = ""
            AssociativeArrayList(i).Value = ""
            AssociativeArrayList(i).Hash = 0
            EXIT SUB
        END IF
    NEXT
END SUB

' Check if a key exists in the array
FUNCTION KeyExists(Key AS STRING, AssociativeArrayList() AS AssociativeArray) AS BOOLEAN
    ' Find the key-value pair with the matching key
    FOR i = 1 TO ArraySize
        IF AssociativeArrayList(i).Key = Key THEN
            KeyExists = TRUE
            EXIT FUNCTION
        END IF
    NEXT

    KeyExists = FALSE
END FUNCTION

' Sort the array by key
SUB SortArray(AssociativeArrayList() AS AssociativeArray)
    ' Use bubble sort to sort the array
    FOR i = 1 TO ArraySize - 1
        FOR j = i + 1 TO ArraySize
            IF AssociativeArrayList(i).Key >

But wait... where's the rest? Th-th-that's all, folks?! 
Is there a limit to the output? Where's the beef??? 

Code: (Select All)
can you show the rest of the program?

Ask and you shall receive!

Code: (Select All)
Certainly! Here is the rest of the revised QuickBasic program that implements an associative array using hashing to optimize performance, and includes functions for inserting, updating, deleting, and checking the existence of key-value pairs, as well as a function for sorting the array:

AssociativeArrayList(j).Key THEN
                ' Swap the key-value pairs
                Temp = AssociativeArrayList(i)
                AssociativeArrayList(i) = AssociativeArrayList(j)
                AssociativeArrayList(j) = Temp
            END IF
        NEXT
    NEXT
END SUB

' Calculate the hash for a given key
FUNCTION GetHash(Key AS STRING) AS INTEGER
    Hash = 0

    ' Calculate the hash by adding up the ASCII values of the characters in the key
    FOR i = 1 TO LEN(Key)
        Hash = Hash + ASC(MID$(Key, i, 1))
    NEXT

    GetHash = Hash
END FUNCTION

' Print the value for a given key
PRINT GetValueForKey("Key2", AssociativeArrayList)

' Get the value for a given key
FUNCTION GetValueForKey(Key AS STRING, AssociativeArrayList() AS AssociativeArray) AS STRING
    ' Calculate the hash for the key
    Hash = GetHash(Key)

    ' Loop through the array and return the value for the given key
    FOR i = 1 TO ArraySize
        IF AssociativeArrayList(i).Key = Key THEN
            GetValueForKey = AssociativeArrayList(i).Value
            EXIT FUNCTION
        END IF
    NEXT
END FUNCTION

This revised version of the program calculates a hash for each key when it is inserted or updated in the array, and stores the hash along with the key and value in the AssociativeArray type. The GetHash function calculates the hash by adding up the ASCII values of the characters in the key.

The SortArray function uses bubble sort to sort the array by key. The KeyExists function checks if a given key exists in the array by looping through the array and checking if any of the keys match the given key.

The GetValueForKey function searches the array for the key-value pair with the matching key, and returns the value if it is found.

I hope this revised version of the program meets your needs! Let me know if you have any questions or if you need further assistance.

I haven't tried running or looking over the code it spat out yet - it's late and I have to sign off now. 
But it looks legit enough! 

Maybe tomorrow we can try asking it to write some QB64 code. Supposedly it was only "trained" (i.e. allowed to surf the Internet and fill its brain with knowledge) upto 2021, so it wouldn't know that QB64 became QB64PE or that Queen Elizabeth II is no longer with us, but if it can write a QuickBasic program based on a couple sentences, that's pretty cool. Maybe it can figure out that RawInput API multiple mouse problem! LOL


RE: has anyone had ChatGPT write QB64 code yet? - mnrvovrfc - 12-16-2022

This is entirely expected from the son of somebody a lot like Dr. Frankenstein but as ultimate computer programmer deep like an expert Linux user.

I have tried and failed to create a program that builds a song for me. It required too many rules, too much input for me to create and then to feed it, and it did only one style of music. It would have required a lot more work for the project to stop focusing on electronic music -- maybe get it to create a Wiener Waltz, or jazz, or merengue, or maybe something a bit simpler like trap... LOL.

I wasn't patient enough to begin with to work on the input, and then adjusting the project according to the input. Artificial Intelligence could become somebody's lifetime project, but not mine.


RE: has anyone had ChatGPT write QB64 code yet? - mnrvovrfc - 12-16-2022

@madscijr

Let me get this straight.

If the request for a program is "too complex" does this "chatgpt" spit out an incomplete program?

That's a hint that it's futile. I think you've been asking it to do too much. You're posting stuff in code blocks that is difficult to follow along. Better leave it to the chess pieces ROFL or to Snoopy cursing out his own shadow or something like that.

I was going to post in your thread that's current at this time about the subject. "Would you please show the rest of the program?" I thought it was one of your gags.


RE: has anyone had ChatGPT write QB64 code yet? - James D Jarvis - 12-16-2022

I hadn't spotted this thread yet when I posted my results earlier.  It is interesting that as it is a chat program of sorts you have to discuss solutions with the AI.  It'll also cheat and say .... the function "MIXLBLIT"  (as an example) does this  to solve a problem even when the function doesn't exist.  You can certainly get it to elaborate and re-evaluate expressions. I had it acting like Stack.pop() did something in an example and while I was more then capable of implementing a simple stack structure it was interesting to figure out how to tell the chat to fix it.


RE: has anyone had ChatGPT write QB64 code yet? - madscijr - 12-16-2022

(12-16-2022, 10:52 PM)mnrvovrfc Wrote: @madscijr

Let me get this straight.

If the request for a program is "too complex" does this "chatgpt" spit out an incomplete program?

That's a hint that it's futile. I think you've been asking it to do too much. You're posting stuff in code blocks that is difficult to follow along. Better leave it to the chess pieces ROFL or to Snoopy cursing out his own shadow or something like that.

I was going to post in your thread that's current at this time about the subject. "Would you please show the rest of the program?" I thought it was one of your gags.

One of my gags! Big Grin Ha! I don't post too many gags, do I? 

Seriously, you can ask it to show the rest of the code and it will show more. 
(See my newer post about getting it to create a Spacewar game to see that in action!)


RE: has anyone had ChatGPT write QB64 code yet? - madscijr - 12-16-2022

(12-16-2022, 11:11 PM)James D Jarvis Wrote: I hadn't spotted this thread yet when I posted my results earlier.  It is interesting that as it is a chat program of sorts you have to discuss solutions with the AI.  It'll also cheat and say .... the function "MIXLBLIT"  (as an example) does this  to solve a problem even when the function doesn't exist.  You can certainly get it to elaborate and re-evaluate expressions. I had it acting like Stack.pop() did something in an example and while I was more then capable of implementing a simple stack structure it was interesting to figure out how to tell the chat to fix it.

Yeah, it does seem to fudge things a little, and it makes some incorrect assumptions about the language (for instance it thought QB64 has native Boolean and Collection types), but it does seem to write somewhat workable code... (depending on how much extra work you are willing to put in to get it working...)

If you want to see what happens when you really try to push it, see the Spacewar thread!