Archived

This topic is now archived and is closed to further replies.

Variable in IF THEN statement

This topic is 5183 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites