|
-
Sep 22nd, 2005, 09:45 AM
#1
Thread Starter
Junior Member
[RESOLVED] Representing a Control With a Variable
Hello all. I have a series of flexgrids that I am trying to set up for text entry. I am using Osborne's VB From The Ground UP as my reference manual, and I am using the style described in this book to float a textbox over the flexgrid. However, this style is designed for one and only one flexgrid.
I have one textbox (txtFloater) and 12 flexgrids (flxFullAP, flxFullA, flxFullAM, etc.). I want to use a variable to point to the correct flexgrid, so that the code for all the flexgrid methods is the same except for the first line of flxXXX_EnterCell (where I would set the 'pointer' variable to represent the current flexgrid in use). My instinct is to do the following:
VB Code:
Private ThisFlx As Control 'This variable will represent whichever flxgrid we are using.
Private Sub PositionFloater()
txtFloater.Left = ThisFlx.CellLeft + ThisFlx.Left
txtFloater.Top = ThisFlx.CellTop + ThisFlx.Top
txtFloater.Width = ThisFlx.CellWidth
txtFloater.Height = ThisFlx.CellHeight
txtFloater.Visible = True
txtFloater.SetFocus
End Sub
Private Sub flxFullAP_EnterCell()
ThisFlx = flxFullAP 'This line would change for each _EnterCell() method
txtFloater.Text = ThisFlx.Text
PositionFloater
End Sub
Private Sub Form_Load()
ThisFlx = flxFullAP 'This sets the top-left flexgrid as the jumping-off point...
Set txtFloater.Font = ThisFlx.Font
Show
ThisFlx.Col = 0
ThisFlx.Row = 0
PositionFloater
End Sub
Private Sub txtFloater_Change()
ThisFlx.Text = txtFloater.Text
End Sub
Private Sub txtFloater_KeyDown(KeyCode As Integer, Shift As Integer)
'This allows implementation of Excel-standard cell navigation
Select Case KeyCode
Case Is = vbKeyUp: ThisFlx.Row = ThisFlx.Row - 1 Mod ThisFlx.Rows
Case Is = vbKeyDown: ThisFlx.Row = ThisFlx.Row + 1 Mod ThisFlx.Rows
Case Is = vbKeyRight: ThisFlx.Col = ThisFlx.Col + 1 Mod ThisFlx.Cols
Case Is = vbKeyLeft: ThisFlx.Col = ThisFlx.Col - 1 Mod ThisFlx.Cols
End Select
End Sub
Obviously, this is isn't working for me. There are several other ways that I could do it, but I'm sure there's a way this approach can work. I simply don't know the correct syntax for representing controls with variables. So my question is:
How do I represent a control with a variable.
The key line here is ThisFlx = flxFullAP. When this line executes, I get the following error: Object variable or With block variable not set.
Any help would be greatly appreciated. Thanks everybody!
-
Sep 22nd, 2005, 09:51 AM
#2
Re: Representing a Control With a Variable
Dim ThisFlx as Flexgrid (or whatever it is)
set ThisFlx = flxFullAP (or whichever you want)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 10:11 AM
#3
Thread Starter
Junior Member
Re: Representing a Control With a Variable
Thanks for the quick reply! I now get the following error:
Run-Time Error 13: Type Mismatch.
I get this error after the form_load event completes:
VB Code:
'Step-Through of Form_Load:
Private Sub Form_Load()
Set ThisFlx = flxFullAP
Set txtFloater.Font = ThisFlx.Font
Show
ThisFlx.Col = 0 'CALLS EnterCell CALLS PositionFloater
ThisFlx.Row = 0 'CALLS EnterCell CALLS PositionFloater
PositionFloater 'Appears to be redundant
End Sub 'ERROR FIRES UPON COMPLETION OF THIS LINE
-
Sep 22nd, 2005, 10:19 AM
#4
Thread Starter
Junior Member
Re: Representing a Control With a Variable
One more piece of info:
I don't know if it's important or not, but this form is being called modally from another form. When the Type Mismatch error occurs, the program's 'debug line' hangs on the modal call in the startup form, not in the actual form where the flexgrids are:
VB Code:
Private Sub Command1_Click()
[HL]formRateSheet.Show , vbModal[/HL]
End Sub
-
Sep 22nd, 2005, 10:27 AM
#5
Re: Representing a Control With a Variable
When I use the code you posted I don't get any error.
-
Sep 22nd, 2005, 10:29 AM
#6
Re: Representing a Control With a Variable
formRateSheet.Show , vbModal
The second argument to the Show method is the Owner Form. Get rid of the comma.
formRateSheet.Show vbModal
-
Sep 22nd, 2005, 10:42 AM
#7
Thread Starter
Junior Member
Re: Representing a Control With a Variable
 Originally Posted by brucevde
