# Programming Visual Basic Help Needed !!



## GT08 (Nov 18, 2008)

I am using Microsoft Visual Studio 2005 and using the basic settings.

I need to know how I can only input the numbers 1 to 10 in a form of textbox. If I can't achieve this by a textbox then could you come up with a solution please?


*What I need:*

1 . I need the user to be able to only input the numbers 1 to 10. 
2. If the user inputs anything other than the numbers then a msgbox will appear stating to only use the numbers.

P.S Step by step guide in how to achieve this please ^_^

Many Thanks


GT08


----------



## Wozzer (Nov 18, 2008)

I could find out by tommorow.

I'm currently learning "Visual Basics" at college and I have the lesson tommorow . 

I know you have to include ">" and "<". (I think)


----------



## Kreij (Nov 18, 2008)

You could use a NumericUpDown control. It allows you to set the min and max values, and the increment (in your case 1). It also allows the user to set the value manually, like a text box.


----------



## Deleted member 3 (Nov 18, 2008)

You could use the changed method and use

Integer.TryParse(yourtextbox.text, 1) 

Returns true or false, ie if it's integer or not. If it is integer you can check if it's between 0 and 10 using < and >.


----------



## Sasqui (Nov 18, 2008)

^ What he said.

Textbox1.OnEvent.LostFocus (sorry about the syntax)
  - Do the integer validation
  - If number <1 or >10, msgbox "Number must be an integer between 1 and 10"
Textbox1.GetFocus


----------



## Kreij (Nov 18, 2008)

While the Focus event works, I usually use the TextChanged event to check for valid characters as the user is typing them. That way you can do error checking on the fly and let the user know that they are inputting invalid values immediately when they type them.

There is more program overhead, but if it not a resourse hungry app it works fine.

Just my 2 cents.


----------



## Noxman (Nov 18, 2008)

Try Delphi, it's easier (for me).. ;D
But, i think its like Sasqui / Dan says. Use their way, i can't VB, but it's pretty much like Delphi. ^^


----------



## FordGT90Concept (Nov 18, 2008)

GT08 said:


> I am using Microsoft Visual Studio 2005 and using the basic settings.
> 
> I need to know how I can only input the numbers 1 to 10 in a form of textbox. If I can't achieve this by a textbox then could you come up with a solution please?
> 
> ...


There's lots of ways to do this...

1. You could also use a MaskedTextBox but it relies more on digits than values (e.g. ## rather than a range 1-10).  A MaskedTextBox would work great for 0-9, for instance.

2. NumericUpDown, as mentioned.

3. A TrackBar with read-only textbox displaying current value.  Limit the range on the TrackBar to 1-10.

4. Plain old TextBox with value verificaton on TextChanged event, as mentioned.

5. TextBox + button where the button validates the input in the TextBox on click.  I usually change the background color of the form control to pink to signify an error.


You can get creative as to how to actually display the error using labels next to the input form or you could even use tooltips that pop up when the mouse is hovering over it.


VB makes programmers lazy so I'll stress one thing VB doesn't: you have to cast.  If you decide any of the methods above that involve TextBoxes, the value they store is of type string.  In order to convert to string to byte (byte can represent a value of 0-255), use something like this:

Dim value As Byte = Convert.ToByte(TextBox1.Text)

Once you have a numeric expression of  the value, you can test it for validity by conditionals.  For example:

If (value >= 1) && (value <= 10) Then
  ' value is good
Else
  ' value is bad
End If

What you do in the if statement depends on which route you take to display the message.


----------



## GT08 (Nov 20, 2008)

Thank you for all of your replies. I have decided to opt for this following code but it does not seem to work at all. This is a little project of mine which I would like to perfect.

I have decided to use lbltotal2.Text = String.Empty. The total clears but then it encounters an error which says *" Conversion from string "" to type 'Double' is not valid. "*

Can you fellow programmers see any mistakes in this Visual Basic coding? Also how can I stop the error from coming up as these *String.Empty* applies to all 14 labels.

The code below is my VB code:


-----------------------------------------------------------------------------------------

Public Class Form1
    Dim CheeseTomato, HamPineapple, Vegetarian, MeatFeast, Seafood As Decimal
    Dim Cola, Lemonade, FizzyOrange As Decimal
    Dim ExtraCheese, Pepperoni, Onions, Peppers As Decimal
    Dim TotalCostPizza, TotalCostPizza2, TotalCostPizza3, TotalCostPizza4, TotalCostPizza5, TotalPizzas As Decimal
    Dim TotalCostDrinks, TotalCostDrinks2, TotalCostDrinks3, TotalCostDrinks4, TotalDrinks, TotalBase, TotalBase2 As Decimal
    Dim TotalCostToppings, TotalCostToppings2, TotalCostToppings3, TotalCostToppings4, TotalCostToppings5, TotalToppings As Decimal
    Dim TotalCost As Decimal
    Dim Order As Decimal

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnorder.Click
        CheeseTomato = 3.5
        HamPineapple = 4.2
        Vegetarian = 5.2
        MeatFeast = 5.8
        Seafood = 5.6
        Cola = 0.9
        Lemonade = 0.8
        FizzyOrange = 0.9
        ExtraCheese = 0.5
        Pepperoni = 0.5
        Onions = 0.5
        Peppers = 0.5
        TotalCost = 0

        If chkboxcat.Checked = True Then
            TotalCostPizza = Val(3.5) * txtbox1.Text
        End If



        If chkboxhap.Checked = True Then
            TotalCostPizza2 = Val(4.2) * txtbox2.Text


            If chkboxVeg.Checked = True Then
                TotalCostPizza3 = Val(5.2) * txtbox3.Text


                If chkboxmfeast.Checked = True Then
                    TotalCostPizza4 = Val(5.8) * txtbox4.Text


                    If chkboxseafood.Checked = True Then
                        TotalCostPizza5 = Val(5.6) * txtbox5.Text
                    End If
                End If
            End If
        End If

        TotalPizzas = TotalCostPizza + TotalCostPizza2 + TotalCostPizza3 + TotalCostPizza4 + TotalCostPizza5
        lbltotal.Text = Format(TotalPizzas, "£#,##0.00")

        If chkboxCola.Checked = True Then
            TotalCostDrinks = Val(0.9) * txtbox6.Text

            If chkboxlemonade.Checked = True Then
                TotalCostDrinks2 = Val(0.8) * txtbox7.Text


                If chkboxorange.Checked = True Then
                    TotalCostDrinks3 = Val(0.9) * txtbox8.Text

                    If chkboxnone.Checked = True Then
                        TotalCostDrinks4 = 0
                    End If
                End If
            End If
        End If

        TotalDrinks = TotalCostDrinks + TotalCostDrinks2 + TotalCostDrinks3 + TotalCostDrinks4
        lbltotal2.Text = Format(TotalDrinks, "£#,##0.00")
        If chkboxtac.Checked = True Then
            TotalBase = Val(0.0) * txtbox9.Text
            If chkboxtrad.Checked = True Then
                TotalBase2 = Val(0.0) * txtbox10.Text
            End If
        End If
        TotalBase = TotalBase + TotalBase2

        If chkboxcheese.Checked = True Then
            TotalCostToppings = Val(0.5) * txtbox11.Text


            If chkboxpproni.Checked = True Then
                TotalCostToppings2 = Val(0.5) * txtbox12.Text


                If chkboxonions.Checked = True Then
                    TotalCostToppings3 = Val(0.5) * txtbox13.Text


                    If chkboxpeppers.Checked = True Then
                        TotalCostToppings4 = Val(0.5) * txtbox14.Text


                        If chkboxnone.Checked = True Then
                            TotalCostToppings5 = 0
                        End If
                    End If
                End If
            End If
        End If
        TotalToppings = TotalCostToppings + TotalCostToppings2 + TotalCostToppings3 + TotalCostToppings4 + TotalCostToppings5
        lbltotal3.Text = Format(TotalToppings, "£#,##0.00")

        TotalCost = TotalPizzas + TotalDrinks + TotalToppings
        lblbill.Text = Format(TotalCost, "£#,##0.00")
        If txtbox1.Text > 10 Then
            lbltotal.Text = String.Empty
            lbltotal.Text = 0.0
            lblbill.Text = String.Empty
            lblbill.Text = 0.0
            MsgBox("Must enter numbers between 1 to 10")

            If txtbox2.Text > 10 Then
                lbltotal.Text = String.Empty
                lbltotal.Text = 0.0
                lblbill.Text = String.Empty
                lblbill.Text = 0.0
                MsgBox("Must enter numbers between 1 to 10")

                If txtbox3.Text > 10 Then
                    lbltotal.Text = String.Empty
                    lbltotal.Text = 0.0
                    lblbill.Text = String.Empty
                    lblbill.Text = 0.0
                    MsgBox("Must enter numbers between 1 to 10")

                    If txtbox4.Text > 10 Then
                        lbltotal.Text = String.Empty
                        lbltotal.Text = 0.0
                        lblbill.Text = String.Empty
                        lblbill.Text = 0.0
                        MsgBox("Must enter numbers between 1 to 10")

                        If txtbox5.Text > 10 Then
                            lbltotal.Text = String.Empty
                            lbltotal.Text = 0.0
                            lblbill.Text = String.Empty
                            lblbill.Text = 0.0
                            MsgBox("Must enter numbers between 1 to 10")

                            If txtbox6.Text > 10 Then
                                lbltotal2.Text = String.Empty
                                lbltotal2.Text = 0.0
                                lblbill.Text = String.Empty
                                lblbill.Text = 0.0
                                MsgBox("Must enter numbers between 1 to 10")

                                If txtbox7.Text > 10 Then
                                    lbltotal2.Text = String.Empty
                                    lbltotal2.Text = 0.0
                                    lblbill.Text = String.Empty
                                    lblbill.Text = 0.0
                                    MsgBox("Must enter numbers between 1 to 10")

                                    If txtbox8.Text > 10 Then
                                        lbltotal2.Text = String.Empty
                                        lbltotal2.Text = 0.0
                                        lblbill.Text = String.Empty
                                        lblbill.Text = 0.0
                                        MsgBox("Must enter numbers between 1 to 10")

                                        If txtbox9.Text > 10 Then
                                            lbltotal4.Text = String.Empty
                                            lbltotal4.Text = 0.0
                                            lblbill.Text = String.Empty
                                            lblbill.Text = 0.0
                                            MsgBox("Must enter numbers between 1 to 10")

                                            If txtbox10.Text > 10 Then
                                                lbltotal.Text = String.Empty
                                                lbltotal.Text = 0.0
                                                lblbill.Text = String.Empty
                                                lblbill.Text = 0.0
                                                MsgBox("Must enter numbers between 1 to 10")

                                                If txtbox11.Text > 10 Then
                                                    lbltotal3.Text = String.Empty
                                                    lbltotal3.Text = 0.0
                                                    lblbill.Text = String.Empty
                                                    lblbill.Text = 0.0
                                                    MsgBox("Must enter numbers between 1 to 10")

                                                    If txtbox12.Text > 10 Then
                                                        lbltotal3.Text = String.Empty
                                                        lbltotal3.Text = 0.0
                                                        lblbill.Text = String.Empty
                                                        lblbill.Text = 0.0
                                                        MsgBox("Must enter numbers between 1 to 10")

                                                        If txtbox13.Text > 10 Then
                                                            lbltotal3.Text = String.Empty
                                                            lbltotal3.Text = 0.0
                                                            lblbill.Text = String.Empty
                                                            lblbill.Text = 0.0
                                                            MsgBox("Must enter numbers between 1 to 10")

                                                            If txtbox14.Text > 10 Then
                                                                lbltotal3.Text = String.Empty
                                                                lbltotal3.Text = 0.0
                                                                lblbill.Text = String.Empty
                                                                lblbill.Text = 0.0
                                                                MsgBox("Must enter numbers between 1 to 10")
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
        Me.Close()
    End Sub
End Class


----------



## FordGT90Concept (Nov 21, 2008)

GT08 said:


> I have decided to use lbltotal2.Text = String.Empty. The total clears but then it encounters an error which says *" Conversion from string "" to type 'Double' is not valid. "*



Instead of...

```
lbltotal2.Text = String.Empty
```
...do this...

```
lbltotal2.Text = ""
```


If that doesn't help, could you zip up the project folder (delete the "bin" and "obj" folders first) and attach it to your post?


----------



## GT08 (Nov 21, 2008)

FordGT90Concept said:


> Instead of...
> 
> ```
> lbltotal2.Text = String.Empty
> ...




Doesn't seem to work. Here is my project I have uploaded with the "bin" and "obj" deleted.


----------



## FordGT90Concept (Nov 21, 2008)

What steps does it take to trigger the error?


Edit: Ah, it errors when all fields are empty on: "If txtbox1.Text > 10 Then"

This is because the conversion algorithms don't know what to make of a null value.  The simple solution is to do...


```
If txtbox1.Text.Length > 0 Then
 ' Proceed as normal
Else
 ' There's nothing there to process
End If
```


And let me give you a tip to cut down on the repetitiveness of your code.  You can write a sub like this to perform all those checks:


```
Private Function Validate(ByRef obj As TextBox) As Double
  If (obj.Text.Length > 0) Then
    Dim value As Double = Convert.ToDouble(obj.Text)
    If (value.Text  > 10) Then
      obj.BackColor = Color.Pink
      MsgBox("Value must be between 1 and 10.")
    Else
      obj.BackColor = Color.White
      Return value
    End If
  End If
End Function
```

Then to validate a control, you'd just have to do the following:

```
Validate(txtbox1)
```

You can play with that concept to make it how you like it.  It cuts way down on the repetition.


----------



## GT08 (Nov 21, 2008)

FordGT90Concept said:


> What steps does it take to trigger the error?
> 
> 
> Edit: Ah, it errors when all fields are empty on: "If txtbox1.Text > 10 Then"
> ...



I'm afraid that this program I am making is not that simple.
Let me try to explain what I am trying to achieve.

It is a pizza restaurant. I want to make a software which can allow the waiters/waitresses to take orders from the table using a small handheld computer.

In the software I must allow the waiters to record the table number (1 to 25), and order up to a maximum of 10 of any item on the menu. A textbox should be provided for any additional requests.

As you can see I have already met my criteria of 'Table Numbers'. 

I am trying to design it so that any order over 10 can not be processed through thus resulting the totals back to 0 along with a message box displaying the message "You can only order up to a maximum of 10 of any item". The total should only be reset back to 0 only on the particular textbox (if more than 10). The other textbox with numbers between 1 to 10 should carry on its calculation thus keeping its total price.

 If the criteria is met between 1 to 10 then the total will appear.

Within my program I have made about 3 or 4 "lbltotal" along with "lblbill" which would be my grand total. "lbltotal" is like the subtotal or you can call it a breakdown.


Any other details you may want to hear more about, just tell me.


I hope to hear from you soon.

GT08


----------



## GT08 (Nov 21, 2008)

FordGT90Concept said:


> And let me give you a tip to cut down on the repetitiveness of your code.  You can write a sub like this to perform all those checks:
> 
> 
> ```
> ...




Where would I put this code? Would it be in my form load or my txtbox1 or in my button (process order)?

As it says " 'Return' Statement in a sub or a set cannot return a value"


----------



## GT08 (Nov 21, 2008)

Damn, I realised I have to make my program count how many pizzas has been ordered and how many drinks ordered.


It will be something like this:

Number Of Pizzas Ordered: _____

Number Of Drinks Ordered: _____


I was intending to use "Val(txtbox1) + Val(txtbox2)" and so on but it comes up with an error. 

I want to display the quantity of how many pizzas ordered.

How am I to achieve this?


----------



## FordGT90Concept (Nov 21, 2008)

GT08 said:


> Where would I put this code? Would it be in my form load or my txtbox1 or in my button (process order)?
> 
> As it says " 'Return' Statement in a sub or a set cannot return a value"


The Private Function/End Function goes inside the Class/End Class tags.

The Validate() bit goes any place that you want the validation to occur (either in a TextChanged or button Click event).




GT08 said:


> How am I to achieve this?


Dim result As Integer = Convert.ToInt32(txtbox1.Text) + Convert.ToInt32(txtbox2.Text)



What I did some time ago on code like yours (CheckBox enable/disable + associated TextBox) is I made a validate function similar to the one above and also an enable/disable sub routine.

Something like...

```
Private Function Validate(ByRef checkbox As CheckBox, ByRef textbox As TextBox) As Boolean
  ' return true if valid and false if invalid
End Function
```
I put the range of values accepted in the TextBox.Tag object as like "1,10."  Then in the Function, I split the two, used the first for min and the second for max.  That way, one sub could take care of the validation of almost everything.


Additionally, I added events to the checkbox to disable/enable the associated textbox.  Something like...


```
Private Sub SetAssocEnable(ByVal sender As Object, ByVal e As EventArgs) Handles chkbox1.CheckedChanged, chkbox2.CheckedChanged, etc...
  Dim chk As CheckBox = sender ' Cast the sender to what it is
  Dim txt As String = "txt" & chk.Name.Substring(3) ' generate the textbox name from the checkbox name
  If (chk.Checked) Then
    Me.Controls(txt).Text = chk.Tag ' Copy stored value from checkbox
    Me.Controls(txt).Enabled = True ' Enable the Textbox
  Else
    chk.Tag = Me.Controls(txt).Text ' Store value to the checkbox
    Me.Controls(txt).Text = "0" ' Null its value so it doesn't conflict with the total
    Me.Controls(txt).Enabled = False ' Disable the Textbox
  End If
End Sub
```

Note that to use this code, the check boxes and text boxes must have a similar name.  For example:
CheckBox = chkSeaFood
TextBox = txtSeaFood

The code will chop off the chk (via Substring) from the CheckBox and add txt on to it giving it the full name for the Textbox to look up.


----------



## GT08 (Nov 21, 2008)

Thank you for your help. Could you check over my project please? What do you think?

I know within my code I have repeated the codes but this is the only way I know to make this program work. I am still new to this. I am always up for improvements to make this code a lot shorter whilst doing the same job.

I am still figuring out how I can count how many pizzas and drinks (quantity) has been ordered corresponding to the orders.


----------



## FordGT90Concept (Nov 21, 2008)

GT08 said:


> Thank you for your help. Could you check over my project please? What do you think?


Considering this is for a PDA, I would make the form as small as possible.  To do that, I would put a TableLayoutPanel in all of those group boxes then add the controls to the tables.  That allows you to keep it neat and also auto-size controls.  I would also try to make the entire form fit to a table panel for the same reason (autosize).




GT08 said:


> I know within my code I have repeated the codes but this is the only way I know to make this program work. I am still new to this. I am always up for improvements to make this code a lot shorter whilst doing the same job.


See above post.  Doing that would remove a lot of the repetitiveness of your code.




GT08 said:


> I am still figuring out how I can count how many pizzas and drinks (quantity) has been ordered corresponding to the orders.


You need a variable in the background and += it.  For instance...

Dim PizzaCount As Integer = 0
Dim DrinkCount As Integer = 0

Private Sub ... ' your function that needs to modify their values
  PizzaCount += pizzasordered
  DrinkCount += drinksordered
End Sub


+= is the same as:

myvar = myvar + othervar


----------



## GT08 (Nov 21, 2008)

FordGT90Concept said:


> The Private Function/End Function goes inside the Class/End Class tags.
> 
> The Validate() bit goes any place that you want the validation to occur (either in a TextChanged or button Click event).
> 
> ...




This seems rather tricky to understand. I do want to understand it but could you explain more in depth as to why and how these codes work. For example what is the chkbox.tag? How do I make that work?

I should be able to understand more if you could kindly incorporate that use of code to my project. That way I could compare that and my current project and see what the differences are.


----------



## FordGT90Concept (Nov 21, 2008)

.Tag is a property basically for random use.  It is an object so the programmer can decide how to use it.  It is there to inexplicably associate extra data to the control (like min/max values).  Every Control has it.  You define it.  If you write an array to it, make sure to read it back as an array.  If you make it a string, process it as a string.


----------



## FordGT90Concept (Nov 21, 2008)

I did just the Pizza one for you but a lot of the stuff I added can be reused for the other parts...

This is coded in Visual Studio 2008 by the way so you'll probably have to add the VB files to your project.  I doubt it whatever version you're using can open the solution/project files.


Try to avoid using MessageBox very often.  It annoys the user.  In the example, I changed it to a ToolTip which displays details of the error by hovering over the errored object.

Also, there is no need for a "Close/Exit" button unless you explicitly remove the "X" in the corner for whatever reason.  Instinctively, people gravitate towards the "X" anyway because that's how you close 99% of applications in Windows.


Is this for a class or a business?


----------



## GT08 (Nov 21, 2008)

FordGT90Concept said:


> I did just the Pizza one for you but a lot of the stuff I added can be reused for the other parts...
> 
> This is coded in Visual Studio 2008 by the way so you'll probably have to add the VB files to your project.  I doubt it whatever version you're using can open the solution/project files.
> 
> ...




Thanks for your reply. This is a class work where we are just practising programming skills by researching and using the scenarios. 

Here is the program I have tried to create by using your technique.

I can't seem to apply it to all of it. How should the correct code be like?

This is quite an intriguing way to program.


----------



## FordGT90Concept (Nov 22, 2008)

I'd get rid of the Extra Toppings -> None.  The only reason why you'd need that is if the rest of them were Radio controls (where you can only select one).  "None" is the equivilent to having none of those boxes checked.


Yeah, that is much better.

Some bugs...
Change Trad to Trads on this line.  The controls are named Trads: Dim PizzaBase As String() = {"TAC", "Trad"}

Still trying to figure out why txtCola and txtLemonade are erroring...


Edit: I just ended up deleting those two controls and readding them.  That made those two errors go away assuming you're getting them.

Before you are done, you should go through and set the order of tab stops.


I don't see any other problems besides that...

Oh, your Table Number combo box is missing?

And the Form.Text is "0.50"


----------



## GT08 (Nov 23, 2008)

FordGT90Concept said:


> I'd get rid of the Extra Toppings -> None.  The only reason why you'd need that is if the rest of them were Radio controls (where you can only select one).  "None" is the equivilent to having none of those boxes checked.
> 
> 
> Yeah, that is much better.
> ...



Thank you for the reply.

How do I get rid of this error?

"Name 'txtCola' is not declared." Line 36 Column 26
"Name 'txtLemonade' is not declared." Line 37 Column 26

        ControlsValidate(txtCola) <---- Highlights the 'txtCola'
        ControlsValidate(txtLemonade) <---- Highlights the 'txtLemonade'

Also what do you mean by "Edit: I just ended up deleting those two controls and readding them.  That made those two errors go away assuming you're getting them."

What two controls? How do I get to it?


Lastly "Before you are done, you should go through and set the order of tab stops."

How do I set the order of tab stops? What good is this? (is it good programming?)


Thanks again for taking your time.


----------



## FordGT90Concept (Nov 24, 2008)

GT08 said:


> How do I get rid of this error?
> 
> "Name 'txtCola' is not declared." Line 36 Column 26
> "Name 'txtLemonade' is not declared." Line 37 Column 26
> ...


1. On the form, select txtCola (it is the input form for Cola).
2. Once it is selected, hit delete.
3. Rinse and repeat for txtLemonade.
4. Now that they are both deletected, select one of the other txt##### controls like the one right below where txtLemonade used to be.
5. Right click on it and select "Copy."
6. Paste it into one of the open spaces.  If it refuses to go in, simply drag and drop it in.  
7. Repeat for the other one.
8. Now just rename them to what they are supposed to be: top one "txtCola" and bottom one "txtLemonade."

VS messed up some how on them with designer code.




GT08 said:


> Lastly "Before you are done, you should go through and set the order of tab stops."
> 
> How do I set the order of tab stops? What good is this? (is it good programming?)


Click on the control you want to check/change and alter TabStop property.  The values start at 1 and work up.

The TabStop is the order in which the tab button proceeds through the form.  For instance, if you have 3 controls with tab stop 1, 2, 3 in order while you currently have focus on 1, should you press tab, it will go to 2.  If you press tab again, it will go to 3.  If you press tab again, it will go back to 1.

This feature is mostly for people that will be using your program without a mouse.  You can easily test it on your compiled application to see if the order is good.


----------



## GT08 (Nov 24, 2008)

FordGT90Concept said:


> 1. On the form, select txtCola (it is the input form for Cola).
> 2. Once it is selected, hit delete.
> 3. Rinse and repeat for txtLemonade.
> 4. Now that they are both deletected, select one of the other txt##### controls like the one right below where txtLemonade used to be.
> ...



Thank you for this. The tab stop is a bit hard to comprehend. The controls your talking about would be what?  I'd initially think that it's the TableLayoutPanel (TLP). Am I correct?

As I am not familiar with the tab stop could you guide me on how to do this step by step please?


----------



## FordGT90Concept (Nov 24, 2008)

It's really not that important...

Everything in the form is a control from TableLayoutPanel to Labels to TextBoxes.  The TabStop system works like a tree in that when it starts, it looks at all the controls it owns.  In your case, it's mostly GroupBoxes.  The TabStop of the group boxes will determine which order the group boxes are selected when the tab key is pressed.  But, because GroupBox is a container control (meaning it holds other controls), the tab heirarchy does not stop there.  If your groupbox is tabbed to, it will then tab through it's children (in your case, just the TableLayoutPanel).  Because a TLP is not focusable, it will jump to the control hierarchy it contains.  It will continue this parent -> children -> parent -> children loop until it reaches the very last (defined by TabStop hierarchy) control on the form at which point, it returns to the beginning.

Yes, that sounds complex.  The best way to grasp it is to just play with it.  Run your application and start hitting tab key.  If you notice the order is not in the way you expect it, alter the TabStops until it is.  Visual Studio forces the usage of TabStop on pretty much every control so, if the order is really messed up, just start at the beginning with 1 and work your way down.  Visual Studio makes sure there are no collisions.


----------



## GT08 (Nov 25, 2008)

Thank you for your reply. I have understood a lot from this thread and I thank you for this. 

I am now trying to enhance my finished program by adding extras to it.

Here is what I want to achieve in my final program:

I would still like to use this program but at this stage I want this system to communicate with the system in the kitchen which would display the orders to be cooked.

Here are some ideas I was thinking of:

By using an existing form, I create a button and the display name would be "Orders to be cooked".
Once I click on that button, it would take me to another form which would display all the Pizzas that needs to be cooked corresponding to the quantities in the first form. It would be something like "Cheese and Tomato Pizza on a Traditional Base with extra cheese topping = 3.

I think in order for this to work, I would need to input the details of what kind of Pizza to create. The previous version was good but now I need this system to communicate with the kitchen to display the orders to be cooked.


I have no idea what the codes would be....


----------



## FordGT90Concept (Nov 25, 2008)

GT08 said:


> I would still like to use this program but at this stage I want this system to communicate with the system in the kitchen which would display the orders to be cooked.


Use UDP packets in System.Net.  There's a lot of guides on how to send/receive packets via UDP in .NET.  Here's an example: http://www.c-sharpcorner.com/Upload...2005040054AM/simpleTcpUdpServerClientPL2.aspx

Remember that a UDP has a limited packet size of around 1024 bytes.





GT08 said:


> By using an existing form, I create a button and the display name would be "Orders to be cooked".
> Once I click on that button, it would take me to another form which would display all the Pizzas that needs to be cooked corresponding to the quantities in the first form. It would be something like "Cheese and Tomato Pizza on a Traditional Base with extra cheese topping = 3.


You can make the second form the same way you made the first.  To add it, just right click on the project and select Add New Windows Form (or some such).  To call that second from from your first (aka Parent) form, just do something like this...

```
Dim ChildForm As New ChildFormName()
' Prep the form here like pass it data to display and the like...
' Then display:
ChildForm.Show() ' or ChildForm.ShowDialog()
```
Show means the original form is still accessible--you can jump between the parent and child form.  ShowDialog means the parent cannot be accessed until the child form is closed.  Use ShowDialog if the parent requires data entered in the child.

You'd put that code in a button click sub, for instance.


----------



## GT08 (Nov 25, 2008)

FordGT90Concept said:


> Use UDP packets in System.Net.  There's a lot of guides on how to send/receive packets via UDP in .NET.  Here's an example: http://www.c-sharpcorner.com/Upload...2005040054AM/simpleTcpUdpServerClientPL2.aspx
> 
> Remember that a UDP has a limited packet size of around 1024 bytes.



Sorry but this isn't what I'm looking for really. A bit too advanced for me at this stage.

For example; on my program if I order 1 Cheese and Tomato Pizza with extra cheese topping on a traditional base and 1 cola. 

How can I process the pizza bit to the other form to display what the chef should cook?

So on the other form I want it to display 1 Cheese and Tomato Pizza with extra cheese on a traditional base. Of course many orders will be different so the information it displays on the other form would have to correspond to the order.

If someone else orders 1 Cheese and Tomato Pizza with extra cheese on a traditional base, 1 MeatFeast on a thin and crispy base then the order I want the chef to cook would be displayed as 1 Cheese and Tomato Pizza with extra cheese on traditional base and 1 MeatFeast on a thin and crispy base.

These information would be on a different form.

*What I would want in the system:*
- Information of the Pizza orders to be displayed on a different form. Every time has to correspond to the different orders. 
- On the first form, once I click on Process Order, I want a message box warning me if I should continue with my order. Yes to Continue and No to Stop the order. 
- Once it has clicked on Yes to continue, another form automatically comes up with the pizza list the chef would have to cook. Whereas for the drinks, it would also be displayed but in a different section of the form.

Do you see where I am trying to go with this?


----------



## FordGT90Concept (Nov 25, 2008)

GT08 said:


> How can I process the pizza bit to the other form to display what the chef should cook?


I knew I forgot to comment on something...

There are two ways you can pass data from one class (Form) to another (you can use both at the same time too):
1) Through initialization parameters.  Defined as:

