PDA

View Full Version : Help Needed!!


fuzzy
11-17-2009, 02:31 PM
Hi,

I'm a bit of a novice i'm afraid, but i was hoping that someone might be able to help get around a compile error in visual basic.

Details as follows:

I am using code to update a textbox with the values from a number of other textboxes. - my code will only allow me to add the values of 44 textboxes, and rather annoyingly, i want it to add 45..!

Code as follows:

Sub UpdateTotal()
TextBox2.Value = Val(TextBox3.Value) + Val(TextBox4.Value) + Val(TextBox5.Value) + Val(TextBox6.Value) + Val(TextBox7.Value) + Val(TextBox8.Value) + Val(TextBox9.Value) + Val(TextBox10.Value) + Val(TextBox11.Value) + Val(TextBox12.Value) + Val(TextBox13.Value) + Val(TextBox14.Value) + Val(TextBox15.Value) + Val(TextBox16.Value) + Val(TextBox17.Value) + Val(TextBox18.Value) + Val(TextBox19.Value) + Val(TextBox20.Value) + Val(TextBox21.Value) + Val(TextBox22.Value) + Val(TextBox23.Value) + Val(TextBox24.Value) + Val(TextBox25.Value) + Val(TextBox26.Value) + Val(TextBox27.Value) + Val(TextBox28.Value) + Val(TextBox29.Value) + Val(TextBox30.Value) + Val(TextBox31.Value) + Val(TextBox32.Value) + Val(TextBox33.Value) + Val(TextBox34.Value) + Val(TextBox35.Value) + Val(TextBox36.Value) + Val(TextBox37.Value) + Val(TextBox38.Value) + Val(TextBox39.Value) + Val(TextBox40.Value) + Val(TextBox41.Value) + Val(TextBox42.Value) + Val(TextBox43.Value) + Val(TextBox44.Value) + Val(TextBox45.Value) + Val(TextBox46.Value)
End Sub

If i try to add another value to the list, it goes red and won't work, and i get either a "compile error:syntax error" or "compile errror: Expected:line number or label or statement or end of statement".

Hope you can help me,

Thanks,

Fuzz :confused:

drhowarddrfine
11-17-2009, 04:07 PM
Great title!!!!!!

brad211987
11-17-2009, 05:16 PM
Syntax wise......I don't see anything particularly wrong that jumps out at me. Is there a statement length restriction in VB perhaps? I'm not as familiar with VB as I'd like to be so I may be missing something.

You may want to re-analyze your approach here though, looking at the massive concatenation is giving me chills. At the very least you could store the text boxes in a collection that you can iterate over, that would clean up the code substantially.

it career
11-18-2009, 07:08 AM
Do not you need ; at the end of line in VB ?

Fou-Lu
11-18-2009, 07:40 AM
Hi,

I'm a bit of a novice i'm afraid, but i was hoping that someone might be able to help get around a compile error in visual basic.

Details as follows:

I am using code to update a textbox with the values from a number of other textboxes. - my code will only allow me to add the values of 44 textboxes, and rather annoyingly, i want it to add 45..!

Code as follows:

Sub UpdateTotal()
TextBox2.Value = Val(TextBox3.Value) + Val(TextBox4.Value) + Val(TextBox5.Value) + Val(TextBox6.Value) + Val(TextBox7.Value) + Val(TextBox8.Value) + Val(TextBox9.Value) + Val(TextBox10.Value) + Val(TextBox11.Value) + Val(TextBox12.Value) + Val(TextBox13.Value) + Val(TextBox14.Value) + Val(TextBox15.Value) + Val(TextBox16.Value) + Val(TextBox17.Value) + Val(TextBox18.Value) + Val(TextBox19.Value) + Val(TextBox20.Value) + Val(TextBox21.Value) + Val(TextBox22.Value) + Val(TextBox23.Value) + Val(TextBox24.Value) + Val(TextBox25.Value) + Val(TextBox26.Value) + Val(TextBox27.Value) + Val(TextBox28.Value) + Val(TextBox29.Value) + Val(TextBox30.Value) + Val(TextBox31.Value) + Val(TextBox32.Value) + Val(TextBox33.Value) + Val(TextBox34.Value) + Val(TextBox35.Value) + Val(TextBox36.Value) + Val(TextBox37.Value) + Val(TextBox38.Value) + Val(TextBox39.Value) + Val(TextBox40.Value) + Val(TextBox41.Value) + Val(TextBox42.Value) + Val(TextBox43.Value) + Val(TextBox44.Value) + Val(TextBox45.Value) + Val(TextBox46.Value)
End Sub

If i try to add another value to the list, it goes red and won't work, and i get either a "compile error:syntax error" or "compile errror: Expected:line number or label or statement or end of statement".

Hope you can help me,

Thanks,

Fuzz :confused:

Its been awhile for me as well, but I recall that VB actually pukes on semi-colons. I always found it odd...
Anyway, with what you have here its tough to tell since its not in code blocks, but are you wrapping those lines like that:

(TextBox33.Value) + Val(TextBox34.Value) + Val(TextBox35.Value) + Val

?
If so, its likely dying when it sees a Val without any parameter to it followed by a linebreak followed by the parameter list.

brad211987
11-18-2009, 02:47 PM
If i try to add another value to the list, it goes red and won't work

That's where I was stumped, it implies to me that its working in its current form but adding another concatenation breaks it?

oracleguy
11-18-2009, 05:09 PM
Its been awhile for me as well, but I recall that VB actually pukes on semi-colons. I always found it odd...
Anyway, with what you have here its tough to tell since its not in code blocks, but are you wrapping those lines like that:

(TextBox33.Value) + Val(TextBox34.Value) + Val(TextBox35.Value) + Val

?
If so, its likely dying when it sees a Val without any parameter to it followed by a linebreak followed by the parameter list.

That is important because in VB you have to use an underscore to mean the code continues on the next line. The line delimiter is a colon or a newline. You rarely see the former though, usually just the latter.

testware
11-21-2009, 11:12 AM
There might be a limit to the number of expressions you can compute on a single line. But honestly - it's not a good idea to be doing this. Instead create an array of textboxes and sum up the value using a loop - cleaner and easier to handle.