TIP: Click on subject to list as thread! ANSI
echo: visual_basic
to: All
from: `kirk Shirley` kirkshirl
date: 2005-02-11 19:06:00
subject: Re: Case problem

Thanks again Rick,
your right as usual.  This is my frist VB program.
Kirk
Rick Rothstein  wrote in message
news:17-dnWdNeN3vhZDfRVn-pQ{at}comcast.com...
> > I am using VB 6 and trying to select 1 of 3 matrixes depending on 1 of
> 3
> > option buttons using the case statement.  Display is a variable 1-3 of
> the
> > matrix to be displayed. Option Buttons are named SelectMatrix (0),
> > SelectMatrix (1), & SelectMatrix (2) . The problem is the Case
> SelectMatrix
> > has to be set to a test expression but this always prints out the 1st
> case
> > for every option button selected.
> >
> > Private Sub SelectMatrix_Click(Index As Integer)
> > Dim Display As Integer
> > Select Case SelectMatrix(0)
> >    Case SelectMatrix(0).value = True
> >        Picture4.Cls
> >     Display = 0
> > Case SelectMatrix(1).value = True
> >        Picture4.Cls
> >     Display = 1
> > Case Else
> >        Picture4.Cls
> >     Display = 2
> > End Select
> >     'test code below to see what was selected
> >     Picture4.Print Display
> > End Sub
>
> Off the top of my head (and based on a very quick look), I am not sure
> why the first cast is being selected; however, you are using the wrong
> value in your Select Case statement. Do you see the "Index As Integer"
> argument inside the Click event's parentheses? That is a
"freebie" that
> VB gives you for control arrays. It identifies the Index value of the
> control array item that triggered the event. So, for the code you set
> up, I would recode it as follows
>
> Private Sub SelectMatrix_Click(Index As Integer)
>   Dim Display As Integer
>   Select Case Index
>     Case 0
>       Picture4.Cls
>       Display = 0
>     Case 1
>       Picture4.Cls
>       Display = 1
>     Case 2
>       Picture4.Cls
>       Display = 2
>   End Select
>   'test code below to see what was selected
>   Picture4.Print Display
> End Sub
>
> HOWEVER, you don't really need that Select Case structure at all (at
> least from the code you posted). Try this instead...
>
> Private Sub SelectMatrix_Click(Index As Integer)
>   Picture4.Cls
>   Picture4.Print Index
> End Sub
>
> where I used the fact that Display was being set to the same value as
> the control's Index value.
>
> Rick - MVP
>




--- UseNet To RIME Gateway {at} 2/11/05 6:45:35 PM ---
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)
SEEN-BY: 633/267 270 5030/786
@PATH: 278/230 10/345 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.