Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / July 2005



Tip: Looking for answers? Try searching our database.

Get Index of Text Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BCS - 29 Jul 2005 22:10 GMT
I have a SSTab form with 3 tabs. On 2 of the tabs, I have a Text box called
"txtPassword", which is for the entry of an employee password. These 2 text
boxes are a control array with Index 0 and 1. When I go to the third tab to
update an employee account, I enter the applicable information including the
employee password (index 1) and then click the command button to update the
employee record. In my code for the command button, I reference the employee
password text box with the syntax "txtPassword(Index).text" but it returns
nothing. I step through the code and find that the value of Index is coming
up "0" and not "1". How can I correct this without hard coding the integer
"1". I would think there should be a way  to discern the Active Tab I'm on
and know the index of the controls on such tab.

Thank you,

Barry
Rick Rothstein [MVP - Visual Basic] - 29 Jul 2005 22:24 GMT
> I have a SSTab form with 3 tabs. On 2 of the tabs, I have a Text box called
> "txtPassword", which is for the entry of an employee password. These 2 text
[quoted text clipped - 7 lines]
> "1". I would think there should be a way  to discern the Active Tab I'm on
> and know the index of the controls on such tab.

I'm not exactly following the layout you have on your form from the
description above (not sure which tabs the TextBox'es are on, what the
Active Tab has to do with the 3rd tab that I think you are on, and so
on). However, I'd like to point out the that Index value for the control
array is not a "global" value, so you cannot reference it from anywhere
other than an event associated with the control array (that is why it is
shown as an argument in the events for the control array controls; it is
no different than if you create a Sub and declare your own arguments....
they are local to your Sub only). The reason you see Index having a
value of 0 is because you do not use an Option Explicit statement on
your forms to alert you when you reference a variable you have not
Dim'med. In this situation, VB creates a variable for you, on the fly,
and sets its Type as Variant. Variants, when referenced as an Integer or
Long (as you are doing when you try to use it as an array index) it has
a default value of 0. I'm not sure how to tell you to proceed because,
as I said in the beginning, I'm not entirely sure what you are doing or
how your control array controls are related to your SSTab control.

Rick
Ken Halter - 29 Jul 2005 22:34 GMT
>I have a SSTab form with 3 tabs. On 2 of the tabs, I have a Text box called
> "txtPassword", which is for the entry of an employee password. These 2
[quoted text clipped - 17 lines]
>
> Barry

First of all, click VB's Tools/Options menu and make sure the "Require
Variable Declaration" box is checked. That will make sure that you're not
creating a new variable out of "thin air" by accident. You can also clear
the "Auto Syntax Check" box. That will get rid of any syntax error related
message boxes and just leave the line red.

You can get the active tab with....

SomeInt = SSTab1.Tab 'returns the zero based tab number

Other than its container relationship, there is absolutely no relationship
between the controls on a tab and the tab control itself. That means that
the Tab control couldn't care less what the Index of a specific textbox is.
That means if you want to place text in a specific element of your control
array, the element's Index must be hard coded (or calculated in some
manner). Since hard coding "1" everywhere is nearly impossible to read
(especially a few weeks/months from now) I usually set up an Enum that
describes each element.

Something like......
'==========
Option Explicit

Private Enum BoxArray
  baPassword ' = 0
  baEmployeePW ' = 1
End Enum

Private Sub Command1_Click()
  txtPassword(baPassword).Text = "1234"
  txtPassword(baEmployeePW).Text = "5678"
End Sub
'==========

Signature

Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..

Ralph - 30 Jul 2005 04:43 GMT
> >I have a SSTab form with 3 tabs. On 2 of the tabs, I have a Text box called
> > "txtPassword", which is for the entry of an employee password. These 2
[quoted text clipped - 51 lines]
> End Sub
> '==========

Ken,

You forgot to add the conditional compile to preserve case... <g>

Private Enum BoxArray
    baPassword ' = 0
    baEmployeePW ' = 1
End Enum
#If 0 Then      'preserve case
   Dim baPassword, baEmployeePW
#End If
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.