I have a form that has a queue and i want to transfer that queue to another queue in another form. however when i try to use the elements in the second queue after transfer, I get the error message queue empty!
below is my code
Imports System.Collections.Generic Public Class Form1 Dim wait As New Queue(Of String) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click wait.Enqueue(InputBox("enter patId...")) Form2.recieveQueue(wait) If wait.Count > 2 Then Dim oForm2 As Form2 oForm2 = New Form2() oForm2.Show() oForm2 = Nothing Me.Hide() End If End Sub End Class
Imports MySql.Data.MySqlClient Public Class Form2 Dim waiting As New Queue(Of String) Public Function recieveQueue(ByVal par1 As Queue(Of String)) As System.Collections.Generic.Queue(Of String) waiting = par1 Return waiting MsgBox(waiting.Peek()) End Function Dim ServerString As String = "Server=localhost;User=root;password= ;Database=clinic" Dim SQLconnection As MySqlConnection = New MySqlConnection Dim fName As String Dim lName As String Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim command As MySqlCommand = New MySqlCommand Dim adapter As MySqlDataAdapter = New MySqlDataAdapter Dim dataset As New DataSet SQLconnection.ConnectionString = ServerString Try If SQLconnection.State = ConnectionState.Closed Then SQLconnection.Open() 'MsgBox("successfuly connected to clinic database")' Else SQLconnection.Close() MsgBox("connection is to database failed") End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub drOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drOne.Click Dim command As MySqlCommand = New MySqlCommand Dim dread As MySqlDataReader Dim hold As String If waiting.Count > 0 And waiting.Peek <> "" Then hold = waiting.Dequeue command.CommandText = "SELECT fName, lName FROM register WHERE patId= '" & hold & " '" command.Connection = SQLconnection dread = command.ExecuteReader While dread.Read() Try fName = dread(0).ToString() lName = dread(1).ToString() Catch ex As Exception End Try 'MessageBox.Show("fName" & dread(0).ToString()) 'MessageBox.Show("lName" & dread(1).ToString()) End While dread.Close() Label1.Text = fName + " " + lName & "To see Doctor In Room 1" Else Label1.Text = "There are No Patients to serve At the moment." End If End Sub End class
I expected the recieveQueue function to copy the queue passed to it into the waiting queue, then it allows me to use the waiting queue contents as I want.
But when I try to use it, around this line of code, < If waiting.Count > 0 And waiting.Peek <> "" Then >
i get the error, 'queue empty'
May be my style of passing data is not right. I created that function to pass data(queue) from form1 to form 2. It seems my function is not returning anything, for some reason i cant tell. Could some one help me here?
Or is it that the return value of the function is not being copied to the waiting queue as i expect?