How to Total numbers on a textbox.
Yep, As in the other post I need to know if its just as simple as I think it is.. :D
Its basicly this code but for a textbox not a list.
Code:
listprice.AddItem "Sub Total: " & subTotal
listprice.ListIndex = listprice.ListCount - 1 '<<< this will highlight new item
thanks
Re: How to Total numbers on a textbox.
You mean to highlight the last line? If so:
Code:
Dim start As Long
start = Len(Text1.Text)
Text1.Text = Text1.Text & vbCrLf & "something new"
start = start + Len(vbCrLf)
Text1.SelStart = start
Text1.SelLength = Len(Text1.Text) - start
Text1.SetFocus
Re: How to Total numbers on a textbox.
Hello, i also need this code, and we are looking for a way to make a subtotal of the numbers in a text box - nothing to do with highlighting ;)
Re: How to Total numbers on a textbox.
I'd like to hear more about the application. Doesn't seem like a text box is your best bet...?
Re: How to Total numbers on a textbox.
Okay so the program we need to make (a cash register thingie) requires you to write a bunch of items onto a datafile (using buttons in our case) then read them from the datafile (we have them going into two text boxes, one for text, one for cost) and produce a subtotal of the cost of all the items for that table/datafile. We tried doing the total with a list box but this gave us problems as far as putting the items from the datafile into the list box went (only the last item was showing =S). So yeh. We need a way to make a subtotal of the numbers in a text box. Or another way if it works xD
Re: How to Total numbers on a textbox.
I recommend a list box as the best way to present the data and then a label can be used to show the total. I doubt that you want users to be changing that total. Here's some sample code in which I build the file using random data:
Code:
Const ListSize = 20
Private Sub Command1_Click()
' Retrieve Data and Total It
Dim Total As Single, MyNumbers As String
Open "MyData" For Input As #1
For I = 1 To ListSize
Line Input #1, MyNumbers
List1.AddItem MyNumbers
Total = Total + CSng(MyNumbers)
Next
Close
Label1.Caption = "Total = " & Format$(Total, "#,###.00")
End Sub
Private Sub Form_Load()
Open "MyData" For Output As #1
' Build a Sample Data File
For I = 1 To ListSize
Print #1, Format$((Rnd * 100) + 1, "###.00")
Next
Close
Label1.Caption = vbNullString
End Sub
If you wish to keep adding numbers to the file, use a text box for data entry and open it for Append to write to the file.
Re: How to Total numbers on a textbox.
Thanks. I shall use that once I learn how to print to a listbox.
:P :)
And haha demonic I've got more posts than you!!! :D
Re: How to Total numbers on a textbox.
I hope you guys realize that you're doing someones homework for them. Read the first line in post 5.:rolleyes:
Re: How to Total numbers on a textbox.
Good point. But man, what a horrible assignment for learning VB. Can't they come up with anything that's even remotely like a real-world situation?