• Welcome to Jose's Read Only Forum 2023.
 

Happy new Year, let AI do my program

Started by Theo Gottwald, January 01, 2023, 01:15:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

I needed a simple Program that will calculate the time-difference between two times like:
"09:32:56:1234".
SO in short what I needed is:
"09:32:56:1234" - "09:32:56:1234"

And i thought let it the AI do. 

AI  - ChatGPT


First I got this:

QuoteYes, it is possible to subtract one time in this format from another time in this format using a PowerBasic program. You can do this by first breaking down the two times into their hours, minutes, seconds, and milliseconds components and then subtracting the corresponding components of the two times.

Here is some example code in PowerBasic that demonstrates how this could be done:

' Declare variables for the two times and for the result
DIM time1 AS STRING, time2 AS STRING, result AS STRING

' Assign values to the times
time1 = "10:45:35.428"
time2 = "07:30:15.220"

' Split the times into their components
DIM hours1 AS INTEGER, minutes1 AS INTEGER, seconds1 AS INTEGER, milliseconds1 AS INTEGER
DIM hours2 AS INTEGER, minutes2 AS INTEGER, seconds2 AS INTEGER, milliseconds2 AS INTEGER

hours1 = VAL(LEFT$(time1, 2))
minutes1 = VAL(MID$(time1, 4, 2))
seconds1 = VAL(MID$(time1, 7, 2))
milliseconds1 = VAL(MID$(time1, 10))

hours2 = VAL(LEFT$(time2, 2))
minutes2 = VAL(MID$(time2, 4, 2))
seconds2 = VAL(MID$(time2, 7, 2))
milliseconds2 = VAL(MID$(time2, 10))

' Subtract the times
DIM carry AS INTEGER
carry = 0
milliseconds1 = milliseconds1 - milliseconds2
IF milliseconds1 < 0 THEN
    milliseconds1 = milliseconds1 + 1000
    carry = 1
END IF
seconds1 = seconds1 - seconds2 - carry
carry = 0
IF seconds1 < 0 THEN
    seconds1 = seconds1 + 60
    carry = 1
END IF
minutes1 = minutes1 - minutes2 - carry
carry = 0
IF minutes1 < 0 THEN
    minutes1 = minutes1 + 60
    carry = 1
END IF
hours1 = hours1 - hours2 - carry

' Format the result as a string
result = FORMAT$(hours1, "00") + ":" + FORMAT$(minutes1, "00") + ":" + FORMAT$(seconds1, "00") + "." + FORMAT$(milliseconds1, "000")

' Print the result
PRINT result


Then I said:

QuoteNow it is possible, that the timeformat is like this: 13:9:4 means the lenght of the parts is not fixed. can you change your proigram in a way that it will split by the position of the ":" instead?

Yes, it is possible to modify the code to split the time strings by the position of the colon characters rather than by a fixed number of characters. Here is an example of how this could be done:


' Declare variables for the two times and for the result
DIM time1 AS STRING, time2 AS STRING, result AS STRING

' Assign values to the times
time1 = "10:45:35.428"
time2 = "07:30:15.220"

' Split the times into their components
DIM hours1 AS INTEGER, minutes1 AS INTEGER, seconds1 AS INTEGER, milliseconds1 AS INTEGER
DIM hours2 AS INTEGER, minutes2 AS INTEGER, seconds2 AS INTEGER, milliseconds2 AS INTEGER

hours1 = VAL(LEFT$(time1, INSTR(time1, ":") - 1))
minutes1 = VAL(MID$(time1, INSTR(time1, ":") + 1, INSTR(time1, ":", INSTR(time1, ":") + 1) - INSTR(time1, ":") - 1))
seconds1 = VAL(MID$(time1, INSTR(time1, ":", INSTR(time1, ":") + 1) + 1, INSTR(time1, ".") - INSTR(time1, ":", INSTR(time1, ":") + 1) - 1))
milliseconds1 = VAL(MID$(time1, INSTR(time1, ".") + 1))

