Reputation: 931
Dim n, front, rear As Integer
Dim x As Integer
Dim arr() As Integer
Public Function init()
n = InputBox("Enter size :")
ReDim arr(n) As Integer
front = 0
rear = -1
End Function
Public Function insert(x As Integer)
If rear = n-1 Then
MsgBox "queue FULL !!!", vbOKOnly, "QUEUE"
Else
rear = rear + 1
arr(rear) = x
MsgBox x, vbOKOnly, "INSERTED"
End If
End Function
Public Function delete() As Integer
If rear + 1 = front Then
MsgBox "queue Empty !!!", vbOKOnly, "QUEUE"
Else
x = arr(front)
front = front + 1
Return x
End If
End Function
Private Sub inser_Click()
If rear < n Then
x = InputBox("Enter element :")
Call insert(x)
Else
MsgBox "queue FULL !!!", vbOKOnly, "QUEUE"
End If
End Sub
Private Sub del_Click()
x = delete()
MsgBox x, vbOKOnly, "DELETED"
End Sub
Private Sub Exit_Click()
End
End Sub
Private Sub Form_Load()
Call init
End Sub
This is my code in VB6.
I am getting an error in insert
function in Return x
line where it says "complier error Expected : End of statement"
One more error is that whenever I try to delete the elements of the queue it shows "0 DELETED"
Upvotes: 0
Views: 2421
Reputation: 53593
You're attempting to return a value from a Function by using a Return statement, which is not valid in VB6. In VB6 you return a Function's value by assigning the return value to the Function's name.
So for your delete
Function you would write this:
Public Function delete() As Integer
If rear + 1 = front Then
MsgBox "queue Empty !!!", vbOKOnly, "QUEUE"
Else
x = arr(front)
front = front + 1
delete = x ' <-- returning x here.
End If
End Function
Take a look at your other Functions, they're not explictly returning values at all.
It might help to take a look at this, which provides an overview of how Subs and Functions work in VB6.
Upvotes: 6