06-01-2005, 08:14 AM
I am trying to calculate a figure with the user's selection from a multiline text box (which is nothing more than a vertical scroll of numbers 1 through 20) and another variable which I dimensioned as an integer. I am getting an error 13 type mis-match. It would appear from monkeying around that the value being passed from the multiline text box is considered a string, not a number. If I reduce the list (or text) to just one line (ie one available number) it works okay. But adding additional lines (ie numbers) to the list creates the type mis-match. How do you tell VB that the values in that list are all numbers? There's no property in the text box that addresses that.
06-01-2005, 08:28 AM
There are several conversion functions to use: CInt(), CLng(), CDbl(), etc. You may be experiencing a problem with the space between the numbers not being recognized as a number, thus an error occurs.
Is there a reason why you are not using a combobox or listbox for this? It seems much better suited for your application.
06-01-2005, 08:34 AM
Would you do this right before you call the value into your formula or just as a general declaration?
As for the scrolling list on a textbox, this actually seems better suited to me. I just want to make the navigation and selection easier for the user...this way they don't have to go from mouse to keyboard to select a value. Just scroll through a list and boom.
06-01-2005, 08:37 AM
How are you adding numbers to a textbox? If you are using "+" to join strings, you might be getting errors because VB doesn't know whether you want to add or concatenate. If you are using "+" then try using "&" instead.
06-01-2005, 08:43 AM
I'm actually not adding numbers TO the textbox, just selecting from it. I set up the textbox as a multiline textbox with vertical scrollbars. Then I entered the numbers in the Text field (which by the way is painful since you can only enter one value at at time). The are entered, and appear in the listing when you edit it, as a column. I was careful not to enter spaces or other extraneous information next to each number so as not to make it look like a string and not a number.....but it did anyway.
06-01-2005, 08:47 AM
Can you post the relevent code? How are you getting the numbers from the textbox?
As far as using a listbox or combobox; most windows users expect to see this type of control for choosing values. It would be more unusual to use a textbox for them.
06-01-2005, 09:13 AM
Dim HT As Integer
Dim WIDTH As Integer
Dim QUANTITY As Integer
HT = frmHEAVYDUTY.txtHEIGHT
WIDTH = frmHEAVYDUTY.txtBASE
QUANTITY = frmHEAVYDUTY.txtQTY
txtSKINCOST = FormatCurrency(((HT + WIDTH + 2.25) * 4.68) * MATERIALCOST)
BTW...I tried HT = CInt(frmHEAVYDUTY.txtHEIGHT) and it didn't work.
I am pulling the value residing in the text box (txtHEIGHT) from the form that it resides in (frmHEAVYDUTY). It works fine witrh just one value in the multiline text box and if I strip out the multiline features and just type in a value it works too.
06-01-2005, 09:45 AM
If you use a multiline textbox, each line is terminated with extra characters (vbCfLf or ASCII 10 & ASCII 13). It is this that is getting in the way for you. When you select each line, you have to strip off these characters.
You might get away with using the Val() function on it first as this should return a usable number from a string.
HT = Val(frmHEAVYDUTY.txtHEIGHT) 'returns a double.
BTW, as your code stands, you are passing the entire contents of the textbox to the variables. This means that all the entries with their carriage return and line feed terminators are there. I really think that using a listbox or combobox is the correct method. It would be much simpler.
06-01-2005, 12:15 PM
Thanks for your help. I appreciate it.