Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

information lookup

Posted on 2001-08-16
9
Medium Priority
?
145 Views
Last Modified: 2010-05-02
I am creating a VB app with a procedure that looks up and returns data based on a value that is passed to it (like querying a record with the record ID).  However, my app has no database functions and the data never changes.  Is there a better way than using an if...Then or a Case statement?

For example:

Private Sub GetData(DataID As Integer, ByRef Data1 As String, ByRef Data2 As Boolean, Data3 As Integer)
    Select Case DataID
        Case 1
            Data1 = "Hello World"
            Data2 = True
            Data3 = 32767
        Case 2
            ...
    End Select
End Sub

Thanks
0
Comment
Question by:thatsthefactsjac
[X]
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
9 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6395297
Hi tahtsthefactsjac,

Why Not declared a user data type?:

Example:

Private Type myArray
    DataID As Integer
    Data1 As String
    Data2 As Boolean
    Data3 As Integer
End Type

Dim myData() As myArray


Private Sub Form_Load()
    ReDim myData(1)
    myData(0).DataID = 1
    myData(0).Data1 = "Hello World"
    myData(0).Data2 = True
    myData(0).Data3 = 123
    myData(0).DataID = 2
    myData(0).Data1 = "EE"
    myData(0).Data2 = False
    myData(0).Data3 = 4567
End Sub
0
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6395300
If you want cleaner code store the data in an Access Database and run your query of that. That is a much better way.

0
 

Author Comment

by:thatsthefactsjac
ID: 6395348
Maxim10553,
I know that an Access database would do the trick nicely, but I would prefer to keep my application as "slim" as possible.  However, I may choose that route...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:thatsthefactsjac
ID: 6395357
Maxim10553,
I know that an Access database would do the trick nicely, but I would prefer to keep my application as "slim" as possible.  However, I may choose that route...
0
 

Author Comment

by:thatsthefactsjac
ID: 6395398
Maxim10553,
I know that an Access database would do the trick nicely, but I would prefer to keep my application as "slim" as possible.  However, I may choose that route...
0
 
LVL 8

Accepted Solution

by:
DennisBorg earned 150 total points
ID: 6395417
TheFacts:

The way you are going about it is just fine.

The only suggestion I might have is that if you have a large number of distinct DataID's, you may want to add that data into a resource file (which is compiled into your executable). You can then use the LoadResString function to load in the data:

Private Sub GetData(DataID As Integer, ByRef Data1 As String, ByRef Data2 As Boolean, Data3 As Integer)
   Data1 = LoadResString(100 + DataID)
   Data2 = (LoadResString(101 + DataID) = "Y")
   Data3 = CInt(LoadResString(102 + DataID))
End Sub


In this example, DataID would be 1, 4, 7, 10, etc. for each consecutive set of data.


-Dennis Borg
0
 

Author Comment

by:thatsthefactsjac
ID: 6400968
A resource file will work well, thanks!
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6401205
You're welcome! Glad to have helped.
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6411640
By the way, Facts. Since you've stated taht the solution will work well, why did you penalize me by giving my a 'B' instead of an 'A'?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…

715 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