ChatGPT - the great programmer's code book ?

AnandGupta

Expert
Licensed User
Longtime User
I am developing the new version of our flagship application in C# and MsSql.
Existing version is on Xbase++ and DBF.

Since I am new to both C# and Sql, I do lots of code snippet search in Google. It requires opening and going through many webpages to get the working code, as I require.
Now ChatGPT gives me exact simple code. If the first one does not work, I click "Regenerate .." and it gives next snippet of the code for same requirement.

Well I was afraid that ChatGPT will take my place, but no. It is here to help me and many programmers like me who are new to a programming language but have knowledge in another programming language. ?
 

AnandGupta

Expert
Licensed User
Longtime User
B4J & MSSql (or B4J & MySql)?
Well I tried that at first, but the name Java is still problem for our clients and our company.
I am using B4J server for our Android app. No problem there as the B4J server is running on our server.

We already have VB .net application and I am making C# one. I have to keep my job.
Maybe in future, I get to make the B4J application.
 

hatzisn

Expert
Licensed User
Longtime User
I am developing the new version of our flagship application in C# and MsSql.
Existing version is on Xbase++ and DBF.

Since I am new to both C# and Sql, I do lots of code snippet search in Google. It requires opening and going through many webpages to get the working code, as I require.
Now ChatGPT gives me exact simple code. If the first one does not work, I click "Regenerate .." and it gives next snippet of the code for same requirement.

Well I was afraid that ChatGPT will take my place, but no. It is here to help me and many programmers like me who are new to a programming language but have knowledge in another programming language. ?

You are abosulutely right @AnandGupta. Yesterday I started learning Objective C by asking ChatGPT to perform several tasks (like "find the last instance of a character in a string and the first instance of another character and display the substring of this string between them"). It can be used also as a cheap tutor. I checked the cost and when my free trial period will end in almost 3 months I will definetely upgrade to a paid account. It is just 0.02$/1000 tokens (at least in the model I am interested in - the others are cheaper) which 1000tokens correspond to almost 750 words as it states in the billing section.
 
Last edited:

Lello1964

Well-Known Member
Licensed User
Longtime User
B4J & MSSql (or B4J & MySql)?


I've done some testing, it generates B4A, B4j and maybe even B4i code as well as Sqlite and MySql.

Just specify in the request the language you want to use.
 

emexes

Expert
Licensed User
Try asking it:

what are the 10th and 20th digits of pi?
what are the 11th and 21st digits of pi?

The answers I got just now were close, but no cigar.

As were many others.

At least it gave a reasonable answer to: did trump say drink bleach?
 

LucaMs

Expert
Licensed User
Longtime User
An answer from that ChatGPT (after answering that it can teach Italian):

1671627987454.png


Translation

Question: I want to test your intelligence. What color is my sister's black dog?

Answer: I'm sorry, but I can't answer your question because I don't have enough information to do so. I don't know who your sister is or what the characteristics of her dog are. I could only answer your question if I had more information available. In any case, the color of the dog has nothing to do with my intelligence or my ability to answer questions. I am simply a language model developed by OpenAI and my goal is to help users ask questions and provide accurate and complete answers based on the data at my disposal.



When I was a child, a common question was:
"What color was Garibaldi's white horse?"
(in Italian, of course)
 

AnandGupta

Expert
Licensed User
Longtime User
I saw a thread today in our Forum,
TextField Prompt Text | B4X Programming Forum

and thought, how to do the same in C# ?
I already know and do it in Xbase++, but C# ?
I copied and pasted the same question from the thread but for C# and ChatGPT gave me full code with explanation ?
 

emexes

Expert
Licensed User
I copied and pasted the same question from the thread but for C# and ChatGPT gave me full code with explanation ?

Did it compile and run and do what you'd asked for?

I asked for a binary search in Brainf*ck and it regurgitated a description of a binary search and tried to pass off a hello, world program as an implementation of that algorithm. I think it even claimed it was an image search, ie not just a string or number search.

It looked mighty impressive, but an advantage of being a curmudgeon is that my bs filter is permanently set to 11.

Real AI wouldn't make stuff up.

Or would it? ?

Perhaps it's considering going into politics. ?
 
Last edited:

emexes

Expert
Licensed User
The "American" version of that is usually along the lines of, "Who's buried in Grant's tomb?"

Similar vein: if aircraft crashes on border between two countries, where are the survivors buried?

Probably worth also testing out with Easiest Quiz Ever:

What is catgut made of?
What animal are Canary Islands named after?
How long was the Hundred Year's War?
What colour is aircraft black box flight data recorder?
In which month was the October Revolution? (although I think this one is 50:50 because the Russians adjusted their calendar soonafter)

