Jump to content

Trouble with cases

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
25 replies to this topic

#1
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Why doesn't this works?


Select Case Player1.Parent


            Case Box1





        End Select

It gives an error and the "box1" is blue highlighted, I want that when the parent of player 1 is box1 that something happens and I want to do this with cases how?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You need to put quotes (") around Box1. IE:

[highlight=vb]
Select Case Player1.Parent
Case "Box1"

End Select
[/highlight]

#3
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
mm, that also doesn't work, cannot be converted to string.

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What is the type of Player1.Parent? You will need to convert this to a string in order to use a string select/case.

#5
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
It is a panel

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Like I told you before, remember? Is this the same question?

You've forgotten the End Case statement. Try this:

[highlight=vb]
Select Case Player1.Parent

Case Box1
'Code here.
End Case

Case Box2
'Code here.
End Case

End Select
[/highlight]
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
No, you dont need the "end case" in vb 2005, the problem is: I got a 2 panels, a little one: Player1. and a big one: Box1 and another big one: Box2. And I try to make cases for those that it will move from box to box. But like I did it doesn't work. It looks like you cant do cases like that with panels or something :S

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
What error does it give you with the code you first posted?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Operator '=' is not defined for types 'System.windows.forms.control' And 'System.windows.forms.panel'

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
That doesn't make sense - after all, in the other thread I told you how to use the = operator with Box1.Parent = Panel. I can't think of anything at the mo, but I'll rack my brains.

@ Jordan, are you familiar with the Parent property? It is not a string - it is a System.Windows.Forms.Control, and represents the control on which another control is within. Converting it to a string will get wazofski nowhere.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I know what you said last time with those cases, that was for my mastermind game, and that turned out well and it is finished, but this is wierd that it doesn't works like that

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I don't mean those - I meant with the set/change location of objects one, remember? I told you to do this:
[highlight=vb]
Box1.Parent = Panel1
[/highlight]

You see, even though Parent and Panel1 are different types, VB2005 allowed us to set one as the other. It should work here as well.

I just have this tiny idea - try this?

[highlight=vb]
Box1.Parent = Form1.Controls("Panel1")
[/highlight]

Replace "Form1" with your form name. Does it work?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums