Solved

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

Posted on 2004-04-30
12
150 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

823 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