2 Replies - 619 Views - Last Post: 14 May 2011 - 11:57 PM Rate Topic: -----

#1 jeromebrown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-May 11

Transfering a queue from one form to another queue in another form

Posted 14 May 2011 - 01:00 PM

hello,

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

First Form
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






Second Form


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'

Any Ideas?

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?

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: Transfering a queue from one form to another queue in another form

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Transfering a queue from one form to another queue in another form

Posted 14 May 2011 - 01:25 PM

 Form2.recieveQueue(wait)


Does this even work?
waiting variable is not a shared variable, so you cannot access it from the class level, you have to instantiate an object of the type Form2 to have access to it.
delete the above line and make these changes

     If wait.Count > 2 Then
            Dim oForm2 As Form2
            oForm2 = New Form2()
            oForm2.recieveQueue(wait)
            oForm2.Show() 'here maybe using ShowDialog?
            oForm2 = Nothing 
            Me.Hide()
        End If


Was This Post Helpful? 1
  • +
  • -

#3 jeromebrown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-May 11

Re: Transfering a queue from one form to another queue in another form

Posted 14 May 2011 - 11:57 PM

View PostIonut, on 14 May 2011 - 01:25 PM, said:

 Form2.recieveQueue(wait)


Does this even work?
waiting variable is not a shared variable, so you cannot access it from the class level, you have to instantiate an object of the type Form2 to have access to it.
delete the above line and make these changes

     If wait.Count > 2 Then
            Dim oForm2 As Form2
            oForm2 = New Form2()
            oForm2.recieveQueue(wait)
            oForm2.Show() 'here maybe using ShowDialog?
            oForm2 = Nothing 
            Me.Hide()
        End If




Thanks a lot, That solves my problem! Many thanks Indeed!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1