Solved

information lookup

Posted on 2001-08-16
9
142 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 52

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

751 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