Variable in IF THEN statement
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.
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.
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?
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.
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
- Jason
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"
there is a error message "run-time error 424: object required"
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement