If...Then...Else or Select Case?

JIMBO89
09-02-2004, 08:12 AM
I have a form with many command buttons. Depending on which comdbutton is clicked, a [pre-saved] document will open. It may be a document, spreadsheet, .pdf file, database or whatever. I'm pretty sure I can do it as an If...Then...Else statement but would a Select Case statement be more efficient?. I had it running with each button having it's own click event but it won't compile - 'out of memory error'. If the Select Case Statement is the better option, can someone give me an example to kick it off please? I am using VB5 and VB6. Also, how the hell do I get an .avi or .swf file to run as a click event?

Thanks heaps
Jim

Iceplug
09-02-2004, 08:21 AM
That depends on what statement you are checking with the If Then Else statements.

If you are checking a specific variable for different values, then you should use a Select Case statement to chkec this variable against different cases.
What do your If Then Else statements look like?

BombDrop
09-02-2004, 08:23 AM
Case is much easier to read than having multilpe If's
ALso i would suggest using a control array this cuts down on memory also.

the following example shows how to use a case statemt with a Command control array.


Option Explicit

Private Sub CmdCase_Click(Index As Integer)
Select Case Index
Case Is = 0
MsgBox "button with index" & Space$(1) & Index & Space(1) & "was pressed"

Case Is = 1
MsgBox "button with index" & Space$(1) & Index & Space(1) & "was pressed"

Case Is = 2
MsgBox "button with index" & Space$(1) & Index & Space(1) & "was pressed"

Case Is = 3
MsgBox "button with index" & Space$(1) & Index & Space(1) & "was pressed"

Case Else
MsgBox "not index 0-3"
End Select
End Sub


Hope this helps

Stuey
09-02-2004, 08:23 AM
I'm not sure but possibly a control array might help 'cause you'd just have one event...you'd use the controls index property as your Select Case in you Click event. I'm not sure how much memory this will save though.

Wouldn't it be easier to have all the different formats in a combo box and just one "open" button nect to it?

SB

jjStinger72
09-02-2004, 08:28 AM
two quick points on that code. Why use "Is =" ?? Case 1 would do the same thing.

Also, you press for Control array (i highly highly agree), and i understand you were trying to demonstrate a select case, but there's no need to....

Option Explicit

Private Sub CmdCase_Click(Index As Integer)

MsgBox "button with index " & cstr(Index) & " was pressed"

end sub


...would have accomplished the same thing. As IcePlug mentioned, lets see what the IfElse statement would look like....

JIMBO89
09-02-2004, 08:31 AM
Thanks Guys, I'm sure the answer I'm looking for is there somewhere. I'll try each one and post back here - probably a couple of days - when I test it.

Thanks again
Jim

JIMBO89
09-09-2004, 07:57 AM
As you all predicted, the Case statement did the job just great. That wasn't the memory problem anyway, because I still get it. The problem is having 8 pictures change every 50 ms in the opening for. I have made it into a flash movie BUT how do I get the movie to run on a click event. I have each picture to it's own form and have the forms change every 50ms but it is very 'flickery', so the flash movie should fix that bit. Any ideas what (the probably simple thing) I have to do ie Add-Ins etc.


Thanks Again

Jim

DeX
09-09-2004, 10:58 AM
Well if you're trying to make an animation by using individual picture boxes you certainly shouldn't put each picture box on a seperate form. How big is each picture? There are better ways of doing animation like this.

JIMBO89
09-09-2004, 10:25 PM
The 'animation' consists of 8 pictures each being 17cm x 12cm. Each picture is 916KB. I have put them together using Flash and saved them as .avi (2300KB), .fla (7400KB) and .swf (2400KB). I have got the avi and fla files on to the form but can't get them to run when the commandBUtton is clicked. I know having the pictures on 8 seperate forms is not the way to do it but the program DID compile that way. Having the pictures change every 50ms on the same form caused the original 'out of memory' error.

Thanks Again

Jim

doofusboy
09-10-2004, 04:32 AM
Jim, for future reference, I thought I'd pass along a rule of thumb that was taught to me many moons ago in hopes it'll benefit you as well.

When choosing among 3 or fewer options, If-Then-Else is generally the way to go. When choosing among 4 or more, Select statements tend to be preferrable.

I've used this rule of thumb over the years and it has served me well.

DeX
09-10-2004, 04:43 AM
If you just want to play a flash animation then use the ShockwaveFlash control.

JIMBO89
09-10-2004, 06:33 AM
hey guys thanks for your replies. doofusboy, i remember the same thing being told to me but i just couldn't remember the start point for the case statement - that part is fine now. dex, i have the shockwave flash control but just can't get it to happen. If you would be so kind, can you show me how - when i click commandbutton, the flash movie should start and when it finishes (1 run through only) another picture object appears. eg..

Private Sub comd1_click()
picture1.visible=false
animation1=play
animation=stop
picture2.visible=true

or something like that...know what I mean?

"picture1" is a welcome screen waiting for user intervention.
"animation1" is the movie
"picture2" is another intro screen waiting for user intervention before proceeding to the next form blah blah blah


Thanks

Jim

Livid
09-10-2004, 08:15 AM
You could also store your animation as an avi file so it doesnt require people to download the flash plugin to see your animation. Avi files are easily played within vb.

JIMBO89
09-11-2004, 07:06 AM
That would be better, buty the real problem is I don't know how. I've checked the help files without success. I have the .avi file ready to go but how do I get VB to activate/run it? I have no idea!!

Thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum