0% found this document useful (0 votes)
164 views6 pages

Gambas

The document provides code examples for various drawing and array operations in Gambas 3: 1. It shows how to draw basic shapes like rectangles and circles using line and ellipse methods. 2. It demonstrates how to implement a 1D array to store student marks and perform search and sort operations. 3. It provides an example of a 2D array to represent matrices and code for matrix multiplication and transpose.

Uploaded by

Alivia Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views6 pages

Gambas

The document provides code examples for various drawing and array operations in Gambas 3: 1. It shows how to draw basic shapes like rectangles and circles using line and ellipse methods. 2. It demonstrates how to implement a 1D array to store student marks and perform search and sort operations. 3. It provides an example of a 2D array to represent matrices and code for matrix multiplication and transpose.

Uploaded by

Alivia Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Draw a rectangle using the line method


Code:
Public sub button1_click()
Drawing Area1.clear
Draw.Begin(Drawing Area1)
Draw.line(1,130,500,400)
Draw.end
End
Public sub button2_click()
Drawing Area1.clear
Draw.Begin(Drawing Area1)
Draw.fillcolor=color.red
Draw.fillstyle=1
Draw.rect(10,10,100,200)
Draw.end
End

2. Draw a circle using the circle method


Code:
Public sub form_open()
Fmain.text=”Drawing Examples”
Drawing Area1.cached= true
End
Public sub Button1_click()
Drawing Area1.clear
Draw.begin(Drawing Area1)
Draw.fillcolor= color.darkblue
Draw.fillstyle=1
Draw.ellipse(10,10,100,100)
Draw.end
End

3. Implement the concept of 1-d array using gambas3.


Code:
Private num as integer
Private counter as integer
Private marks[10] as integer

Public sub button1_click()


Dim i as integer
Dim s as integer
Listbox1.clear
Counter=inputbox(“how many numbers to enter?”)
For i=1 to counter
S= inputbox(“enter marks”)
Marks[i]=s
Listbox1.add(marks[i])
Next
End
Public sub button2_click()
Dim I as integer
Dim x,c,pos as integer
X= inputbox(“enter number to be searched”)
C=0
For i=1 to counter
If marks[i]==x then
C=c+1
Pos=i
End if
Next
If c==1 then
Message.info(“number found at pos”&(pos))
Else
Message.info(“number not found”)
End if
End
Public sub button_click()
Dim I,j,temp1 as integer
Listbox2.clear
For i=1 to counter
For j=1 to counter
If marks[i]>marks[j] then
Temp1=marks[j]
Marks[j]=temp1
End if
Next
Next for i=1 to counter
Listbox2.add(marks[i])
Next
End
Public sub button4_click()
Dim i,j,temp1 as integer
Listbox2.clear
For i=1 to counter
For j=1 to counter
If marks[i]<marks[j] then
Temp1= marks[i]
Marks[i]=marks[j]
Marks[j]= temp1
End if
Next
Next
For i=1 to counter
Listbox2.add(marks[i])
Next
End
Public sub button5_click()
Form1.close
End

4. Implement matrix multiplication and transpose in gambas 3 with 2-d array


Code:
Private num as integer
Private counterRow as integer
Private counterCol as integer
Private matrix[5,5] as integer
Private matrix2[5,5] as integer
Private resultmayrix[5,5] as integer
Public sub button1_click()
Listbox1.clear
Dim str as string
Dim I,j as integer
counterRow= inputbox(“enter number of rows:”)
counterCol= inputbox(“enter number of columns:”)
for i=1 to counterRow
str=” “
for j=1 to counterCol
matrix[i,j]= inputbox(“enter number of row”&i&”and number of column”&j)
str= str & space$(3) & matrix[i,j]
next

listbox1,add(str)

next
end
public sub button2_click()
listbox2.clear
dim str as string
dim i,j as string
for i=1 to counterRow
str=” “
for j= 1 to counterCol
matrix2[i,j]= matrix[j,i]
str=str & space$(3) & matrix2[i,j]
next
listbox2.add(str)
next
end
public sub button3_click()
listbox3.clear
dim str as string
dim i,j,k as integer
for i= 1 to counterRow
str=” “
for j= 1 to counterRow
resultmatrix[i,j] = 0
for k= 1 to counterCol
resultmatrix[i,j]= resultmatrix[i,j]+matrix2[k,j]*matrix[i,k]
next
next
next
for i= 1 to counterRow
str=” “
for j=1 to counterCol
str= str & space$(3) & resultmatrix[i,j]
next
listbox3.add(str)
next
end
public sub button4_click()
Fmain.close
End

5. Swapping
Code:
Public sub swap1(x as integer, y as integer)
Dim s as integer
S= x
X= y
Y=s
Textbox1.text =x
Textbox2.text=y
End
Public sub button1_click()
Dim x1,y1 as integer
X1= val(textbox1.text)
Y1= val(textbox2.text)
Swap(x1,y1)
End

6. Write a program in gambas 2 to habe user i/p textbox as integer 1 to 10 to specify the height
and base of a right trabgle. Display the tringle in a listbox using string.
Code:
Public sub button1_click()
Dim x,s,i as integer
Dim str as string
Str=” “
X=val(textbox1.text)
If x<0 then
Message.info(“pattern not possible”)
Else
Message.info(“print the pattern”)
Listbox1.clear
For i=1 to x step1
Str=str &’#’
Listbox1.add(str)
Next
End if
End

7. Have the user i/p a positive number via i/p box. Use a validation loop to prompt for i/p until
valid. Display message indication when valid input is received.
Code:
Public sub button1_click()
Dim s as a string
Dim n as a integer
While true
S= inputbox(“enter a positive number”)
N=s
If n>0 then
Message.info(“valid input”)
Break
Else
Message.info(“invalid input”)
Continue
End if
Wend
End

8. Create a multiplication table.


Code:
Public sub button1_click()
Dim x,I as integer
Dim str as string
Listbox1.clesr
I=1
X= val(textbox1.text)
If x>0 and x<=1
While i<=10
Str= x & “*’ & I & “=” &(x*i)
Listbox1.add(str)
Inc i
Wend
Else
Message.info(“invalid number”)
End if
End
Public sub button2_click()
Listbox1.clear
Textbox1.text=” “
End

9. Shopping cort
Code:

You might also like