and about another 6-10 questions that I can't remember right now.

Then again, if the AI's been trained on internet material, it should be well-versed in those questions = trap could turn into case of us being hoist with own petards. ?
 
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
Did it compile and run and do what you'd asked for?
No it didn't.
But I learnt something from it and know which textbox events I can use for it.
I am beginner in C# and thankful to these code samples which are like quick tutorials for me.

I also got wrong code for database fetch of records, but on 'Regenerate..' I got the code which compiled and worked.
 

dghoskins

New Member
Licensed User
Longtime User
Not the only pedant!
The Hundred Years War lasted 116 years (1337 - 1453).
While there are several theories on the naming of the Canary Islands, none of them involve song birds. One involves dogs.
Catgut is usually made from sheep or goat intestines but not cat's guts.

Dennis
 

Derek Johnson

Active Member
Licensed User
Longtime User
Chat GPT seems to provide incorrect answers when Android Libraries are involved. I asked it:

create code in b4a to replace the toastmessage function

It suggested the following code:

Show Toast Message:
Sub ShowToastMessage(Message As String)
  Dim t As Toast
  t.Initialize(Message, True)
  t.Duration = t.LENGTH_SHORT
  t.SetGravity(Gravity.BOTTOM, 0, 0)
  t.Show
End Sub

So I asked it:
which library enables declaration of an object as 'toast'

To use the Toast object in your code, you need to import the Android library by adding the following line at the top of your code file:

Copy code
Import Android.Widget.Toast

Still getting an error:Main - 16: Attribute not supported: additionaljavadirectory

I apologize for the mistake in my previous response. The correct syntax for importing a library in Basic4Android (B4A) is #AdditionalRes:.

#AdditionalRes: C:\Program Files (x86)\Anywhere Software\Basic4android\AdditionalLibraries\Android\res

So we are not all going to be redundant just yet!

Incidentally how would you be able to use the Toast object as described?
 

Intelemarketing

Active Member
Licensed User
Longtime User
Well I tried that at first, but the name Java is still problem for our clients and our company.
I am using B4J server for our Android app. No problem there as the B4J server is running on our server.

We already have VB .net application and I am making C# one. I have to keep my job.
Maybe in future, I get to make the B4J application.
Is the translator of VB.Net to C# still available ?
 

hatzisn

Expert
Licensed User
Longtime User
Is the translator of VB.Net to C# still available ?

There are two on-line. I have Googled it in the past and have found them. They are both correct by almost 100% (minus little something).
 

AnandGupta

Expert
Licensed User
Longtime User
Is the translator of VB.Net to C# still available ?
Do not know.
I am making my application fresh, not using any existing VB code. VB is done by different team.
I am developing my application by using Xbase++ logic as it is next version of my existing application.
 

LWGShane

Well-Known Member
Licensed User
Longtime User
Years back I had an app (now unpublished) that would convert various units of measurement into feet and then convert the feet into hammer units. For those who don't know, the game "Garry's Mod" uses the Valve Hammer Editor for map creation and its unit of measurement are hammer units. I'm planning on rewriting this app as a BANano or PHP app as I don't want to deal with app stores for something so simple.

I just used ChatGPT and it successfully recreated the conversion code with one catch. In the first response it fails to take into account if the unit type is feet so check my commented solution in the first response. I regenerated it and the second solution works perfectly.

Original Question:
In B4A: Using a scale where 16 hammer units is equal to one foot, create a Sub that converts centimeters, millimeters, meters, inches, miles, and yards to feet and convert that value to its value in hammer units.

Solution 1:
B4X:
Sub ConvertToHammerUnits(units As Double, unitType As String) As Double
    Dim feet As Double 'easy fix would be to include change this to "Dim feet As Double = units"
    Select Case unitType
        Case "centimeters"
            feet = units / 30.48
        Case "millimeters"
            feet = units / 304.8
        Case "meters"
            feet = units / 0.3048
        Case "inches"
            feet = units / 12
        Case "miles"
            feet = units * 5280
        Case "yards"
            feet = units * 3
    End Select
    Return feet * 16 'convert feet to hammer units
End Sub

Solution 2:
B4X:
Sub ConvertToHammerUnits(value As Double, unit As String) As Double
    Select unit
        Case "centimeters"
            value = value / 30.48
        Case "millimeters"
            value = value / 304.8
        Case "meters"
            value = value / 0.3048
        Case "inches"
            value = value / 12
        Case "miles"
            value = value / 0.000189394
        Case "yards"
            value = value / 0.333333
    End Select
   
    ' convert feet to hammer units
    Return value * 16
End Sub
 
Last edited:
Top