I have an assignement to use each grouping of code only once and put it into an application. Cut the snips of code from the snips part (ill have that coded at the bottom) and paste in the application based on comments within the application. You dont enter a single character of code. The teacher made sure the application has been verified and does work. The problem is I keep running into the same problem, I have more code then places to put them, so im hoping you guys could see where im leaving the codes out, basically all im asking is could you look at the code and see where everything goes and could help me out. I know where certain things go like

If intProductsEntered

and where the close goes, but I always got a couple left, ill leave everything blank so you can see it the way I got it, where it has the ' and then writing right under that, thats where the code should go There is 4 forms of codes on here. Form1 code is

Public Class frmOrderTotal

    Public Sub LoadOrder()
        'clear the grid
        dgOrder.Rows.Clear()
        Dim dclOrderTotal As Decimal
        'add all products to screen by adding rows to data grid
        For i As Integer = 0 To Products.Length - 1
            dgOrder.Rows.Add()
            dgOrder.Rows(i).Cells(0).Value = Products(i).UPC
            dgOrder.Rows(i).Cells(1).Value = Products(i).Description
            dgOrder.Rows(i).Cells(2).Value = FormatCurrency(Products(i).Price)
            dgOrder.Rows(i).Cells(3).Value = Products(i).Qty
            'display extended price to screen
            dgOrder.Rows(i).Cells(4).Value = FormatCurrency(Products(i).Qty * Products(i).Price)
            'accumulate total price

        Next
        'display total price
        lblOrderTotal.Text = FormatCurrency(dclOrderTotal)
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        'close the form

    End Sub
End Class

form2

Public Class frmOrders

    Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
        Dim strFileName As String
        'if file exists, load the order and display order total screen with the order date
        If ValidateFileExists(FileName(DateTimePicker.Value)) = True Then

            OrderTotal.Show()
        Else
            'file does not exist, give error
            MessageBox.Show("There are no orders for that date")
        End If
    End Sub

    Private Sub frmOrders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'load products offered

        'give message box to students to help them find existing orders
        MessageBox.Show("by default, you can view orders from 12/01/2015 and 12/02/2015")
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        'validate file exists based on date
        'if no, clear quantities from structure and display entry form
        If ValidateFileExists(FileName(DateTimePicker.Value)) = False Then

        Else
            'an order does exist, do not allow a new one to be created
            MessageBox.Show("An order already exists for this date")
        End If
    End Sub
End Class

form3

Public Class frmEntry
    Public OrderDate As Date
    Dim intProductsEntered As Integer

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        'Make certain a valid UPC was entered
        Dim i As Integer = ValidateProduct(txtUPC.Text)
        If i = -1 Then
            'give error message for invalid UPC
            MessageBox.Show("Please enter a valid UPC")
            txtUPC.SelectAll()
        Else
            'Update quantity for selected product

            'clear the form

            txtUPC.Focus()
            'update number of products entered
            intProductsEntered += 1
        End If
    End Sub

    Function ValidateProduct(ByVal UPC As String) As Integer
        'compare UPC to UPCs in data file
        For i As Integer = 0 To Products.Length - 1
            If UPC = Products(i).UPC Then
                'UPC was validated, return array element number
                Return i
            End If
        Next
        'UPC was not validated
        Return -1
    End Function

    Private Sub frmEntry_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'if products were entered, ask to save -- if yes, call save process

    End Sub

    Private Sub frmEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'update caption with current order date
        grpEntry.Text = "Product Entry (" & OrderDate & ")"
    End Sub

End Class

form4

Imports System.IO

