Is there a better way ?

Posted on 1999-01-14
Last Modified: 2013-12-25
Is there a better way to do this ?

IF iprix = 1 Then
      PrixMax = 2000
      If iprix = 2001 THEN
            PrixMax = 5000
            If iprix = 5001 THEN
                  PrixMax = 10000
                  IF iprix = 10001 THEN
                        PrixMax = 14000
                        IF iprix = 14001 THEN
                              PrixMax = 20000
                        END IF
                  END IF
            END IF
      END IF
End IF

besides assigning a variable to each of the values ?
Question by:AnitaP
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 1830610
Hi, I really don't know basic that much, but in C or Pascal you could do something like:

case iprix of      //PASCAL
  1: PrixMax := 2000;
  2001: PrixMax := 5000;
  5001: PrixMax := 10000;
10001: PrixMax := 14000;
14001: PrixMax := 20000;

switch (iprix) {      /*C / C++*/
  case 1: PrixMax = 2000;
  case 2001: PrixMax = 5000;
  case 5001: PrixMax = 10000;
  case 10001: PrixMax = 14000;
  case 14001: PrixMax = 20000;

Hope it helps!!


Jorge del Conde

Author Comment

ID: 1830611
How about Visual Basic 4 ?

I am using this code in an ASP script which is mostly formed of Visual Basic code.

Accepted Solution

mrgentry earned 10 total points
ID: 1830612
I believe this is how it's done in VB.

PrixMax = 0
Switch Case iprix
    Case 2001
        PrixMax = 5000
    Case 5001
        PrixMax = 10000
    Case 10001
        PrixMax = 14000
    Case 14001
        PrixMax = 20000
End Select


Author Comment

ID: 1830613
Thank you.

Author Comment

ID: 1830614
by the way, it is SELECT case and not SWITCH

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question