hours2 = VAL(LEFT$(time2, INSTR(time2, ":") - 1))
minutes2 = VAL(MID$(time2, INSTR(time2, ":") + 1, INSTR(time2, ":", INSTR(time2, ":") + 1) - INSTR(time2, ":") - 1))
seconds2 = VAL(MID$(time2, INSTR(time2, ":", INSTR(time2, ":") + 1) + 1, INSTR(time2, ".") - INSTR(time2, ":", INSTR(time2, ":") + 1) - 1))
milliseconds2 = VAL(MID$(time2, INSTR(time2, ".") + 1))

' Subtract the times
DIM carry AS INTEGER
carry = 0
milliseconds1 = milliseconds1 - milliseconds2
IF milliseconds1 < 0 THEN
    milliseconds1 = milliseconds1 + 1000
    carry = 1
END IF
seconds1 = seconds1 - seconds2 - carry
carry = 0
IF seconds1 < 0 THEN
    seconds1 = seconds1 + 60
    carry = 1
END IF
minutes1 = minutes1 - minutes2 - carry
carry = 0
IF minutes1 < 0 THEN
    minutes1 = minutes1 + 60
    carry = 1
END IF
hours1 = hours1 - hours2 - carry

' Format the result as a string
result = FORMAT$(hours1, "00") + ":" + FORMAT$(minutes1, "00") + ":" + FORMAT$(seconds1, "00") + "." + FORMAT$(milliseconds1, "000")

' Print the result
PRINT result



Its funny and maybe time-saving :-)

Roland Stowasser

Hi Theo,

do you know which programming languages ​​can be used with ChatGPT? I tried to learn more about ChatGPT and OpenAI but it seems I have to create an account before I can see anything? Is this an open source project?

Charles Pegge

Happy New Year!

I think the need to sign on is a basic protection against bad actors.

I asked it: do you know how to do "hello world" in OxygenBasic

Quote
code:

Copy code
' Hello, World! program in Oxygen Basic

Print "Hello, World!"

This code will print the message "Hello, World!" to the console when the program is run.

To run the program, you will need to open Oxygen Basic and create a new project. Then, you can copy and paste the code into the editor and run the program by clicking the "Run" button or pressing F5.

It is worth noting that the syntax for Oxygen Basic is similar to other BASIC programming languages, so if you are familiar with BASIC, you should find it easy to learn and use.

Overall, creating a "Hello, World!" program in Oxygen Basic is a simple and straightforward process. With just a few lines of code, you can create a program that will print a message to the console.

Theo Gottwald

#3
QuoteYou can see examples of Oxygen Basic here:
http://www.jose.it-berater.org/smfforum/index.php?board=152.0

Can you take a look?

AI:
Quote
I'm sorry, I am unable to access external links at this time. Oxygen Basic is a programming language created by Charles Pegge which aims to be a blend of the simplicity of BASIC and the power of C. As far as I know, it is not as popular as other languages and it has a relatively small user base. Oxygen Basic is a dialect of the programming language Basic and it is an interpreted, high-level, general-purpose programming language. It aims to be easy to use for beginners, but also powerful enough for advanced users. It is used to create Windows-based applications, and it can also create GUI (graphical user interface) programs, as well as console-based applications.

It can be used to develop a wide variety of software, such as games, utilities, and business applications.

It's worth noting that while this language can be used to create windows based application, it might not have the support and community of other more common languages such as C++, C# or Python and it might be hard to find libraries, tutorials or support for some features.





@Roland
To login, i just use my normal "Google-Account".
As it can be used to log in at many places, such an google account is very handy.
It may not be the best idea if you want a lot of privacy,
but if - like me - you have accepted that you live in 1984 -
a google account is a good thing and saves a lot of time.

Which programming languages?
He knows all public languages, russian, thai and about programming anything that is welknow, including Powerbasic, C .. Python ...
while he is not perfect you always get something that you can use  as a Template.

You can also feed him your code and ask "What can be improved".

Zlatko Vid

QuoteYou can also feed him your code and ask "What can be improved"

Theo

I see this like a big fake propaganda and potential for malware

Theo Gottwald

Please try it first then give comments.

I am using it often lately because it knows all API's and can also make sample code in Powerbasic for all API's.
It can even make INCLUDE-Definitions where they are missing.