Solved

information lookup

Posted on 2001-08-16
9
141 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 51

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

713 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