```
' This class inherits a Form...
Public Class MyForm
  ' This line is already defined in FormName.Designer.vb so
  ' this is just an example...
  Private txtProperty As New System.Windows.Forms.TextBox()

  Public Sub New(ByVal param1 As String, ByVal param2 As String, ByVal param3 As String, ...)
    txtProperty.Text = param1 & param2 & param3
  End Sub
End Class
```
Example of usage:

```
Dim ChildForm As New MyForm(param1, param2, param3, ...)
ChildForm.Show()
```
2) Through public varibles.  These can take many shapes.  In your case, a public accessor/mutator is probably the best way to go--that is, read and write access to an internally defined variable (this example allows an instance of the class to access only the Text field of "txtProperty"):

```
' This class inherits a Form...
Public Class MyForm
  ' This line is already defined in FormName.Designer.vb so
  ' this is just an example...
  Private txtProperty As New System.Windows.Forms.TextBox()

  ' The property...
  Public Property Text() As String
    ' Accessor
    Get
      Return txtProperty.Text
    End Get
    ' Mutator
    Set(ByVal value As String)
      txtProperty.Text = value
    End Set
  End Property
End Class
```

Then, in your parent form, it looks something like this:

```
' this is in a sub that calls the new form
Dim ChildForm As New MyForm()
ChildForm.Text = "Text Message to Display."
ChildForm.Show()
```

I think you should be able to figure out how best to handle the specifics from that...

...but it does sound like you need to establish a shared table of data (a List of Orders).


----------

