Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > If...Then...Else or Select Case?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2004, 08:12 AM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default If...Then...Else or Select Case?


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
__________________
DUTY FIRST
Reply With Quote
  #2  
Old 09-02-2004, 08:21 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

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?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 09-02-2004, 08:23 AM
BombDrop BombDrop is offline
Newcomer
 
Join Date: Sep 2004
Location: St.Helens, England, UK
Posts: 20
Wink

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.

Code:
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
__________________
BombDrop's VB.Classic Help File
Reply With Quote
  #4  
Old 09-02-2004, 08:23 AM
Stuey Stuey is offline
Regular
 
Join Date: Jan 2004
Posts: 67
Default

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
Reply With Quote
  #5  
Old 09-02-2004, 08:28 AM
jjStinger72's Avatar
jjStinger72 jjStinger72 is offline
Senior Contributor

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
Default

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....

Code:
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....
__________________
Jay

[vb][/vb] Tags | Standards & Practices Tutorial | File I/O Tutorial | List of all these Tags
Reply With Quote
  #6  
Old 09-02-2004, 08:31 AM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default Many Thanks

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
__________________
DUTY FIRST
Reply With Quote
  #7  
Old 09-09-2004, 07:57 AM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default

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
__________________
DUTY FIRST
Reply With Quote
  #8  
Old 09-09-2004, 10:58 AM
DeX's Avatar
DeX DeX is offline
Senior Contributor

* Expert *
 
Join Date: Aug 2003
Location: Berkhamsted, England
Posts: 940
Default

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.
__________________
Check out my free Download Meter prog written in VB6.
Having trouble using the registry in VB? Try my free registry control.
Reply With Quote
  #9  
Old 09-09-2004, 10:25 PM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default

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
__________________
DUTY FIRST
Reply With Quote
  #10  
Old 09-10-2004, 04:32 AM
doofusboy doofusboy is offline
Centurion
 
Join Date: Sep 2003
Posts: 183
Default

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.
Reply With Quote
  #11  
Old 09-10-2004, 04:43 AM
DeX's Avatar
DeX DeX is offline
Senior Contributor

* Expert *
 
Join Date: Aug 2003
Location: Berkhamsted, England
Posts: 940
Default

If you just want to play a flash animation then use the ShockwaveFlash control.
__________________
Check out my free Download Meter prog written in VB6.
Having trouble using the registry in VB? Try my free registry control.
Reply With Quote
  #12  
Old 09-10-2004, 06:33 AM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default

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
__________________
DUTY FIRST
Reply With Quote
  #13  
Old 09-10-2004, 08:15 AM
Livid Livid is offline
Centurion
 
Join Date: Feb 2004
Posts: 126
Default

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.
Reply With Quote
  #14  
Old 09-11-2004, 07:06 AM
JIMBO89 JIMBO89 is offline
Newcomer
 
Join Date: Aug 2004
Posts: 8
Default

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
__________________
DUTY FIRST
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->