CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 41

Threaded View

  1. #1
    Join Date
    Jan 2006
    Posts
    20

    Red face Help with application

    I have two forms; frmMain & frmReport. I have the following coding for ensuring that the numeric data entered into each of the TextBoxes in in the correct format:

    Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
    txtRef.Text = Format(CInt(txtRef.Text), "000000")
    nudProductType.Text = Format(CStr(nudProductType.Text), "0")
    txtWeight.Text = Format(CInt(txtWeight.Text), "0000")
    txtQuantity.Text = Format(CInt(txtQuantity.Text), "0000")
    nudCalcMeth.Text = Format(CStr(nudCalcMeth.Text), "0")
    txtBuy.Text = Format(CInt(txtBuy.Text), "0000")
    txtSale.Text = Format(CInt(txtSale.Text), "0000")

    My first question is that this is VB6 and I would like to know a better way of coding this event process?

    Following on from this I then have all the data saved to a string which is then saved to a *txt file:

    Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
    txtRef.Text = Format(CInt(txtRef.Text), "000000")
    nudProductType.Text = Format(CStr(nudProductType.Text), "0")
    txtWeight.Text = Format(CInt(txtWeight.Text), "0000")
    txtQuantity.Text = Format(CInt(txtQuantity.Text), "0000")
    nudCalcMeth.Text = Format(CStr(nudCalcMeth.Text), "0")
    txtBuy.Text = Format(CInt(txtBuy.Text), "0000")
    txtSale.Text = Format(CInt(txtSale.Text), "0000")


    Dim TotalSalesFile As String
    'put fields together to go to Sales Text File
    TotalSalesFile = txtRef.Text & nudProductType.Text _
    & txtWeight.Text & txtQuantity.Text & nudCalcMeth.Text _
    & txtBuy.Text & txtSale.Text

    FileOpen(1, "TotalSalesFile.txt", OpenMode.Append)
    PrintLine(1, TotalSalesFile)
    FileClose(1)


    If MessageBox.Show("Click Yes or No", "Reset", MessageBoxButtons.YesNo) = DialogResult.Yes Then
    If MessageBox.Show("Do you wish to clear this purchase?", "Reset", MessageBoxButtons.YesNoCancel) = DialogResult.Yes Then
    'Clears existing purchase
    txtRef.Text = ""
    nudProductType.Text = ""
    txtWeight.Text = ""
    txtQuantity.Text = ""
    nudCalcMeth.Text = ""
    txtBuy.Text = ""
    txtSale.Text = ""
    Else
    End If
    End If

    My second form, frmReport is to read the TotalSalesFile.txt and display the data. My problem here is that I have a NumericUpDown (nudCalcMeth), which has two options (1 or 2) Therefore this is calculated as follows:

    Calculation Method 1 Weight * Price
    Calculation Method 2 Quantity * Price

    My second form has to perfom these calculation when it load and the using Tab print the data. I totaly unsure of how to do this and would very much appreciate someones assistance.

    I have included the app in case someone wants to view it and give feedback.

    Many thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured