Solved

information lookup

Posted on 2001-08-16
9
138 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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:thatsthefactsjac
Comment Utility
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
Comment Utility
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
Comment Utility
A resource file will work well, thanks!
0
 
LVL 8

Expert Comment

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

Expert Comment

by:DennisBorg
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now