Solved

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

Posted on 2004-04-30
12
149 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now