Solved

information lookup

Posted on 2001-08-16
9
140 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
9 Comments
 
LVL 50

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 50 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

839 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