1111
Printable View
1111
that code looks messed up. Don't you realize that everytime you press a key, the keypress event will fire? What are you trying to do? Also, use VB code tags. Here's how it looks:
Code:Dim IGap As Integer
Dim QGap As Integer
Dim AGap As Integer
Dim EGap As Integer
Private Type stocktable
descript As String * 24
PRICE As String * 7
You don't have to PM me to get me to read the thread.
You should zip up the project, and the files that it is supposed to be reading, and then maybe we could make some sense of it.
What does it do? What do you want the subtotal of? It looks like the instances of rec.Price are used incorrectly or commented out.
If this program ran at all, it would run 100's of times slower than it should. It is so poorly designed that it isn't worth fixing, if you ask me.
The code might look better if you use the vb code tags.
[ vbcode ]
your code
[ /vbcode ]
With no spaces inside [ ]
Your table appears to be Binary. Try to open it with notepad to see what I mean. The program doesn't read binary files.
Can you get it to do anything? I can't. Maybe if you could get it to a running state, the we could help get subtotals. I don't think that it will ever work right, as its poorly written.
If your problem has been solved the dont forget to edit your original
post and add the green checkmark as the subject icon or add
Resolved to the post's subject.
:)
then your .tbl file was corrupt. I looked at it in Notepad, after stepping through. None of the fields had values, unless it was an unsupported (Non-English) character set.
If you want to try and post it again, I'll take another look.
Do you realize that it is supposed to read 13001 fields here?
and that it happens in a keypress routine?Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim rec As stocktable
Open "c:\pos\bob.tbl" For Random As #1 Len = 120
For X% = 2 To 13001
Get #1, X%, rec
If RTrim$(LTrim$(rec.STOCKNUMBER)) = RTrim$(LTrim$(Text1.Text)) Then
'Label14 = ""
'InputBox "subtotal", subtotal
Text2.Text = rec.PRICE
Text4.Text = rec.descript
'InputBox "subtotal", rec.price
'subtotal = subtotal + rec.PRICE
'Label14 = subtotal
'Print #2, Text2.Text
also, why is everything commented out?
To get a sub-total, you have do determine which field you want to use to compute the total, then declare a field (curSubTotal as Currency), and set it to 0 first off, then add to it (curSubTotal = curSubTotal + ???) where ??? is your field.
What do you want the subtotal of? All of the records, or everything for that item, or something else?
When you start the program, what is the first step? (Load File?) or Enter Data somewhere?
I am trying to fill the list, and when I type the second letter of the description, it adds to the list. I couldn't get any items by number, so I don't know if you want to keep track of the prices that you enter before they get added, and then compute tax and subtotal, or want to loop through the listbox to subtotal the items.
You need to check for CHR(13) Enter in the keypress routine, and then move the data.
I only add them when the user hits ENTER.Code:Private Sub flx_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then ' Not Enter
If KeyAscii = 27 Then ' IS Escape
txtInput.Visible = False
Exit Sub
End If
If KeyAscii = 8 Then ' IS BackSpace
tl = Len(txtInput.Text)
If Len(tl) > 0 Then
txtInput.Text = Left(txtInput.Text, tl - 1)
Exit Sub
End If
End If
Else
flx.TextMatrix(flx.Row, flx.Col) = txtInput.Text
txtInput.Visible = False
endif
End Sub
You don't have a tax rate anywhere, but if it's 5%, just multiply the total by .05 to get the tax, or 1.05 to get the total including the tax. (I compute the tax and then add it to the subtotal to get the total.)
Here is some of my calculation code. I'm making Panels.
Code:txtTotal(4).Text = Format(PanelSubTotal, "$ ##,###.00")
PanelTax = PanelSubTotal * TaxRate
txtTotal(5).Text = Format(PanelTax, "$ ##,###.00")
PanelTotal = PanelSubTotal + PanelTax
txtTotal(6).Text = Format(PanelTotal, "$ ##,###.00")
PanelQuantity = Val(txtTotal(7).Text)
If PanelQuantity <> 0 Then
txtTotal(8).Text = Format(PanelTotal * PanelQuantity, "$ ##,###.00")
Else
txtTotal(8).Text = " Estimate Only "
PanelQuantity = 0
End If
that was code from my app. I didn't change yours. feel free to copy it and modify it for your use.
I was using a textbox that floated OVER the cell. The user types in it, and when he presses Enter, the value is transferred to the flexgrid.
Then, I have a control array of textboxes to keep the totals information.
I still have to transfer the info to one more place (or maybe two - for a summary sheet ) before my app is done. It was 35 pages last month.
I also have option buttons for choices (like taxable, and if the panel is to be assembled)
what is the name of the field that you want totalled?
where is it entered, or read?
when do you want the subtotal?
I've already showed you the code that I used to actually do the subtotal and add the tax which gives the total.
ps. just reply back to the thread, and I will see it. no need to email or PM. I won't do the work FOR you, and nobody else will, either. we'll all help you get it working, though.
I don't understand how you managed to get it working. I can't look up any part numbers that exist in the table, but can enter prices and quantities of item that i make up. I don't think that this is what you want/need, though.
tell me which buttons you press, and what you enter (and in what textbox) to get the item to subtotal.
ps - have you read anything that I've posted about the errors?
---- what do you want to do about them?
Here is how the logic should be if you want to read the file to get the part info. Change the IF statement, and then copy the values of .rec to the form.Code:Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
If KeyAscii t= 8 Then ' IS BackSpace
tl = Len(rec.PRICE)
If Len(tl) > 0 Then
Text4.text = Left(Text4.text, tl - 1)
End If
End If
Else
Dim rec As stocktable
Dim STOCKNUMBER As String
Dim a#(60, 4)
Open "c:\pos\bob.tbl" For Random As #1 Len = 120
For X% = 2 To 13001
Get #1, X%, rec
' If rec.???? = Text4.text Then Exit For
' You must use the name of the variable here
Next X%
Close #1
End If
Exit Sub
When you have something that works, post it here. I used your old project, and changed the location of the file. I could only enter one character into the textbox.
Each time you enter a quantity, calculate the total price before you put it up. also, add the total price to the subtotal variable.
when you press the subtotal button, display the value.
when you hit the total button, add the tax to the subtotal to get the total, also.
I got you program to work without generating an error.
It is very confusing, and that's probably why nobody else wanted to get involved.
If you have more problems, then post the project again, because I am deleting it.
create a subtotal field, and use it.
then, print it when you press subtotal. set a flag afterwards.
when you hit total, if you didn't press subtotal, calculate it anyways.
if you used currency data types, then divided everything by 100, you could get things to be formatted.
Code:format(text1.text."$ ##0.##")
don't you read what I post? forget about the code that I posted. to format, just change the string to what you want.
"####" is for an Integer. Use "$#,###.00" for currency.
you need to print a subtotal line, a tax line, and a total line.
post another version of the project, and I'll look at it again.
I made some changes, for subtotal, tax, and total. i didn't change anything else, though. you'll still want to change things, but I hope that I have gotten you started in the right direction.