Announcement

Collapse
No announcement yet.

Using ChatGPT to write PB code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using ChatGPT to write PB code

    For the most part, this works pretty good. I see it as good tool that will save me time.


    I asked:
    In powerbasic console compiler v6, I have a string variable "starttime" with looks like this "08:00 PM" and I have a numeric value called "totalMinutes". Write the code to add the minutes to 08:00 PM and and show an end time. For instance, if startTime="08:00 PM" and total minutes=90, I want a function that would return "09:30 PM

    and it replied:

    In PowerBASIC Console Compiler v6, you can create a function to add the minutes to the start time and return the end time as follows:

    Code:
    FUNCTION AddMinutesToTime(BYVAL startTime AS STRING, BYVAL totalMinutes AS LONG) AS STRING
    
    LOCAL hour, minute AS LONG
    LOCAL isPM AS STRING
    
    ' Extract hour, minute and AM/PM from the input string
    hour = VAL(LEFT$(startTime, 2))
    minute = VAL(MID$(startTime, 4, 2))
    isPM = RIGHT$(startTime, 2)
    
    ' Check if the given time is in PM, and convert to 24-hour format
    IF isPM = "PM" AND hour <> 12 THEN
    hour = hour + 12
    END IF
    
    ' Add the total minutes
    minute = minute + totalMinutes
    
    ' Adjust the hour and minutes accordingly
    hour = hour + (minute \ 60)
    minute = minute MOD 60
    hour = hour MOD 24
    
    ' Convert back to 12-hour format and set the correct AM/PM indicator
    IF hour >= 12 THEN
    IF hour > 12 THEN hour = hour - 12
    isPM = "PM"
    ELSE
    IF hour = 0 THEN hour = 12
    isPM = "AM"
    END IF
    
    ' Format the resulting time string and return it
    FUNCTION = FORMAT$(hour, "00") & ":" & FORMAT$(minute, "00") & " " & isPM
    
    END FUNCTION
    Now you can use this function to add minutes to a given start time:

    Code:
    FUNCTION PBMAIN () AS LONG
    DIM startTime AS STRING
    DIM totalMinutes AS LONG
    DIM endTime AS STRING
    
    startTime = "08:00 PM"
    totalMinutes = 90
    
    endTime = AddMinutesToTime(startTime, totalMinutes)
    
    PRINT "Start Time: " & startTime
    PRINT "End Time: " & endTime
    
    END FUNCTION
    ​
    ​
    I'm mostly impressed by how it understood my question.
    Yes, I could have figured this out myself but I think it's a fine illustration on AI's usefulness in programming.

  • #2
    Yes, I could have figured this out myself but I think it's a fine illustration on AI's usefulness in programming.
    If you could have figured this out yourself, you would probably have used the AddMinutes method of the PowerTime object when you read the doc.

    Maybe AI ain't so smart after all.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      maybe...
      "Hey AI: read the PB docs and do it a better way"...
      now I'm curious

      Comment


      • #4
        "redo the example using the powertime object"

        "Certainly! You can use the PowerTime object in PowerBASIC Console Compiler v6 to manipulate time more efficiently. Here's the modified version of the example using the PowerTime object:"

        Code:
        #INCLUDE "ptime.inc"
        
        FUNCTION AddMinutesToTime(BYVAL startTime AS STRING, BYVAL totalMinutes AS LONG) AS STRING
        LOCAL ptStartTime, ptEndTime AS PowerTime
        LOCAL endTime AS STRING
        
        ' Convert the input string to PowerTime
        ptStartTime = PARSE(startTime, "hh:mm tt")
        
        ' Add the total minutes
        ptEndTime = ptStartTime + (totalMinutes * 60)
        
        ' Format the resulting time string
        endTime = FORMAT$(ptEndTime, "hh:mm tt")
        
        FUNCTION = endTime
        END FUNCTION
        ​
        c'mon man that's pretty neat

        Comment


        • #5
          It is absolutely neat and your earlier point about saving time is spot on. I heard a brief segment on NPR that mentioned a study where AI was providing information to call center agents and found that in aggregate it improved the expertise of low-skilled workers to perform at a higher level and also more efficiently. I think your post is an example of time savings for sure!
          Donnie Ewald
          [email protected]

          Comment


          • #6
            ???????????
            Do you even have PB Help?
            Just for one see PARSE. Syntax not close at all.
            ???????????
            Dale

            Comment


            • #7
              What is
              . . . is absolutely neat . . .
              ??

              From post 2
              Maybe AI ain't so smart after all.
              Not only the AI seems lacking.
              Dale

              Comment


              • #8
                Be aware that so called AI is actually quite stupid. It is a data engine. It finds things online and passes them back to you to best answer your question. But is AI really intelligent ? Absolutely not.

                Spent a little time with Googles AI called Bard. Asked it simple questions about a person which has an online presence. I can tell it is simply grabbing anything it can find online which it thinks may answer the questions. It made terrible mistakes. I informed it of the correct answers and it thanked me. When I asked the question again and again it made even worse mistakes. It took my replies and knew it was wrong, but in an effort to seek out more info to fill in the blanks it provided even more erroneous information.

                Now if an AI makes those kind of mistakes, imagine the errors it will make with code. Most likely the AI's are browsing the web for code examples and using that for its answers. To actually write code totally from scratch and actually know what it is doing is not an easy task and as long as AI is data oriented rather than actually think, it is a dangerous tool to use for coding.

                Modern AI is not like the talking computers we see in science fiction. They are based on algorithms and not an actual intelligence. They don't really learn like we do. Computers do not understand the nuances of human language like we do.
                Chris Boss
                Computer Workshop
                Developer of "EZGUI"
                http://cwsof.com
                http://twitter.com/EZGUIProGuy

                Comment


                • #9
                  Post 1
                  works but not efficient

                  Post 4
                  is wrong in many ways, not really using Powertime, and using Parse wrong.
                  a great example of AI hallucinations.

                  ChatGPT is not a brain people keep using it as a know it all but it's not meant to be. It's a Chat simulator and it does that very well, chat in humanly very convincing way, but when it comes to facts and actual content it has a tendency to pointlessly embed plausible-sounding random falsehoods​. So you need to already know the answer to know if its lying to you.

                  Comment


                  • #10
                    Originally posted by Shawn Anderson View Post
                    "redo the example using the powertime object"

                    "Certainly! You can use the PowerTime object in PowerBASIC Console Compiler v6 to manipulate time more efficiently. Here's the modified version of the example using the PowerTime object:"

                    Code:
                    #INCLUDE "ptime.inc"
                    ​
                    c'mon man that's pretty neat
                    No, that's absolutely useless and the fact that you think it is "pretty neat" a prime example of the dangers of engines like ChatGPT.

                    Ask it to generate ptime.inc for you since it is not a PB component. I'd be intered in seeing what it comes up with.

                    Apart from that, not one of the three codes lines are even close to correct PB code. You can't use either PARSE or a PowerTime object like that.

                    Comment


                    • #11
                      Hmm. Had to try three times before it gave me any code with ain inc file. Finally it gave me PowerTime.inc.
                      According to ChapGPT:
                      "PowerTime.inc is a file that contains the definitions and declarations necessary to use the PowerTime object in PowerBASIC Console Compiler. It is provided by PowerBASIC as part of the PowerBASIC Console Compiler distribution​."

                      and
                      "Here's an example of what the PowerTime.inc file might look like:​"

                      Code:
                      ' PowerTime.inc
                      ' Declarations and definitions for the PowerTime class
                      
                      ' Declare the PowerTime class
                      CLASS PowerTime
                      
                          ' Constructor methods
                          CLASS METHOD PowerTime () ' Default constructor
                          END METHOD
                          
                          CLASS METHOD PowerTime (hours AS LONG, minutes AS LONG, seconds AS LONG) ' Constructor with parameters
                          END METHOD
                          
                          ' Properties
                          PROPERTY Hours() AS LONG
                          PROPERTY Minutes() AS LONG
                          PROPERTY Seconds() AS LONG
                          
                          ' Methods
                          METHOD AddMinutes(minutesToAdd AS LONG) AS PowerTime
                          METHOD ToString(format AS STRING) AS STRING
                      
                          ' Static methods
                          CLASS METHOD TimeValue(hours AS LONG, minutes AS LONG, seconds AS LONG) AS PowerTime
                      
                      END CLASS

                      As you can see, this file declares the PowerTime class, which has several methods and properties for working with time values. The file also defines the implementation of the class methods, which is what enables you to use them in your program.

                      By including the PowerTime.inc file in your program, you can use the PowerTime class to create and manipulate time values with ease."


                      IOW - Absolute, errant nonsense from ChatGPT!!!

                      Comment


                      • #12
                        Since AI has to learn "somewhere," by definition it cannot have an original idea. Humans can.

                        AI can be a tool... nothing more.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Originally posted by Michael Mattias View Post
                          Since AI has to learn "somewhere," by definition it cannot have an original idea. Humans can.

                          AI can be a tool... nothing more.
                          for now............
                          [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                          Kerry Farmer

                          Comment


                          • #14
                            The real danger with Artificial "Intelligence" is human stupidity. Many tend to believe what these AI-robots produce, which of course can and will be used for political purposes and even to start wars. This, together with the ability to use new ways to create fake photos and films that we cannot tell fake from real, makes it extremely important to mistrust everything that is said and shown both now and in the future. Better keep an eye on Arnold... "Today, August 4, 1997, Cyberdyne Systems' supercomputer network Skynet goes online​...".

                            Comment


                            • #15


                              Since AI has to learn "somewhere," by definition it cannot have an original idea. Humans can.

                              AI can be a tool... nothing more.
                              ==>
                              for now............​
                              That's the language of the people who believe in A) Aliens among us ; B) black helicopters; C)Elvis lives
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Originally posted by Michael Mattias View Post

                                That's the language of the people who believe in A) Aliens among us ; B) black helicopters; C)Elvis lives
                                or D) all or the above, Elvis (the Alien among us) lives, and pilots a black helicopter.

                                Comment


                                • #17
                                  I think most of you are missing the point.

                                  Comment


                                  • #18
                                    Originally posted by Shawn Anderson View Post
                                    I think most of you are missing the point.
                                    Is it that humans have no original ideas, just observations and gathered data applied to questions that they might also observe?
                                    The world is strange and wonderful.*
                                    I reserve the right to be horrifically wrong.
                                    Please maintain a safe following distance.
                                    *wonderful sold separately.

                                    Comment


                                    • #19
                                      > I think most of you are missing the point.

                                      Originally posted by Shawn Anderson View Post
                                      I'm mostly impressed by how it understood my question.

                                      That's what has impressed me the most, the conversational nature of the interface. But after all, it's named ChatGTP.
                                      I can ask a second question like "Does that take into account..." and it will apologize and re-do the calculation, explaining each intermediate calculation.

                                      Added: In second place is how it automatically interpolates information. I asked "I graduated from high school in 19XX with a class size of YYY. Statistically, how any of my classmates are likely to have died before our ZZth reunion?​", Chat GTP subtracted 18 from 19XX to get the likely year of birth, and added ZZ to 19XX to get the likely reunion date, then used an actuarial table to get the life expectancy numbers.

                                      Then I asked "Does that take into account people who are likely to have died before high school?" and it re-did everything, showing every step along the way.
                                      "Not my circus, not my monkeys."

                                      Comment


                                      • #20
                                        The truth (?)
                                        Take an exclusive look inside ChatGPT headquarters and see how the controversial AI program responds to all those questions.

                                        Comment

                                        Working...
                                        X