|
-
Sep 28th, 2000, 07:12 PM
#1
Thread Starter
Addicted Member
What exactly is wrong with this code?
Private Sub VScroll1_Change()
For Each TextBox In frmAdd
Let TextBox.Top = TextBox.Top + -1 * (VScroll1.Value + 10)
Next
End Sub
its saying the top property cannot be read at runtime
-
Sep 28th, 2000, 07:18 PM
#2
The code works fine for me. Do you have textboxes on your form for the scrollbar to move them?
-
Sep 28th, 2000, 07:20 PM
#3
Thread Starter
Addicted Member
yes i do
do the text boxes have to be named textbox in this code? Sorry ive never tried for each loops before. Thanks matthew, wow a guru helping me
-
Sep 28th, 2000, 07:29 PM
#4
Hyperactive Member
Well I didn't get it to work as is:
But,
Code:
Private Sub VScroll1_Change()
Dim aControl As Control
For Each aControl In frmAdd.Controls
If TypeName(aControl) = "TextBox" Then
Let aControl.Top = aControl.Top + -1 * (VScroll1.Value + 10)
End If
Next
End Sub
works.
If there is another way without the test, then let me know Matthew (or anyone).
Regards
-
Sep 28th, 2000, 07:31 PM
#5
_______
<?>
Code:
'I didn't get it to work either
'but this does
Option Explicit
Public Sub SetTop()
'
'mycontrol = control and increment is increment for forms
'some situtations use more than one form.
'
Dim ctlMyControl As Control
Dim intIncrement As Integer
'
For intIncrement = 0 To Forms.Count - 1
For Each ctlMyControl In Forms(intIncrement).Controls
'
If TypeOf ctlMyControl Is textbox Then
'
ctlMyControl.Top = ctlMyControl.Top + (-1 * (VScroll1.Value + 10))
'
End If
'
Next ctlMyControl
'
Next intIncrement
'
End Sub
Private Sub VScroll1_Change()
Call SetTop
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 28th, 2000, 07:32 PM
#6
Thread Starter
Addicted Member
thanks but why wont my first code work?
i have 2 textboxes and the scrollbar
-
Sep 28th, 2000, 08:19 PM
#7
Hyperactive Member
Because you are fibbing :)
You have more than 2 text boxes and a vscroll bar on your form. I guarantee it.
Your code is attempting to move EVERY control on the form. I have assumed you declared your variable "TextBox" as a Variant, or that you do not have Option Explicit at the head of your module.
In either case, "TextBox" in your code is merely a variable name like "a" or "b".
In my code and HeSaidJoe's we explicitly check what sort of control we have and then move it.
I hope that explains it to you?
It would have helped you if you had Option Explicit in your module. This would help because you would have recieved an error in your code which would have hinted to you that TextBox needs to be decalred. Then you would have thought about what type of data it will be...
Anyhow enough preaching 
Cheers
-
Sep 29th, 2000, 10:36 AM
#8
Thread Starter
Addicted Member
Thanks ;)
Thanks I understand what I was missing now.
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
|