English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hi , I have list box in my program , single line in the list contains price and QTY and I have text box called txt_sum , I want program to do calculations when something added in side the list box so answer will be in the text box simultaneously

How list box looks like

e.g 2 QTY. £3.57 ,

thank you

2006-12-21 23:10:34 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

Since you may have several text boxes with different bits of info in them, I assume that you are assembling (Concatenating) these different textbox values into a string and loading this string into the list box....

Create a module level private variable

Private m_ListTotal as double 'holds total value of items in list

You will need to also DIM two more variables in your sub/function

dim str as string 'hold a copy of text
dim num as double 'hold converted value
Although you may cram many steps into one line and not use some or all extra variables... I preferr to use them so as to improve readability of the code.

The m_ListTotal value is cleared to zero whenever you clear the listbox
Next whenever you add an item to your list you will use the text in textBox_Price convert the text to a number and add its value to the total

listbox.add .....
str = textbox_Price.text 'copy text into str
num = cdbl(val(str)) 'convert str into a number and ensure it is of type double

m_ListTotal = m_ListTotal + num 'totalize

You will then format m_ListTotal and display in a labelbox

The key to this working properly is the VAL function....
Val will convert string numbers into a value. This function starts the numeric conversion on the left most character and continues working right until it encounters the first non-numeric character.
It may only convert a portion of a string...

example:
string Value
45 ==> 45
45$ ==> 45
$45 ==> 0

45 or 50 ==> 45

If you have difficult because you are including a monetary symbol in your textbox you should limit entry into the textbox to numeric data only through validation. Add your symbol during the string concatenation before adding the string to the listbox

2006-12-22 00:47:47 · answer #1 · answered by MarkG 7 · 0 0

check out http://www.pscode.com for great examples.

2006-12-22 22:13:09 · answer #2 · answered by Richard H 7 · 1 0

fedest.com, questions and answers