Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
has anyone had ChatGPT write QB64 code yet?
#4
(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.
Reply


Messages In This Thread
RE: has anyone had ChatGPT write QB64 code yet? - by madscijr - 12-16-2022, 05:53 AM



Users browsing this thread: 1 Guest(s)