|
-
Aug 3rd, 2008, 09:40 PM
#1
Thread Starter
New Member
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.. 
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
-
Aug 4th, 2008, 03:49 AM
#2
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
-
Aug 5th, 2008, 04:08 PM
#3
New Member
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
-
Aug 5th, 2008, 04:10 PM
#4
Lively Member
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...?
-
Aug 5th, 2008, 04:21 PM
#5
New Member
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
-
Aug 5th, 2008, 05:03 PM
#6
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.
Last edited by Code Doc; Aug 5th, 2008 at 06:17 PM.
Doctor Ed
-
Aug 7th, 2008, 05:26 PM
#7
Thread Starter
New Member
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!!!
-
Aug 7th, 2008, 07:31 PM
#8
-
Aug 11th, 2008, 03:25 PM
#9
Lively Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|