View previous topic :: View next topic |
Author |
Message |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 19, 2005 8:52 pm Post subject: Help with some simple visual basic code... |
|
|
Hello,
I have something I want to do in Visual Basic, and its simple but I cant work it out. I want to transfer text from a text input box into a variable for use in a equation I want to do.
I have the code as follows:
Quote: | Private Sub wattstovoltamps_Click(OutputMessage As Integer)
InputNumber = Var(WattsBox.Item.Text)
OutputMessage = WattsBox / 0.7
MsgBox OutputMessage
End Sub |
and i get the error:
Quote: | Compile error, argument not operational |
on the .Item part of the script and then the top line highlights in yellow.
Any ideas? Ive tried just about everything and according to one of my friends the code is correct.
Thanks in advance. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
roganty -
Joined: 08 Jun 2004 Posts: 357 Location: Bristol, UK
|
Posted: Wed Oct 19, 2005 10:40 pm Post subject: |
|
|
my understanding of vb is sketchy to say the least...
Code: | Private Sub wattstovoltamps_Click(OutputMessage As Integer)
InputNumber = Var(WattsBox.Item.Text)
OutputMessage = WattsBox / 0.7
MsgBox OutputMessage
End Sub |
is this code being called from a webpage or an actual program?
if its a webpage the 2nd line might need to read:
InputNumber = Var(document.WattsBox.Text)
if from a program then i dont think that you need the Item part. eg
InputNumber = Var(WattsBox.Text)
i also think that it needs to be Val() instead of Var() _________________ Anthony R
Roganty | Links-Links.co.uk |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 19, 2005 10:42 pm Post subject: |
|
|
*Slaps self*
It was supposed to be "Val" but it still causes the same error. It is an actual VB program and isnt called from a web page.
It makes no odds if the ".Item" bit is there or not it still causes the same error but then on the ".Text" part of it.
Quote: | Private Sub wattstovoltamps_Click(OutputMessage As Integer)
InputMessage = Val(WattsBox.Item.Text)
OutputMessage = InputMessage / 0.7
MsgBox OutputMessage
End Sub |
This is what I have yet I still get an error with the WattsBox.Item.Text part regardless of whether .Item is there or not. It just says .Text or .Item is the problem then highlights, as before, the top line in yellow. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Thu Oct 20, 2005 12:00 am Post subject: |
|
|
I haven't used VB in a long while... Are you sure .Text is the correct variable, and not .Value or some other object property?
Are you sure the error isn't "Argument Not Optional"? _________________
"Invent an idiot proof webserver and they'll invent a better idiot..." |
|
Back to top |
|
 |
roganty -
Joined: 08 Jun 2004 Posts: 357 Location: Bristol, UK
|
Posted: Thu Oct 20, 2005 12:04 am Post subject: |
|
|
*been thinking*
Private Sub wattstovoltamps_Click(OutputMessage As Integer)
should it be like that or...
Private Sub wattstovoltamps_Click()
*shrug* _________________ Anthony R
Roganty | Links-Links.co.uk |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Thu Oct 20, 2005 8:02 am Post subject: |
|
|
roganty wrote: | *been thinking*
Private Sub wattstovoltamps_Click(OutputMessage As Integer)
should it be like that or...
Private Sub wattstovoltamps_Click()
*shrug* |
I have tried that then it comes up with "argument not found" as the error :-s _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
abyssisthebest -
Joined: 30 Jun 2005 Posts: 319 Location: Boston, UK
|
Posted: Thu Oct 20, 2005 1:14 pm Post subject: |
|
|
try this
Code: |
Private Sub wattstovoltamps_Click(OutputMessage As Integer)
Var = InputNumber(WattsBox.Item.Text)
OutputMessage = WattsBox / 0.7
MsgBox OutputMessage
End Sub
|
-or-
Code: |
Private Sub wattstovoltamps_Click(OutputMessage As Integer)
InputNumber = var(WattsBox.Item.Text)
MsgBox (& wattsbox.text / 0.7)
End Sub
|
I have created some code that does the same but is a lot smaller
Code: |
MsgBox ("Watts = " & wattsbox.text / 0.7, VBYesOnly)
|
That should work, but i am school and i cant check it.
P.S I use Visual Basic 2003 Pro _________________ My online Portfolio |
|
Back to top |
|
 |
|