When my code gets to a loop it always crashes and I am not sure why the system that I have been tasked (as a school project) to build is an Electronic Point of Sale system for a fast food resturanct.

I will load the all the menu items and prices into an array then when a button on the main screen is pressed it will assign a value to a variable (index) which is then used to retrieve from the array the menu item. If the item can be ordered in varying sizes (such as a pizza) then a new form should pop up which asks what size they would like to order (small, medium and large) those buttons then assign a value to a variable which is then passed back to the function in the main form.

The problem is that when my function is called it does not wait for input from the second form and just proceeds, causing an error to be thrown because it has no size to get the price. So I put it into a loop whilst it waits for input but now it crashes everytime.

Any advise would be greatly appreciated

Here is the code for my function which is called everytime a food item button is pressed(clicked) on the main screen.

 Public Function fAddOrder()
        Dim p1 As Integer = 0 'p1 is the variable that size value is passed to from pKeyboard var1
        If iSize = True Then   'if the menu item has varying sizes then 

            Do Until p1 > 0          'loop to prevent function from proceeding until a size has been selected
                pKeyboard.Visible = True
                p1 = NanzzaEPOS.pKeyboard.var1 'pass var1 (size) from pKeyboard to p1 in main form
            Loop

            If p1 = 0 Then
                MsgBox("An error has occured, no size was selected")
            End If
        Else
            p1 = 4
        End If
        If p1 > 0 Then



        End If

        Return True
    End Function

Thanks in advance.

I dont understand why you are using a loop to tie up the system. you should use an event to trigger the purchase rather than keep looping.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.