PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Very simple question for all u brains out there

Im a BIG noob at evb, im making a little program for myself to work out the cost of computer parts, i need to know how to add together the inputs from all the boxes then display it in the total :).
This is the layout:
Image

I just need the code to make it work, please rember to keep it simple I have only done very simple stuff like programs that can load the text you enter into a label.

heres the code with all the names of the labels
Code:
Option Explicit

Private Sub Form_OKClick()
App.End
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub

Private Sub Label7_Click()

End Sub

Private Sub Label8_Click()

End Sub

Private Sub Label9_Click()

End Sub

Help getting me going would be great ! thanks
I don't really know VB very well, but on a desktop, a simple solution would be:

in your command click event

Code:

dim cost as single

cost = 0
cost = cost + text1.text
cost = cost + text2.text
cost = cost + text3.text
cost = cost + text4.text
cost = cost + text5.text
cost = cost + text6.text

label7.caption = cost


Of course, that is just quick and dirty. You may want to name your controls something a little more descriptive than the default name too, espescially the text boxes and the command button. It won't matter much in a simple program, but once you get 4 or 5 buttons, it can start to get annoying.
Thanks for the help, I managed to use code you gave me for adding the things together and now it works :D.
aah wait it isnt working propely its just putting the numbers together not adding them up :(. I have just used this bit of code :
Code:
cost.Caption = text1.Text + text2.Text

how can I make it add them up ?
Draluy · 17 Apr 2003, 14:29 UTC — re
Well u are currently using strings, and vb redefines operator + to put two strings togheter. vb "doesn't know" these strings are in fact numbers. U have to first turn them into numbers. I don't exacly remenber how to do that (it's been a long time...)
but i think it was something easy.
Uhm... tomdon, go to:
http://rain.prohosting.com/~moosem/wwpc.html

and download my application there. It's in vb source for the PPC. It waits for the input of all three boxes to be full (floating point only) and then allows the user to press the Equals button to apply a formula which is just really one long addition string, and then outputs it in the final box. Maybe that will help you. I'd just tell you the source but I don't have VB installed.
After reading thought what you all said I have come up with a soloution that works :D.
Code:
Option Explicit
Dim cost As Single

Private Sub Command1_Click()
cost = 0
cost = cost + text1.Text + text2.Text + text3.Text + text4.Text + text5.Text + text6.Text

Label7.Caption = cost

End Sub

Private Sub Form_OKClick()
App.End
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub

Private Sub Label7_Click()

End Sub

Private Sub Label8_Click()

End Sub

Private Sub Label9_Click()

End Sub


Thanks for all the help everyone I know im anoying asking simple questions but we all have to start somwhere ;)
Technically, you should check for the values of the textboxes first before adding them up because an error could occur if someone types in a non-numeric char on one of your textboxes. :) just a small reminder.
ah that wont matter because im making it just for my own use, I have about a hundred bits of paper with notes about how much stuff costs so this should save some time.
I think what would be good now is to be able to save all the things into a text file in a list like this:

Case: Shuttle £200
CPU: AMD £130
etc etc etc

This is what it looks like at the moment, I have added a name bit so I know what thing im talking about. The problem is I tried using the tutorial at http://www.justppc.com/evb5.shtml for saving and loading, and it works fine for a single box, but I cant work out how to save all the boxes then be able to reload them all.
Image


**Update**
I have decided to stick within my Knowledge, so I have come up with a sollution, I now have a button that saves all the information into a text box at the bottom, then saves it all as a text file which can be viewed again in the text box at a latter date :D. I know its simple and probbaly bad programming but im chuffed that I have found a way around the problem I faced.
In the dialog editor (or whatever it's called in eVB) where you lay out the controls you should be able to specify the data type and range for that edit box.

Dan East
i have another question :) hehe sorry, i need to put a break in the line between each component, this is the code for one line:

Code:
text.text = "Case" + " - " + cpn1.text + " - " + "£" + text1.text


This is how the above apears in the text box :

Case - Shuttle - £200

When I add the next component I need it to be below the first, how can I do that ? just having it straight after didnt work :(
text.text = "Case" + " - " + cpn1.text + " - " + "£" + text1.text + vbcrlf