473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Calling functions with hardcoded fieldnames?

I have a module which has a function that returns values from a table.

e.g.
GetFromUsersTable(userID,"UserName")
GetFromUsersTable(userID,"UserDept")
etc.

depending on the userID passed, it will return the field requested.

Question is where/how do I define constants that I can use in place of
"UserName", "UserDept", etc., in case these field names change?

What is the correct syntax and where could I place them (in the main
module, in their own module, a class)?
thanks.

Nov 21 '05 #1
3 906
I would use an "Enum" for the fields like: (not sure of exact syntax)

Public Enum myFields
UserName
UserDept
End Enum

Dim FieldNeeded as myFields

GetFromUsersTable(UserId as string, FieldNeeded as myFields)
Select Case FieldNeeded
case UserName
'return the users name
case UserDept
'return user Dept
End Select
End Sub

"Eych" wrote:
I have a module which has a function that returns values from a table.

e.g.
GetFromUsersTable(userID,"UserName")
GetFromUsersTable(userID,"UserDept")
etc.

depending on the userID passed, it will return the field requested.

Question is where/how do I define constants that I can use in place of
"UserName", "UserDept", etc., in case these field names change?

What is the correct syntax and where could I place them (in the main
module, in their own module, a class)?
thanks.

Nov 21 '05 #2
No one on this NG wrote your 'GetFromUsersTable' class, so it's pretty tough
for us to help you.

If you post some of the code from that class, we may be able to help...

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Eych" <ey******@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I have a module which has a function that returns values from a table.

e.g.
GetFromUsersTable(userID,"UserName")
GetFromUsersTable(userID,"UserDept")
etc.

depending on the userID passed, it will return the field requested.

Question is where/how do I define constants that I can use in place of
"UserName", "UserDept", etc., in case these field names change?

What is the correct syntax and where could I place them (in the main
module, in their own module, a class)?
thanks.

Nov 21 '05 #3
Below is some code from the function, it searches for the userID and
returns the field requested.

I was asking because I just didn't want to hardcode the requested
field.

I could do the Enum like:

Public Enum dbFields as String
UserName = "UserName"
UserDept = "UserDept"
End Enum

and place this in the module where I have my Public Sub main()

I guess I'm wondering if there is a more conventional way, such as
creating project-wide constants so that
I don't have to declare a dbFields each time I want to use a field.
Then again, I could create an Enum for each table, where each Enum
contains the fields for that table...hmmm...

Function GetFromUsersTable(ByVal user_ID As String, ByVal fieldName As
String) As String

Dim globalDBDataConnect As New DataConnect 'class I created in
easing creation of datasets
Dim returnValue As String = ""

Try
globalDBDataConnect.Connection = New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source="C:\maindb.mdb")
globalDBDataConnect.Adapter = New
System.Data.OleDb.OleDbDataAdapter("select * from UsersTable where
UserID = '" & user_ID & "'", globalDBDataConnect.Connection)
globalDBDataConnect.Dataset = New DataSet

globalDBDataConnect.Adapter.Fill(globalDBDataConne ct.Dataset,
"UsersTable")

If globalDBDataConnect.Dataset.Tables(0).Rows.Count > 0
Then
'status found
returnValue =
(globalDBDataConnect.Dataset.Tables(0).Rows(0)(fie ldName))
End If
Return returnValue

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
7
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
8
by: York | last post by:
Hi, R language has very high-level IO functions, its read.table can read a total .csv file and recogonize the types of each column. write.table can do the reverse. R's MySQL interface has...
6
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
1
by: Jay Balapa | last post by:
Hello, Iam creating a query page, in which a Drop Down List will have collection of fieldnames. Is there a elegant way of doing it? Currently Iam opening up a datareader and using...
3
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b...
2
by: leonard.guillaume | last post by:
Hi again guys, I configured my MFC project so that it can call few webservices I made. The web services are in VB.Net and are using few namespace such as WebClientProtocol which I need in MFC....
46
by: Usenet User | last post by:
I need to be able to call the same API function from VB, which will reside in different DLLs. While all of the functions have the same signature and name, DLL file names are not known at compile...
0
by: BornTOCode | last post by:
Hello, I am attempting to call a (Delphi) win32 DLL from a Delphi.Net webservice. I am using a slightly modified version of the hello world webservice that comes with Delphi 2006. The DLL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.