2012-05-10 162 views
0
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 

這是我在VB6中的代碼。 我在Return x線的地方說得到一個錯誤insert功能「編譯錯誤預期:語句結束」在VB6中實現隊列

還有一個錯誤是,每當我試圖刪除隊列中的元素顯示「0刪除」

+2

什麼是VB2006? VB.NET不是VB6,所以你的標籤只會讓事情更加混亂。 – Oded

+0

如果你有任何意見,如果你的意思是VB6 VB98。 – Bob77

+0

請縮進您的代碼。 [看看它更容易遵循嗎?](http://stackoverflow.com/posts/10538957/revisions) – Deanna

回答

6

您試圖通過使用返回語句來返回函數中的值,該語句在VB6中無效。在VB6中,通過將返回值分配給Function的名稱來返回Function的值。

因此,對於你delete功能,你會這樣寫:

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 

看看你的其他功能方面,他們沒有顯式地在所有返回值。

這可能有助於看看this,它提供的替補和功能如何在VB6工作的概述。

+2

+1。對於VBA也是如此 –