First i introduce what is my assignment doing.
I'm doing a Ordering System of Donuts which getting customer order product and quantities,
and the System will calculate the FINAL PAYMENT after discount.

Problem:
Now i have a customer order and added into shoppingCart (ListBox),
and inside the listbox will display "<Product Name>, <Quantity>, <SubTotal>"
Now let's assume the customer want delete a order, so how can i SubString a item from the listbox inorder to re-Calculate the grandtotal, and also the product name might have longer name or shorter name, so how can i substring the exactly subtotal amount?

Another problem,
i got a new form that able to linked from 2 different forms, but how can i determine which forms is called from?
because when i press the back/cancel button will return the form where the forms is called.

Problem 1:

If you are seperating the values with ','; then you can make use of the string split function (asuming all values will be in the same format.)

Just pass in the string from the listbox and then parse the string into an array using string split.

Example:

 Dim ar() As String = Split(ListBox1.SelectedItem, ",")
'This will return something that looks like this'
'String: Chocolate, 10, 24.55'
' ar(0): Chocolate'
' ar(1): 10'
' ar(2): 24.55'

Problem 2:

You should make use of the sender object that is passed in.

You will have to use CType(sender, Form) to manipulate the form from another.

Example:

   Dim callingForm As Form = CType(sender, Form)
   Dim FormName As String = callingForm.Name

Hope this helps!

Another important problem i've faced..
i just changed all of the forms' property:
FormBorder: Fixed3D
ControlBox: False
StartPosition: CenterScreen
and also changed the SplashScreen into None and Startup Form = frmWelcome

just assume that i've finish load the frmWelcome and will go to frmMenu,
and click picOrder inorder to go frmOrder
once i clicked, the frmMenu should be hide because i coded it..
and the frmOrder will appear. at this moment,
the frmMenu never hide, but two forms appear at the sametime..
what's wrong with my program?

i also tried changed the SplashScreen = frmWelcome and Startup Form = frmMenu,
and it work properly :(

When your program is running how many forms would the user have open at one time? Are any of these Child forms? If they are not child forms you can use the following
Form Wide Variable Dim sef As frmDailySales >>frmDailySales is a Form.
Then in the event you want to open that form use

 Private Sub lnkEnterSales_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkEnterSales.LinkClicked

    If sef Is Nothing OrElse sef.IsDisposed = True Then
      sef = New frmDailySales
    End If

    If sef.Visible = False Then
      sef.Show()
      sef.whoCalled = Me 'Pass the Calling Form
      Me.Hide()
    End If

  End Sub

The frmDailySales will open. The form(frmSalesMain) that called frmDailySales will hide
The frmDailySales will have a variable>> Public whoCalled as Form
When you close frmDailySales

 Private Sub frmDailySales_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    whoCalled.Show()
  End Sub

frmSalesMain will again be visible.

If I didn't explain this well enough let me know and I will help where you need it.

I've solved all of the problem so far. thanks for the suggestiions and helping :)

Solution Problem 1:

Dim splitSelectedText() as String = Split(lstShoppingCart.SelectedItem, vbTab)
'Assume i have a item in the listbox like this
'Chocolate<vbTab><vbTab>2<vbTab>19.80
'Then i only return the amount for the purpose of delete and update the grand total
'So

Return splitSelectedText(2)

Solution Problem 2:
Havent Do Yet... Update soon

Solution Problem 3:
Sorry to kRod for not using his suggestion,
but i know what you are typing, is just too complicated due to i am Junior. Sorry dude and Thanks :)
So i changed back SplashScreen = frmWelcome & Startup Form = frmMenu
and at frmWelcome i've do some setting in order to get some animation.

Now i got a problem of the problem 1
this is what i've tried.

Private Function SplitString() As String
    Dim splitStr() As String = Split(lstShoppingCart.SelectedItem, vbTab)

   Return splitStr(2)
End Function

...

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        lstShoppingCart.Items.RemoveAt(lstShoppingCart.SelectedIndex)

        Dim getText As String = SplitString()
        Dim selectedAmount as double = double.parse(getText)

        lblGrandTotal.Text = (dblGrandTotal - selectedAmount).ToString("n2")
End Sub

'Assume My Selected Item IS:
'Chocolate<vbTab><vbTab>10<vbTab>20.30

and the problem occur is my array index is out of bounded.
i don't know what's wrong with my code.. :/

The Problem 2 i still can't work it out, could you give a simple example to reference?

i linked Database of memberlogin and my assignment also already have frmLogin,
so how can i check the database data whether same as the user key-in(textBox).
if possible, provide example to reference, sorry for keep asking due to lecturer no teach clearing. :/

Any chance we could see a sample of your CSV File? I am curious why you are tab delimiting and there are 2 tabs between Chocolate and the number 10 which I am guessing is the count. You could make your coding life a lot easier if you had a Orders Class and then add each order to a list(Of Orders). Or a simple DataTable with all your orders would be a more manageable. Also could you post the code you have so far I'd like to look at it and see what your thought process is?

because due to my listbox size, so i have to 2 tabs and 1 tabs as the format to display the value.

About the (CType, Sender)

i am not really understand it, could you please provide an example?

This is a simple function to determine if all the textboxes on a form have input or have not had there text property set to nothing. It creates a control variable, uses it to loop through all the control, when it finds a control that is of type TextBox it converts the variable to a TextBox That way it can check its Text Property. I know there are better explainations on MSDN about how it works.

Private Function ValidateInput() As Boolean

    Dim ret As Boolean = True

    For Each cnt In Me.Controls
      If TypeOf (cnt) Is TextBox Then
        If CType(cnt, TextBox).Text = "" Or CType(cnt, TextBox).Text Is Nothing Then
          ret = False
        End If
      End If
    Next

    Return ret

  End Function

Microsoft says >> Click Here

If your controls are in a Container on the Form you would have to iterate the Container to get the TextBoxes in the Container.

Edited 4 Years Ago by kRod

Hmm, i still don't get it, but my brain suddenly pop out a new idea of calling the form by determine which form is calling.

 Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Hide()
        If nameForm = "frmMenu" Then
            frmMenu.Show()
        ElseIf nameForm = "frmOrder" Then
            frmOrder.Show()
        End If
End Sub

by the way, thanks for helps. :):) and also i've already solved the split method. :):)
now left database problem. Thanks alot :)

This question has already been answered. Start a new discussion instead.