Variable in IF THEN statement

Started by
7 comments, last by the_guy 20 years, 6 months ago
Hi there Im new to programming, i use Visual basic 6.0 . So i got a question. Is it posible to use a variable in a IF THEN statement? Here''s the code: If feld.BackColor = &HFF& Then F = 1 Else F = 2 End If "feld" is the variable.
Advertisement
What a question. o_0

Has it occurred to you to actually try it and see? If for some reason you don''t have access to a copy of VB 6.0, the answer is yes.
It wouldn''t be very useful if you couldn''t refer to a variable, now would it? I mean, what else could you put in there?
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter
I tried it but i only get a error. It says "Invalid qualifier"

and then it marks the "feld".


i try to explain my code better.

Dim feld As String
Dim numberset As Boolean
_____________________________

Private Sub NRound_Click()

If numberset = False Then

fieldnumber = (Rnd * 15)
Nummer.Caption = fieldnumber
numberset = True

End If


If fieldnumber = 15 Then
feld = "AAAABBBB"
Else

If fieldnumber = 14 Then
feld = "AAAABBB"
Else

......
end if
end if

If feld.BackColor = &HFF& Then
F = 1
Else
F = 2
End If

so, i hope it is now better to understand.
maybe the variablenames are confuse you. its a mix of german and english.


Um, you defined "feld" as a string at the start of your program. So it would not have a member "BackColor". I think perhaps you meant to reference "field.BackColor" instead which should work.

- Jason
"Iacta alea est" - Julius Caesar"So far as I know, I've never been defeated by a 'powerful over-arching potentiality' before"
quote:Original post by the_guy
I tried it but i only get a error. It says "Invalid qualifier"

and then it marks the "feld".


i try to explain my code better.

Dim feld As String
Dim numberset As Boolean
_____________________________

Private Sub NRound_Click()

If numberset = False Then

fieldnumber = (Rnd * 15)
Nummer.Caption = fieldnumber
numberset = True

End If


If fieldnumber = 15 Then
feld = "AAAABBBB"
Else

If fieldnumber = 14 Then
feld = "AAAABBB"
Else

......
end if
end if

If feld.BackColor = &HFF& Then
F = 1
Else
F = 2
End If

so, i hope it is now better to understand.
maybe the variablenames are confuse you. its a mix of german and english.





I think your field doesn''t have to me string...delete that line and see what is going to happen
so, if i delete "Dim feld As String"
there is a error message "run-time error 424: object required"
*rolls eyes*
BackColor is a property, but not all objects have this property. In order to access BackColor, you would need a Feld object that is a type which has a BackColor. For example, you could say Form.BackColor or, if you have a TextBox called TextBox1, you could say TextBox1.BackColor. However, if Feld is a mere String (which doesn''t have a BackColor property) or it doesn''t exist at all, then an error will occur.
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)

This topic is closed to new replies.

Advertisement