|
-
Aug 15th, 2000, 12:55 PM
#1
Thread Starter
Lively Member
Trying to pass a control array of text boxes to a sub where I can do work on it.
The form has a text1 textbox control array on it
Public Sub form_load()
Dim i As Integer
For i = 1 To 5
Load frmMain.Text1(i)
frmMain.Text1(i).Top = frmMain.Text1(i - 1).Top + 50
frmMain.Text1(i).Visible = True
Next i
InsertValues(Text1) '????
end sub
Public Sub InsertValues(theControl as ??)
dim i as integer
for i = 0 to 5
theControl(i).text = 100
next i
end sub
I keep getting arguement not optional no matter what I try. Help????
-
Aug 15th, 2000, 01:16 PM
#2
_______
<?>
Code:
'you can't contain the name of a control
'in a variable and access it..just doesn't work
'you can accomplich the feat using a public variable
'and a function...but it's not generic...
Public newValue As String
Public Sub form_load()
Dim i As Integer
For i = 1 To 5
Load frmMain.Text1(i)
frmMain.Text1(i).Top = frmMain.Text1(i - 1).Top + 800
frmMain.Text1(i).Visible = True
Next i
newValue = 200
InsertValue
End Sub
Public Function InsertValue()
Dim i As Integer
For i = 0 To Text1.Count - 1
Text1(i).Text = newValue
Next i
End Function
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 15th, 2000, 01:20 PM
#3
There's probably a better/simpler way, but this works
Code:
Option Explicit
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 5
Load frmMain.Text1(i)
frmMain.Text1(i).Top = frmMain.Text1(i - 1).Top + 50
frmMain.Text1(i).Visible = True
Next i
InsertValues (Text1(0).Name)
End Sub
Public Sub InsertValues(theControl As String)
Dim ctl As Control
For Each ctl In Controls
If ctl.Name = theControl Then
ctl.Text = 100
End If
Next
End Sub
-
Aug 15th, 2000, 01:26 PM
#4
Thread Starter
Lively Member
nope... that doesn't help at all. I want to pass a control array to a sub. I can pass a control to a sub, why can't I pass a control array?
-
Aug 15th, 2000, 01:31 PM
#5
_______
<?>
the control array is not accessed by name. if you type text1.name you can't get it...it is accessed by index
text1(0)
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 15th, 2000, 01:47 PM
#6
nope... that doesn't help at all. I want to pass a control array to a sub. I can pass a control to a sub, why can't I pass a control array?
Because in VB as in life, you can't always do what you want to do.
-
Aug 15th, 2000, 02:01 PM
#7
Frenzied Member
And, as in life, there are multiple ways to do things. Declare the control array "global" or "public"
-
Aug 15th, 2000, 04:18 PM
#8
transcendental analytic
I would have to disagree with Martin here, you can pass the control array as an object. But you would have to use the item property, since vb can't determine it's default.
Code:
Public Sub InsertValues(theControl As Object)
Dim ctl As Control
For Each ctl In thecontrol
ctl.Text = 100
Next
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 15th, 2000, 04:33 PM
#9
Frenzied Member
Originally posted by kedaman
I would have to disagree with Martin here, you can pass the control array as an object. But you would have to use the item property, since vb can't determine it's default.
Code:
Public Sub InsertValues(theControl As Object)
Dim ctl As Control
For Each ctl In thecontrol
ctl.Text = 100
Next
End Sub
Heh. Coming to theaters soon:
"Clash of the Guru's"
-
Aug 15th, 2000, 05:32 PM
#10
You can expand the Procedure to work for either a single Control or a Control Array, also you don't need to qualify the property you want to set, once the Control is enumerated in the For .. Each statement VB knows what the Default property is, i.e.
Code:
Sub SetControlValue(ByRef oControl As Object, ByVal NewValue As Variant)
Dim oSubControl As Control
If Not TypeOf oControl Is Control Then
For Each oSubControl In oControl
oSubControl = NewValue
Next
Else
oControl = NewValue
End If
End Sub
Example:
Code:
Private Sub Command1_Click()
SetControlValue txtArray, "Hello"
SetControlValue Text1, "Goodbye"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|