By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

Parsing textbox names as a variable in a sub

P: 6
Hi

I got a grid of textboxes which all need to do the same function on their doubleclick event, however the code they call needs to copy the data in the textbox to another textbox.

I don't really want to repeat the code all 32 times so am looking to create a standard sub function which can be called. That's easy enough, i am just unaware of how to make this function parse a variable depending on which textbox was clicked.

Here is what the code looks like as a private sub (sorry if it is bad coding, I haven't done this in YEARS)

Expand|Select|Wrap|Line Numbers
  1. '*** check if the txtbox is null
  2.     If IsNull(txtGrid1.Value) Then
  3.     '*** Depending on which temp field has data, copy it to the txtbox
  4.         If IsNull(txtStudent1temp) Then
  5.             txtGrid1 = txtStudent2temp
  6.             txtStudent2temp = Null
  7.         Else
  8.             txtGrid1 = txtStudent1temp
  9.             txtStudent1temp.Value = Null
  10.         End If
  11.         txtGrid1.BackColor = 16777215
  12.     Else
  13.     '*** if the txtbox is not null, copy it's data to the temp field
  14.         If IsNull(txtStudent1temp) Then
  15.             txtStudent1temp = txtGrid1
  16.             txtGrid1 = Null
  17.         Else
  18.             txtStudent2temp = Null
  19.             txtStudent2temp = txtGrid1
  20.             txtGrid1 = Null
  21.         End If
  22.         txtGrid1.BackColor = 13434828
  23.     End If

Now I want to move this code into a public sub function BUT make the txtGrid1 value change depending which txtbox in the grid is double clicked.
Aug 25 '08 #1
Share this Question
Share on Google+
2 Replies


Delerna
Expert 100+
P: 1,134
pass the textbox in the parameters for the function.

Expand|Select|Wrap|Line Numbers
  1. public sub SubroutinesName(byref txt as textbox)
  2.     'your code in your post goes here
  3.     'except you use txt instead of TextGrid1
  4. end sub
  5.  
now all you need is to put the function call into the doubleclick event for each control and pass the appropriate textgrid# control
Aug 25 '08 #2

P: 6
pass the textbox in the parameters for the function.

Expand|Select|Wrap|Line Numbers
  1. public sub SubroutinesName(byref txt as textbox)
  2.     'your code in your post goes here
  3.     'except you use txt instead of TextGrid1
  4. end sub
  5.  
now all you need is to put the function call into the doubleclick event for each control and pass the appropriate textgrid# control

Thanks, that worked a treat!
Aug 25 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.