Help with some simple visual basic code...

 
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions
View previous topic :: View next topic  
Author Message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 19, 2005 8:52 pm    Post subject: Help with some simple visual basic code... Reply with quote

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 View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Wed Oct 19, 2005 10:40 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 19, 2005 10:42 pm    Post subject: Reply with quote

*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 View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Thu Oct 20, 2005 12:00 am    Post subject: Reply with quote

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 View user's profile Send private message
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Thu Oct 20, 2005 12:04 am    Post subject: Reply with quote

*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 View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 20, 2005 8:02 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Thu Oct 20, 2005 1:14 pm    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group