Solved

variable field name referencing

Posted on 1998-09-17
8
144 Views
Last Modified: 2010-04-30
i want to hold a field name in a variable, then write one
piece of code where i can reference the .text value of
the field hald in that variable, same as using the NAME_IN
function in SQL*FORMS.

is there a way to do this or is vb worse than i thought!
0
Comment
Question by:newlook
8 Comments
 

Expert Comment

by:Saradhi
ID: 1435341
Well, its easy. You can use the type statement in VB which is much like a structure in C.

You can declare a new type as :

Type Employee
      No As Integer
      Text As String
      Address As String
       Phone As Long
End Type

When declared you can use it in your program as:

Sub Main()
      Dim MyRecord As Employee       'Declare variable as Employee type      
      MyRecord.No = 12003      
                  MyRecord.Text="Sara"
                  MyRecord.Address="B-dj,Wels Street,Badel"
End Sub


You can reference this variable wherever you like in your program with all its fields (ie..MyRecord.Text).


0
 

Author Comment

by:newlook
ID: 1435342
sorry, thats not what i meant.
I need to have (for example) 2 text boxes Text1, Text2

set variable = Text1
msgbox variable.text ' to show Text1.Text

set variable = Text2
msgbox variable.text ' to show Text2.Text
0
 
LVL 18

Expert Comment

by:deighton
ID: 1435343
This is what you want

Private Sub Command1_Click()

    Dim x As TextBox
   
    Set x = Text1
   
    MsgBox x.Text
   
    Set x = text2
   
    MsgBox x.Text
   
   
End Sub
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1435344
This is what you want   I hope!

      Private Sub Command1_Click()

          Dim x As TextBox
           
          Set x = Text1
           
          MsgBox x.Text
           
          Set x = text2
           
          MsgBox x.Text
           
           
      End Sub
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:ChasDevlin
ID: 1435345
Hello Mr Deighton!
0
 

Author Comment

by:newlook
ID: 1435346
thanks for your help. sadly, although it works with text boxes
(i used that as an easier example) i need to get it working on
listboxes!! (it doesnt like that)

thanks anyway
0
 
LVL 18

Expert Comment

by:deighton
ID: 1435347
WHAT DOESN'T WORK????

Please ask here if you need any specific info.

[Hallo Chas!]

Here is a list box example, i seem to be able to access the properties ok.


Private Sub Command1_Click()

    Dim X As ListBox

    Set X = List1
   
    MsgBox X.Name
    MsgBox X.List(0)
    MsgBox X.List(1)
   

End Sub
0
 

Author Comment

by:newlook
ID: 1435348
ooh i tried that and couldn't get it to work! will cut and
paste your code and let you know
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now