isnoend2001
asked on
name cells in msflexgrid using vb6
Hi
I use many msFlexgrids in different project,like this:
grid.textmatrix(2,4) = "runs"
how can i name the textmatrix(2,4) to a name and then refer to the name ?
using vb6
I use many msFlexgrids in different project,like this:
grid.textmatrix(2,4) = "runs"
how can i name the textmatrix(2,4) to a name and then refer to the name ?
using vb6
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thought their may have been a simple solution
MartinLiss
have to give your solution some thought.
Most have a description column and a data column
so that might work
aikimark
many apps are included in setups and i hate to include references eg;vbscript
It may be easier to just to use it like i have been
MartinLiss
have to give your solution some thought.
Most have a description column and a data column
so that might work
aikimark
many apps are included in setups and i hate to include references eg;vbscript
It may be easier to just to use it like i have been
ASKER
got this from another forum:
Option Explicit
Private colRows As Collection
Private colCols As Collection
Private Sub AllocateName(strName As String, intRow As Integer, intCol As Integer, Optional boModify = False)
'
' Inserts values in the 'look-up' table
' If the optional argument is specified as True, will modify an
' existing name's row and column
'
If Not boModify Then
On Error Resume Next ' we're going to check the error code
colRows.Add intRow, strName
If Err.Number = 0 Then
On Error GoTo 0 ' back to normal error handling
colCols.Add intCol, strName
Else
On Error GoTo 0 ' back to normal error handling
MsgBox "Name " & strName & " already Allocated"
End If
Else
On Error Resume Next 'Ignore the error if it's not there
colRows.Remove strName
colCols.Remove strName
On Error GoTo 0 ' Back to normal error handling
colRows.Add intRow, strName
colCols.Add intCol, strName
End If
End Sub
Private Sub SetValue(gr As MSFlexGrid, strName As String, strValue As String)
Dim intRow As Integer
Dim intCol As Integer
intRow = colRows.Item(strName)
intCol = colCols.Item(strName)
gr.TextMatrix(intRow, intCol) = strValue
End Sub
Private Function GetValue(gr As MSFlexGrid, strName As String) As String
Dim intRow As Integer
Dim intCol As Integer
intRow = colRows.Item(strName)
intCol = colCols.Item(strName)
GetValue = gr.TextMatrix(intRow, intCol)
End Function
Private Sub Form_Load()
Set colRows = New Collection
Set colCols = New Collection
grid.Rows = 5
grid.Cols = 5
grid.FixedCols = 0
grid.FixedRows = 1
grid.TextMatrix(2, 0) = "Fred's second value"
Call AllocateName("Fred", 1, 0)
Call AllocateName("Bert", 1, 1)
SetValue grid, "Fred", "Doogle"
SetValue grid, "Bert", "Doogle2"
Debug.Print GetValue(grid, "Fred")
AllocateName "Fred", 2, 0, True
Debug.Print GetValue(grid, "Fred")
End Sub
thought there might be something simple
Think i will stick with referring to cells like i have been
Option Explicit
Private colRows As Collection
Private colCols As Collection
Private Sub AllocateName(strName As String, intRow As Integer, intCol As Integer, Optional boModify = False)
'
' Inserts values in the 'look-up' table
' If the optional argument is specified as True, will modify an
' existing name's row and column
'
If Not boModify Then
On Error Resume Next ' we're going to check the error code
colRows.Add intRow, strName
If Err.Number = 0 Then
On Error GoTo 0 ' back to normal error handling
colCols.Add intCol, strName
Else
On Error GoTo 0 ' back to normal error handling
MsgBox "Name " & strName & " already Allocated"
End If
Else
On Error Resume Next 'Ignore the error if it's not there
colRows.Remove strName
colCols.Remove strName
On Error GoTo 0 ' Back to normal error handling
colRows.Add intRow, strName
colCols.Add intCol, strName
End If
End Sub
Private Sub SetValue(gr As MSFlexGrid, strName As String, strValue As String)
Dim intRow As Integer
Dim intCol As Integer
intRow = colRows.Item(strName)
intCol = colCols.Item(strName)
gr.TextMatrix(intRow, intCol) = strValue
End Sub
Private Function GetValue(gr As MSFlexGrid, strName As String) As String
Dim intRow As Integer
Dim intCol As Integer
intRow = colRows.Item(strName)
intCol = colCols.Item(strName)
GetValue = gr.TextMatrix(intRow, intCol)
End Function
Private Sub Form_Load()
Set colRows = New Collection
Set colCols = New Collection
grid.Rows = 5
grid.Cols = 5
grid.FixedCols = 0
grid.FixedRows = 1
grid.TextMatrix(2, 0) = "Fred's second value"
Call AllocateName("Fred", 1, 0)
Call AllocateName("Bert", 1, 1)
SetValue grid, "Fred", "Doogle"
SetValue grid, "Bert", "Doogle2"
Debug.Print GetValue(grid, "Fred")
AllocateName "Fred", 2, 0, True
Debug.Print GetValue(grid, "Fred")
End Sub
thought there might be something simple
Think i will stick with referring to cells like i have been
>>i hate to include references eg;vbscript
There are no references. This is a dynamic object creation from a system resource.
There is no VB Script in this code or this object.
>>It may be easier to just to use it like i have been
* So two different collections are easier than a single dictionary object?!?
* The advantage of the dictionary object in this scenario is that you can use its .Exists() method to determine if the key/name has been defined. Another advantage is that dictionary keys can be numeric values.
Here's a good article on the Dictionary class worth reading:
http:A_3391-Using-the-Dictionary-Class-in-VBA.html
Note: duplicated keys/names in the two collection configuration waste memory
Here is a version of your code that uses a dictionary and the class object mentioned in my prior comment.
There are no references. This is a dynamic object creation from a system resource.
There is no VB Script in this code or this object.
>>It may be easier to just to use it like i have been
* So two different collections are easier than a single dictionary object?!?
* The advantage of the dictionary object in this scenario is that you can use its .Exists() method to determine if the key/name has been defined. Another advantage is that dictionary keys can be numeric values.
Here's a good article on the Dictionary class worth reading:
http:A_3391-Using-the-Dictionary-Class-in-VBA.html
Note: duplicated keys/names in the two collection configuration waste memory
Here is a version of your code that uses a dictionary and the class object mentioned in my prior comment.
Option Explicit
Private dicBookmarks As Object
Private Sub AllocateName(strName As String, intRow As Integer, intCol As Integer, Optional boModify = False)
'
' Inserts values in the 'look-up' table
' If the optional argument is specified as True, will modify an
' existing name's row and column
'
Dim clsBookmark As clsArrayPoint
If boModify Then
If dicBookmarks.Exists(strName) Then
dicBookmarks(strName).TMrow = intRow
dicBookmarks(strName).TMcol = intCol
Else
MsgBox "Name " & strName & " does not exist -- modify not possible."
'shouldn't this really be an .Add action here instead of an error?
End If
Else
If dicBookmarks.Exists(strName) Then
MsgBox "Name " & strName & " already Allocated -- create not possible."
'shouldn't this really be a replace/update action here instead of an error?
Else
Set clsBookmark = New clsArrayPoint
With clsBookmark
.TMrow = intRow
.TMcol = intCol
End With
dicBookmarks.Add strName, clsBookmark
End If
End If
End Sub
Private Sub SetValue(gr As MSFlexGrid, strName As String, strValue As String)
If dicBookmarks.Exists(strName) Then
gr.TextMatrix(dicBookmarks(strName).TMrow, dicBookmarks(strName).TMcol) = strValue
Else
MsgBox "Name " & strName & " does not exist -- SetValue not possible."
End If
End Sub
Private Function GetValue(gr As MSFlexGrid, strName As String) As String
If dicBookmarks.Exists(strName) Then
GetValue = gr.TextMatrix(dicBookmarks(strName).TMrow, dicBookmarks(strName).TMcol)
Else
MsgBox "Name " & strName & " does not exist -- GetValue not possible."
End If
End Function
Private Sub Form_Load()
Set dicBookmarks = CreateObject("scripting.dictionary")
grid.Rows = 5
grid.Cols = 5
grid.FixedCols = 0
grid.FixedRows = 1
grid.TextMatrix(2, 0) = "Fred's second value"
Call AllocateName("Fred", 1, 0)
Call AllocateName("Bert", 1, 1)
SetValue grid, "Fred", "Doogle"
SetValue grid, "Bert", "Doogle2"
Debug.Print GetValue(grid, "Fred")
AllocateName "Fred", 2, 0, True
Debug.Print GetValue(grid, "Fred")
End Sub
ASKER
Thanks for explaining. i thought the scripting.dictionary was a reference
If you don't use createobject(), then you will need a reference in your project for any non-intrinsic object.
The dictionary object is closely related to the filesystemobject, which you probably use elsewhere in your application, since they both belong to the "scripting" library/namespace.
The dictionary object is closely related to the filesystemobject, which you probably use elsewhere in your application, since they both belong to the "scripting" library/namespace.
ASKER