I thought I would test GPT-3 to see if it could write B4X code. Turns out that it can. I have included my prompts and the B4X code generated by GPT-3 below.
Prompt: Write a function in b4x that checks a string to see if the contents are numeric.
B4X:
Prompt: Write a function in B4X that adds a grid of imageviews. Call it CreateGrid. The grid size is specified by parameters X and Y. Pass the image file names in a list called ImageFileNameList.
Write a function in the B4X language that checks a string to see if it is a valid email address using regex.
This above one is somewhat poor (probably because I used the word function instead of sub).
Write sub in the B4X language that does the following:
1). Download an image file from the web address: https://mindware.mobi/wp-content/uploads/2020/08/cropped-header-1.png. Use httpjob.
2). Display the image in an imageview.
This next one took several tries and being more specific about what I wanted it to do.
Write sub in the B4X language that does the following (named: SetTextSizeToAverage):
1). Iterate through the labels in a panel to generate a list that contains the text size of all labels (called LabelTextSizeList). Also create a list of the labels (called LabelList).
2). Calculate the average text size. Iterate through LabelTextSizeList to caluclate the average.
3). Set the text size of all labels to the average text size. Get the labels from LabelList.
There are errors, but it is easy to fix.
If you have a prompt you want me to try, let me know here. GPT-3 could be fine-tuned fairly easily to write even better B4X code. There is plenty of data in the forums.
Prompt: Write a function in b4x that checks a string to see if the contents are numeric.
B4X:
B4X:
Public Sub CheckIfNumeric (s As String) As Boolean
If IsNumeric (s) Then
Return True
Else
Return False
End If
End Sub
Prompt: Write a function in B4X that adds a grid of imageviews. Call it CreateGrid. The grid size is specified by parameters X and Y. Pass the image file names in a list called ImageFileNameList.
Error on Line 8:
Sub CreateGrid(X As Int, Y As Int, ImageFileNameList As List)
Dim imageview As ImageView
For i = 0 To X - 1
For j = 0 To Y - 1
imageview = new imageview
imageview.Bitmap = LoadBitmap(File.DirAssets, ImageFileNameList.Get(j + i*Y))
imageview.Width = 100dip
imageview.Height = 100dip
imageview.Top = j*100dip
imageview.Left = i*100dip
Activity.AddView(imageview)
Next
Next
End Sub
Write a function in the B4X language that checks a string to see if it is a valid email address using regex.
B4X:
Function CheckEmail(email As String) As Boolean
If Regex.IsMatch(email, "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)") Then
Return True
Else
Return False
End If
End Function
This above one is somewhat poor (probably because I used the word function instead of sub).
Write sub in the B4X language that does the following:
1). Download an image file from the web address: https://mindware.mobi/wp-content/uploads/2020/08/cropped-header-1.png. Use httpjob.
2). Display the image in an imageview.
B4X:
Sub Process_Globals
Dim job As HttpJob
End Sub
Sub Globals
Dim ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
job.Initialize("job", Me)
job.Download("https://mindware.mobi/wp-content/uploads/2020/08/cropped-header-1.png")
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success Then
ImageView1.Bitmap = Job.GetBitmap
End If
job.Release
End Sub
This next one took several tries and being more specific about what I wanted it to do.
Write sub in the B4X language that does the following (named: SetTextSizeToAverage):
1). Iterate through the labels in a panel to generate a list that contains the text size of all labels (called LabelTextSizeList). Also create a list of the labels (called LabelList).
2). Calculate the average text size. Iterate through LabelTextSizeList to caluclate the average.
3). Set the text size of all labels to the average text size. Get the labels from LabelList.
B4X:
Sub SetTextSizeToAverage
For Each l As B4XView In Panel1.GetAllViewsRecursive
If l Is B4XLabel Then
LabelTextSizeList.Add(l.TextSize)
LabelList.Add(l)
End If
Next
Dim average As Double
For Each size As Int In LabelTextSizeList
average = average + size
Next
average = average / LabelTextSizeList.Size
For Each l As B4XLabel In LabelList
l.TextSize = average
Next
End Sub
There are errors, but it is easy to fix.
If you have a prompt you want me to try, let me know here. GPT-3 could be fine-tuned fairly easily to write even better B4X code. There is plenty of data in the forums.