Module mdlProduct
    Public Products(-1) As Product

    Structure Product
        'structure to contain products
        Dim UPC As String
        Dim Description As String
        Dim Price As Decimal
        Dim Qty As Integer
    End Structure

    Public Sub LoadProduct()
        'load products offered information to structure from data file
        Dim textfile As StreamReader

    End Sub

    Public Sub LoadOrder(ByVal FileName As String)
        'load order from order text file based on date (filename) 
        Dim textfile As StreamReader
        textfile = File.OpenText(FileName)
        Call ClearQuantities()
        Do Until textfile.Peek = -1
            Dim strUPC As String = textfile.ReadLine
            Dim intQty As Integer = textfile.ReadLine
            For i As Integer = 0 To Products.Length - 1
                If strUPC = Products(i).UPC Then
                    Products(i).Qty += intQty
                    Exit For
                End If
            Next
        Loop
        textfile.Close()
    End Sub

    Function ValidateFileExists(ByVal FileName As String) As Boolean
        'return if file exists in folder or not
        Return File.Exists(FileName)
    End Function

    Function FileName(ByVal DateOfOrder As Date) As String
        'create the file name based on date passed to function
        Dim strMonth, strDay, strYear As String
        strMonth = DateOfOrder.Month
        strDay = DateOfOrder.Day
        strYear = DateOfOrder.Year
        If strMonth.Length = 1 Then strMonth = "0" & strMonth
        If strDay.Length = 1 Then strDay = "0" & strDay
        Return strMonth & strDay & strYear & ".txt"
    End Function

    Public Sub WriteProduct(ByVal OrderDate As String)
        'write only products ordered and quantity to new text file

    End Sub

    Public Sub ClearQuantities()
        'clear the quantities of each product in structure

    End Sub
End Module

and the code snips that are suppose to go in there, the are numbered to help out

1.
Products(i).Qty += Convert.ToInt16(txtQty.Text)

2.
strFileName = FileName(DateTimePicker.Value)
Call mdlProduct.LoadOrder(strFileName)
Dim OrderTotal As New frmOrderTotal
OrderTotal.lblDate.Text = DateTimePicker.Value
Call OrderTotal.LoadOrder()

3.
txtQty.Clear()
txtUPC.Clear()            	

4.
dclOrderTotal += Products(i).Qty * Products(i).Price

5.
textfile = File.OpenText("product.txt")
Do Until textfile.Peek = -1
     ReDim Preserve Products(Products.Length)
     With Products(Products.Length - 1)
           .UPC = textfile.ReadLine
           .Description = textfile.ReadLine
           .Price = textfile.ReadLine
     End With
Loop

6.
If intProductsEntered > 0 Then
If MessageBox.Show("You have entered " & intProductsEntered & " products.  Do you want to process this batch?", "Process Order", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
     Call mdlProduct.WriteProduct(OrderDate)
End If
End If

7.
Call mdlProduct.ClearQuantities()
frmEntry.OrderDate = DateTimePicker.Value
frmEntry.Show()


8.
   Close()


9.
 Call LoadProduct()

10.
 For i As Integer = 0 To Products.Length – 1
      Products(i).Qty = 0
 Next

11.
Dim textfile As StreamWriter
textfile = File.CreateText(FileName(OrderDate))
For i As Integer = 0 To Products.Length – 1
     If Products(i).Qty > 0 Then
          textfile.WriteLine(Products(i).UPC)
          textfile.WriteLine(Products(i).Qty)
    End If
Next
textfile.Close()

Now I keep putting code in here and trying to figure out everything but I still keep coming up with problems of putting it in the right place, you cant edit the code in any way except for copy and past the snips into the right place, but this is where im having trouble at, because like I said I keep running into more code snips then where to put them, all the code has to used, so its not like its a trick or anything, im just having trouble doing this and was hoping you guys could help me out, ill figure it would be an easy solved thread and could help people out that are having the same trouble as me, I know its a bad thing to have people do my assignmaets for me but I dont know what to do, and its not like people are making any code for me all im asking is can someone help me put the snips in the right place and thats all, thanks

Im just having problem trying to figure out wher to put

For i As Integer = 0 To Products.Length – 1
      Products(i).Qty = 0
 Next

and

Dim textfile As StreamWriter
textfile = File.CreateText(FileName(OrderDate))
For i As Integer = 0 To Products.Length – 1
     If Products(i).Qty > 0 Then
          textfile.WriteLine(Products(i).UPC)
          textfile.WriteLine(Products(i).Qty)
    End If
Next
textfile.Close()

because it keeps on coming up with an error with the " - " thats after the product length, these are the only two i need help on figuring out where they go

Hi,

You can try this:

Dim i As Integer
 For i = 0 To Products.Length – 1
      Products(i).Qty = 0
 Next

And:

Dim textfile As StreamWriter
textfile = File.CreateText(FileName(OrderDate))
Dim i As Integer
For i = 0 To Products.Length – 1
     If Products(i).Qty > 0 Then
          textfile.WriteLine(Products(i).UPC)
          textfile.WriteLine(Products(i).Qty)
    End If
Next
textfile.Close()
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.