Dear OT79,
in the frmReport forms code
make the line
For i As Integer = 0 To UBound(sales)
to
For i As Integer = 0 To UBound(sales) - 1
and try once again.
Pramod S Nair
Printable View
Dear OT79,
in the frmReport forms code
make the line
For i As Integer = 0 To UBound(sales)
to
For i As Integer = 0 To UBound(sales) - 1
and try once again.
Pramod S Nair
To PramodsNair,
Just before I say anthing else, many thanks to you for your continued assistance, its very much appreciated!
I ammended the coding to your suggestion and that solved the error. My only problem is that the sales file isn't showing the values calculated? As you will see on the descriptive it needs to show the Buy and Sale price, with the inclusion of the Values? I also need to get them displayed like the following:
Buying Sale
Ref No Type Weight Qty CalcMeth Price Value Price Value
P £ P £
100033 1 20 0 1 14.0 2.80 33.0 6.60
100033 1 20 0 1 13.0 2.70 32.0 6.40
etc..............
Thanks
p.s. the above example should be displayed with the Buying and Sale above Price and Value, P is under Price and the £ is under Value, it has bunched it all up when I posted it, if unclear!
Well how are they being displayed now?
I'm not displaying the Sale Value? I also require the Buying (Price & Value) and the Sale (Price & Value) to be displayed in decimal? Is there a way that I can drop the leading zeros also?
Many thanks
Dear OT79,
Could you please give me detailed info on the way in which you need the report to be shown. i.e, is the price (sales/purchase) are to be parsed in to pound and pence, what is the differnece you mean on the price and value etc. Then i will try to do this report section for you, even if my schedules are a bit tight.
Pramod S Nair
Dear PramodsNair,
Many thanks. On the actual report (i've included a screen shot attachment of how the report is to look) the calculations are as discussed:
CalcMeth 1 Weight * Price
CalcMeth 2 Quantity * Price
Therefore in the first instance (CalcMeth1) the calculations are to be Weight * the Buy Price and the Sale Price, thus giving two seperate values ( Buying Value and Sale Value), this is also the case with the second CalcMeth2, where Quantity is to be Qty * Buy Price and then also Qty * Sale Price. I think currently I'm only performing i.e Weight * Buying price, which is giving only one Value!
* As the sale and buying prices have been entered in tenths (1/10) of a pence on form1, these need to be divided by 1000 to give a value in pounds (£) and pence (p) e.g. 1230 will be £1.23, plus I also need to drop leading zeros?
p.s. I have also included the app in case that is more helpful.
Many thanks for your assistance.
Dear OT79,
i didn't until the last post noticed the need for multiplying both sales and buying with quantity. i got it this time.
i will try to post a prg to meet your need by Monday eve. Weekend :wave: so a bit busy. i am working on it and will post it by Monday. don't worry
Pramod S Nair
Hi PramodsNair:
Many thanks for that, you have been a great help!
Regards
OT
Dear OT79,
I have rebuilt the Report Form's Load event to meet your demands. please use the below given code .
I think to display the records properly, you can use a Flex grid instead of writing to a textbox as this can affect the alignment. If you need any help regarding the use of flexgrid pls feel free to contact.Code:Private Sub frmReport2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This subrouting uses a StreamReader object to open an existing file when the form loads
Dim ReportStream As StreamReader
ReportStream = _
New StreamReader("TotalSalesFile.txt")
'''Made a Change Here
Dim tempstr As String
'RichTextBox1.Text = ReportStream.ReadToEnd
tempstr = ReportStream.ReadToEnd
''''''''''
ReportStream.Close()
'RichTextBox1.Select(0, 0)
''''''''''''''
'Another change
' The quick and dirty way of handling
'Added by Pramod S Nair
Dim TotsalesStr As String
Dim sales
sales = Split(tempstr, vbLf) ' Split your file using Linefeed character to get the individual sales entries
For i As Integer = 0 To UBound(sales) - 1
'Now split each sales record using Tab as
'we added a vbtab after each entry while
'constructing the sales record.
Dim esale
esale = Split(sales(i), vbTab)
'Now we have each field in esale
' check the fifth array item to find way of calculation
Dim amt1, amt2
If esale(4) = "1" Then
' the calculation method is 1
'Calculation Method 1 Weight * buy Price
'and weight * sale price
'The 3rd member of esale array is weight and now multiply
' it with your price (Here i presume the 6th one that is buying
' is the amount is the price you are talking about )
amt1 = esale(2) * esale(5) 'Buy * weight
amt2 = esale(2) * esale(6) 'sale * weight
Else
' the calculation method is 2
'Calculation Method 2 Quantity * Price
'and quantity * sale price
'The 4th member of esale array is qty and now multiply
' it with your price (Here i presume the 6th one that is buying
' is the amount is the price you are talking about )
amt1 = esale(3) * esale(5) ' buy * qty
amt2 = esale(3) * esale(6) ' sale * qty
End If
'now rebuild the record with the amt we calculated
TotsalesStr = TotsalesStr & Val(esale(0)) & vbTab & Val(esale(1)) & vbTab & Val(esale(2)) & vbTab & Val(esale(3)) & vbTab & Val(esale(4)) & vbTab & Math.Floor(Val(amt1) / 1000) & vbTab & Val(amt1) Mod 1000 & vbTab & Math.Floor(Val(amt2) / 1000) & vbTab & Val(amt2) Mod 1000 & vbTab & vbNewLine
'TotsalesStr = TotsalesStr & Mid(sales(i), 1, sales(i).length - 1) & vbTab & amt & vbNewLine
Next
RichTextBox1.Text = TotsalesStr
''''''''''''''''
End Sub
Pramod S Nair
To PramodsNair,
I have implemented the code you have gratefully worked on; however it would appear that it is displaying Vaue (Buy and Sale) as 0? It doesn't appear to be multiplying correctly? Is there a way also of displaying the BuyPrice and Value in decimal when the form2 loads the txt* file?
Many thanks for assistance, sorry to be a pest.
Regards
OT
Dear OT79,
OOPS !!! My Mistake, i just messed the order of Pence and Pound calculation.
Mistake is in the below given line,
I have corrected it and the new line of code will be,Code:TotsalesStr = TotsalesStr & Val(esale(0)) & vbTab & Val(esale(1)) & vbTab & Val(esale(2)) & vbTab & Val(esale(3)) & vbTab & Val(esale(4)) & vbTab & Math.Floor(Val(amt1) / 1000) & vbTab & Val(amt1) Mod 1000 & vbTab & Math.Floor(Val(amt2) / 1000) & vbTab & Val(amt2) Mod 1000 & vbTab & vbNewLine
Please reflect the above change and it will sure work (:-) it is working here). Still if you have any probs with the program, feel free to contact.Code:TotsalesStr = TotsalesStr & Val(esale(0)) & vbTab & Val(esale(1)) & vbTab & Val(esale(2)) & vbTab & Val(esale(3)) & vbTab & Val(esale(4)) & vbTab & Val(amt1) Mod 1000 & vbTab & Math.Floor(Val(amt1) / 1000) & vbTab & Val(amt2) Mod 1000 & vbTab & Math.Floor(Val(amt2) / 1000) & vbNewLine
Sorry for being careless.
Now being for a Pest, it's my pleasure to help others as i myself improved in this industry due to other peoples who were devoted in giving help. So pressing me by asking for assistance is not bothering me at all (hmmm, may be my schedule gets a bit tight ;) , but it's a thrill).
Pramod S Nair
Hi PramodsNair,
That works now; however running the app I have realized that the Buying Price and the Sale Price are the result of the multiplication Weight * Buying Price / Weight * Sale Price? Perhaps I haven’t given you a full enough explanation of the Sales Report display. Under the Buying Price and Sale Price is to be the original user input amounts from the MainMenu (Form1); the resulting Value (Buy & Sale) is the Weight * Buy price, and obviously Weight * Sale Price. Therefore only one calculation needs to be performed for Buy Value and the Sale Value. Is there a way to amending the coding to fit this? Is it also possible to show a decimal point for both Buying – (Price & Value) and Sale – (Buying and Value)?
Many thanks
Dear OT79,
is the original sale & buying price also be parsed to pense and pound ?
is the output be needed like this
BuyPriceEnteredbyUser <> BuyValueCalculatedByUs <> SellPriceEnteredbyUser <> SellValueCalculatedByUs
where <> is a tab
Pramod S Nair
Hi:
Yes, the original Buy Price & Value are to be pence, and yes the output you have displayed above is correct: Buy Price entered by user displayed, Buy Value calculated and displayed by us, same for Sale. Sorry I should have added this much sooner, only realised when I ran the app and saw the outputted results!
Many thanks
OT