|
-
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!
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
|