Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use "value description" rather than value to evaluate.

Posted on 2004-04-30
12
Medium Priority
?
156 Views
Last Modified: 2010-05-02
hi experts,
I didn't know the right terminology, sorry.
I saw this somewhere but now I can't remember.
To make the code more readable, what I'm want to do is:

Instead of:
   If a = 1 then ...
   If a = 2 then ...
   If a = 3 then ...

I'd like to say:
   If a_is_1 then ...
   If a_is_2 then ...
   If a_is_3 then ...

where (This syntax is what I'm looking for):
   dim   a    as  integer
        a_is_1 value 1
        a_is_2 value 2
        a_is_3 value 3

Thank you,
Phil
0
Comment
Question by:spoowiz
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 6

Expert Comment

by:prasitlee
ID: 10965105
Hi spoowiz,
   I don't understand. Please explain more details.
                                                         Meng
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10965177
I understand what you are saying, but what you need to understand is that visual basic doesnt know what to evaluate agaisnt what when you do it like that.

You could do...

select case A
 case 1
  msgbox "A is 1"
 case 2
  msgbox "A is 2"
 case 3
  msgbox "A is 3"
end select

0
 

Author Comment

by:spoowiz
ID: 10965179
sorry. that's the best explanation i can give.
I know that if you know the syntax, you'll understand.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:spoowiz
ID: 10965185
Brian,
That's still not it. Maybe I'm just mistaken but I could swear I saw it before. (For those old fogies out there, it's an old COBOL 88 syntax which makes code very readable).
Phil
0
 

Author Comment

by:spoowiz
ID: 10965197
When reading code, it's much easier to read if it said,
   If ACCOUNT_IS_DELINQUENT THEN ....
rather than
   If AccountStatus = 7 then ... ' or whatever value

In Cobol, if I remember correctly it would be defined:
01   AccountStatus       Pic  9(2).
88   ACCOUNT_IS_DELINQUENT   VALUE 7.


0
 
LVL 6

Expert Comment

by:prasitlee
ID: 10965201
Hi spoowiz,
   May I ask you something ?

   If a_is_1 then ...
   If a_is_2 then ...
   If a_is_3 then ...
   What is a_is_1 stored ? At the line below, you told that it stored "1". If so, what if compare with so it know what it should do next. Normally if would compare and return to TRUE or FALSE. So it would know what to do next.
                                                   Meng
0
 
LVL 6

Expert Comment

by:prasitlee
ID: 10965213
Sorry to ask you again
   If ACCOUNT_IS_DELINQUENT THEN ....
   Is ACCOUNT_IS_DELINQUENT a variable or constant ?
   how could if statement know that it would be true if it is equal to 7 or any value ?
                                                                    Meng
0
 

Author Comment

by:spoowiz
ID: 10965223
Hi Meng,
That's the question. I know I've seen it somewhere, rarely used, but a very good programming technique as in the Account_is_delinquent example.
Phil
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 150 total points
ID: 10965599
What you want to do is something like this:

a_is_1 when a = 1
a_is_2 when a = 2
a_is_3 when a = 3

a = 2

if a_is_2 then
 ok....
end if

this cannot be done in VB.

-Brian
0
 
LVL 1

Assisted Solution

by:sadcock
sadcock earned 150 total points
ID: 10965743
Spoowiz-

The closest you can come to the good old COBOL 88's (yes I coded them too) is a VB Boolean variable.  You would have to set the three booleans you want to interpret with if/case logic (which may defeat your purpose).  See below

Dim a_is_1 as boolean
Dim  a_is_2 as boolean
Dim a_is_3 as boolean
Select case a
   case is 1
      a_is_1 = True
   case is 2
      a_is_2 = True
   case is 3
      a_is_3 = True
end select

if a_is_1 then
   ...
end if

0
 

Author Comment

by:spoowiz
ID: 10965956
wow. another Cobol coder!
sadcock :-),
that's not it. i'm going to keep this open a bit and look for it myself so i can post it when i find it. actually, i think it was used in a module and i couldn't understand how it was done exactly. when i find it, i'll post and ask some questions.
phil
0
 

Author Comment

by:spoowiz
ID: 11095305
thanks for trying. i couldn't find it so i'm closing it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

916 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