PDA

View Full Version : Anyone skilled on VB, please help



stawte
20-01-11, 21:21
Could somebody help me with this, as I am getting an error saying object required: "n".

I did declare it, value 1 stands for btnA, so I don`t know why doesn`t work. This is the bit of code.
Dim btn(8)
Dim n
Dim m
Sub Window_onLoad()
Randomize
btn(1) = "A"
btn(2) = "B"
btn(3) = "C"
btn(4) = "D"
End Sub
Sub btnStart_OnClick()
btnStart.value="Play"

n=1+Int(Rnd()*8)
m=1+Int(Rnd()*2)

End If
End Sub

Sub btnA_onClick()
If n.value="1" Then
feedback.innerText="Corect!"
Else
feedback.innerText="Wrong! Try Again!"

End If
End Sub

iGoD ReLeNtLeS
20-01-11, 22:06
i believe you need to use


Dim n As Integer
Dim m As Integer

or whatever datatype you are using them vars for, from what i can see its going to be an integer.

Also in your Rnd() i believe you need some parameters too.

May be wrong, i've only done a little VB.net.

stawte
20-01-11, 22:46
Thanks, but is not working. Many thanks anyway!

DoubleTop
20-01-11, 22:58
what is it you are trying to do? That code is pretty difficult to try to understand what homework you've been set ;)

Spaceboy
20-01-11, 23:02
I don't know VB at all having never coded it but... isn't there an extraneous EndIf in the following ?


Sub btnStart_OnClick()
btnStart.value="Play"

n=1+Int(Rnd()*8)
m=1+Int(Rnd()*2)

End If
End Sub

stawte
20-01-11, 23:27
I don't know VB at all having never coded it but... isn't there an extraneous EndIf in the following ?


Sub btnStart_OnClick()
btnStart.value="Play"

n=1+Int(Rnd()*8)
m=1+Int(Rnd()*2)

End If
End Sub

Is just fragment of the entire code. The code is around 700 lines.


what is it you are trying to do? That code is pretty difficult to try to understand what homework you've been set ;)

It is difficult indeed, but is a project at uni, altough I`m not on IT course. I really cannot explain, cos I can barely understand myself.



But I managed to do it. Turns out that there`s no need for ".value" after n, since n is a declared variable.
Thank guys!

DoubleTop
20-01-11, 23:43
Nice one :chuckles: not being sure on what you wanted, and with not wanting to give the game away, tbh it was pretty obvious.

Types in VB are assumed, so you declared a type 'n', the moment you gave it a value it became an INT and then treated it as an object. In a "proper" language, you declare variables with a type, such as Smifis posted.

DT.

stawte
21-01-11, 08:47
Nice one :chuckles: not being sure on what you wanted, and with not wanting to give the game away, tbh it was pretty obvious.

Types in VB are assumed, so you declared a type 'n', the moment you gave it a value it became an INT and then treated it as an object. In a "proper" language, you declare variables with a type, such as Smifis posted.

DT.

Well, yeah it is obvious for somebody who knows, but for me is not really. Cos is just a "side" module and is the first time when I`ve came in contact with programming.
I still get loads of errors, but I take each one and try figure it, but some are just ..........:censored:

Thanks guys very much.

andyn
21-01-11, 09:17
In a "proper" language, you declare variables with a type, such as Smifis posted.


Bah @ strongly-typed language nazis, you're as bad as jhorner :P.

Perl FTW.

DoubleTop
21-01-11, 09:28
that came close to costing me a new monitor :lol:

stawte
21-01-11, 14:31
One more little thing guys. As you can see in the above code, I`ve declared the variables and randomize them, but how can I make sure that doesn`t plays the same sound twice in succession?

Smifis
21-01-11, 15:10
Nice one :chuckles: not being sure on what you wanted, and with not wanting to give the game away, tbh it was pretty obvious.

Types in VB are assumed, so you declared a type 'n', the moment you gave it a value it became an INT and then treated it as an object. In a "proper" language, you declare variables with a type, such as Smifis posted.

DT.
I did?


You could make it the random variable wider I suppose.

DoubleTop
21-01-11, 15:44
One more little thing guys. As you can see in the above code, I`ve declared the variables and randomize them, but how can I make sure that doesn`t plays the same sound twice in succession?

have a 'spare', an o and p if you like :) to remember last values. Ofc, if you are making sure you don't get two the same, you're not randomising