Solved

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

Posted on 2004-04-30
12
151 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

837 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