473,408 Members | 1,767 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,408 software developers and data experts.

Variable Pointers

Hi,
Is there a way to use something similar to C pointers in VBA? My reasoning
is as follows:
Imagine I have 10 items on a report, all called txtItem1,
txtItem2...txtItem10. I want to perform some operation to all of them in
VBA, and I'd like to use a for loop, and perform an operation on the
variable "txtItem" & i. In C perhaps you could operate on a pointer, and
direct the pointer to "txtItem" & i. Is there a way to do this in VBA?
Thanks.
Nov 13 '05 #1
4 4495
Yes, this can be done in VBA, but you have to use one of the alternate
syntax methods of referring to the control.

For i = 1 To 10
Me.Controls("txtItem" & i) = "whatever"
Next i

--
Wayne Morgan
MS Access MVP
"Raphi" <le**@DELETEME.optFAKEonline.net.REMOVE> wrote in message
news:Ff*****************@fe12.lga...
Hi,
Is there a way to use something similar to C pointers in VBA? My reasoning
is as follows:
Imagine I have 10 items on a report, all called txtItem1,
txtItem2...txtItem10. I want to perform some operation to all of them in
VBA, and I'd like to use a for loop, and perform an operation on the
variable "txtItem" & i. In C perhaps you could operate on a pointer, and
direct the pointer to "txtItem" & i. Is there a way to do this in VBA?
Thanks.

Nov 13 '05 #2
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:DA***************@newssvr25.news.prodigy.net:
Yes, this can be done in VBA, but you have to use one of the
alternate syntax methods of referring to the control.

For i = 1 To 10
Me.Controls("txtItem" & i) = "whatever"
Next i


In a report, this will be fine, but in a form, you'd be better off
creating a custom collection and populating that with the relevant
controls. You then don't need to have special naming conventions --
only your code that populates the custom collection needs to know
which controls to put in the collection (I often use the .Tag
property for keeping track of which controls belong together).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3
Raphi wrote:
Hi,
Is there a way to use something similar to C pointers in VBA? My reasoning
is as follows:
Imagine I have 10 items on a report, all called txtItem1,
txtItem2...txtItem10. I want to perform some operation to all of them in
VBA, and I'd like to use a for loop, and perform an operation on the
variable "txtItem" & i. In C perhaps you could operate on a pointer, and
direct the pointer to "txtItem" & i. Is there a way to do this in VBA?
Thanks.

The nearist thing I can think of is Type. Here's an example from Access
Help.

Type EmployeeRecord ' Create user-defined type.
ID As Integer ' Define elements of data type.
Name As String * 20
Address As String * 30
Phone As Long
HireDate As Date
End Type
Sub CreateRecord()
Dim MyRecord As EmployeeRecord ' Declare variable.

' Assignment to EmployeeRecord variable must occur in a procedure.
MyRecord.ID = 12003 ' Assign a value to an element.
End Sub

You can make EmployeeRecord an array of types.

Dim typEmp() As EmployeeRecord
Dim intEmpCnt As Integer
For intEmpCnt = 0 To 3
ReDim Preserve typEmps(intEmpCnt)
typEmp(intJobCnt).ID = intEmpCnt
Next
Nov 13 '05 #4
What is the operation to accomplish? I tend to think too procedurally,
this looks to me as if you could be thinking too procedurally here too.

Raphi wrote:
Hi,
Is there a way to use something similar to C pointers in VBA? My reasoning
is as follows:
Imagine I have 10 items on a report, all called txtItem1,
txtItem2...txtItem10. I want to perform some operation to all of them in
VBA, and I'd like to use a for loop, and perform an operation on the
variable "txtItem" & i. In C perhaps you could operate on a pointer, and
direct the pointer to "txtItem" & i. Is there a way to do this in VBA?
Thanks.


--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #5

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

Similar topics

5
by: g18c | last post by:
I am trying to have a pointer to a member variable, however i will be deriving a number of classes from a base class. Whilst the code below works, i am wondering if there is a better way of doing...
53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
11
by: Satish Kumar | last post by:
Can any one give me indetail about, what are pointers? How are pointers useful in C prgramming? How do they work? i had gone through one book, i am a bit confused. Regards, Satish...
3
by: dmbacon | last post by:
I am having difficulty setting and retrieving the string value of a variable on one form from another form. Can someone please point me in the right direction. Thanks dmb
4
by: jagguy | last post by:
can you declare variables as pointers without using new or make them point at another variable. this works I thought it shouldn't char *p ; p="xat"; cout << p <<endl;
13
by: arnuld | last post by:
at the very beginning of the chapter, i see some statements i am unable to understand. i know the "Pointer" takes the address of a variable, useful if, in case, we want to manipulate that variable...
4
by: freefighter | last post by:
Is there such a way to ensure that at a time just one variable (pointer to ref type) is used to maintain the object. This is needed for a multi-threded application where shared data should be used...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.