The second argument to the Show method is the Owner Form. Get rid of the comma.
AHA! I'm not exactly sure what your explanation means, so I'll have to review the formX.Show method. But after your suggestion I searched through all my code and found that my other formX.Show calls DID NOT include a comma. So that did the trick.... sort of.
Now I'm receiving the following error:
Run-Time Error 400: Form already displayed; can't show modally.
Once again, this error occurs after formRateSheet.Form_Load() completes.
Thanks again for all the quick help everybody!
-
Sep 22nd, 2005, 10:42 AM
#8
Re: Representing a Control With a Variable
when you have a form vbModal
any breaks will jump to that line because in a way.. vb is looping endlessly on that line untill the form is closed.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 10:49 AM
#9
Re: Representing a Control With a Variable
 Originally Posted by ufdigga
AHA! I'm not exactly sure what your explanation means, so I'll have to review the formX.Show method. But after your suggestion I searched through all my code and found that my other formX.Show calls DID NOT include a comma. So that did the trick.... sort of.
Now I'm receiving the following error:
Run-Time Error 400: Form already displayed; can't show modally.
Once again, this error occurs after formRateSheet.Form_Load() completes.
Thanks again for all the quick help everybody!
When you show a form using the vbModal parameter you are telling VB that you want the user to be locked into that form and not be able to go to any other form until the modal form is closed or it is no longer being shown modally. Since you are already showing one form modally, the error is telling you that you can't show a second one modally until you finish with the first.
-
Sep 22nd, 2005, 10:53 AM
#10
Thread Starter
Junior Member
Re: Representing a Control With a Variable
OK, after doing a search for that run-time error, it appears that I'm trying to show the form twice: once with formRateSheet.Show() in the startup form, and again in the Form_Load() method of formRateSheet.
So I removed the Show from Form_Load(). Now I get an invalid procedure error when I try to set focus to txtfloater within Form_Load (this first occurs when the line
VB Code:
ThisFlx.Col=0 CALLS EnterCell CALLS PositionFloater CALLS txtFloater.SetFocus.
I've run into this problem before when trying to set focus within the Form_Load event. How do I avoid this problem?
-
Sep 22nd, 2005, 10:55 AM
#11
Thread Starter
Junior Member
Re: Representing a Control With a Variable
Alright everybody, I'm all set. I've fixed the problem by eliminating the following lines from the Form_Load event:
VB Code:
Set ThisFlx = flxFullAP 'This sets the top-left flexgrid as the jumping-off point...
Set txtFloater.Font = ThisFlx.Font
'Show -> REMOVED
'ThisFlx.Col = 0 -> REMOVED
'ThisFlx.Row = 0 -> REMOVED
Thanks for everybody's help!
-
Sep 22nd, 2005, 11:02 AM
#12
Re: Representing a Control With a Variable
Unless there is other code to handle it, this code will cause errors.
VB Code:
Select Case KeyCode
Case Is = vbKeyUp: ThisFlx.Row = ThisFlx.Row - 1 Mod ThisFlx.Rows
Case Is = vbKeyDown: ThisFlx.Row = ThisFlx.Row + 1 Mod ThisFlx.Rows
Case Is = vbKeyRight: ThisFlx.Col = ThisFlx.Col + 1 Mod ThisFlx.Cols
Case Is = vbKeyLeft: ThisFlx.Col = ThisFlx.Col - 1 Mod ThisFlx.Cols
End Select
For example when you are already in the last row the ThisFlx.Row = ThisFlx.Row + 1 Mod ThisFlx.Rows in the vbKeyDown code will result in a row number equal to the number of rows, which is invalid since the rows start at 0. Similarly if you are already at the top row ThisFlx.Row = ThisFlx.Row - 1 Mod ThisFlx.Rows in the vbKeyUp code will result in -1 which of course is also an invalid row.
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
|