Two values in .tag of an option box

Hi ALl

I am wondering if I can store 2 different values in a .tag of an option button,
The code is below:

For iIndx = 0 To optMisRes.UBound      If optMisRes(iIndx).Value = True Then
            somethingsthere = True
            gDatatoSave.CallType = optMisRes(iIndx).Tag
            gDatatoSave.SubCallTypes = optMisRes(iIndx).Tag
        End If

What I am looking to do is save the value of CALLTYPE Which also has a SubCallType.
When an option button is clicked it will using an array store the value.

Problem been that there are 2 option button and all are different types of missed calls, but they need to be the same calltype, so I have a subcode assigned.

Anyone any ideas ??

Thanks
Aidan
LVL 2
aidan_gillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aidan_gillAuthor Commented:
Sorry what I meant to add was that it over wrote the CallType Value for some reason with the SubCalltype.

thanks
0
crazymanCommented:
You could store CallType in the tag and subCallType in an array or even a collection with its key being the CallType,there is no real need to store the variables in the .tag property
0
crazymanCommented:
If you really want to store them in the .tag try storing the data with a sperator say a | then splitting it in your function like



For iIndx = 0 To optMisRes.UBound      If optMisRes(iIndx).Value = True Then
                                       somethingsthere = True
                                       gDatatoSave.CallType = left(instr(optMisRes(iIndx).Tag,"|")-1))
                                       gDatatoSave.SubCallTypes = mid(instr(optMisRes(iIndx).Tag,"|")+1)
                                   End If
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

crazymanCommented:
For that to you have to input them into the .tag like

..tag=calltype & "|" & subCalltype
0
NancyShahCommented:
I agree to the comment given by CrazyMan
about using a separator..
0
mcriderCommented:
The TAG Property can only be set with strings, not types.  Why don't you just define a Public or Global variable in a module as the type of your type:


   Global MyInfo1 As CALLTYPE

Then you can just use the variable anywhere in your program...



Cheers!
0
crazymanCommented:
I was assuming that CallType and SubCallType were Variable names for strings other wise my soloution will not work as McRider said Object or types cannotr be stored in tags
0
freelnceCommented:
I have exactly what you want.  I wrote a class for storing and retrieving keyed information to the Tag property of any object in Visual Basic that supports the Tag property.  Here is the code:


'Attribute VB_Name = "modTagKeys"
'===================================================
' Module Name: modTagKeys
' Module File: TagKeys.Bas
'
' Author: Eddie E. Craig
' Date:   03/05/1998
'
' Purpose: Allows developer to use the tag property to store
'          values for either temporary or permanent use by
'          providing a keyed method to store and retrieve
'          these values to both an objects Tag property or
'          to the Registry or Application INI file. In a
'          32-bit OS the key list can be of virtually
'          unlimited size and can contain a virtually
'          unlimited number of individual keys.
'
' Tested/Completed Date: 03/11/1998
' Tested Platforms: Windows 95, Windows 98,
'                   Windows NT 4.0
'===================================================
Option Explicit

'--- Tag Key routines error variables. These two variables
'    can be used to check if an error was reported back by
'    any of the procedures in this module. The syntax for
'    using these variables is as follows:
'
' Example:
'
'    If LastKeyErr Then
'      sMsg = "Error "&cstr(lastkeyerr) & vbCr
'      sMsg = sMsg & LastKeyErrDesc
'
'      MsgBox sMsg, vbInformation, "TagKey Error"
'    End If
'
Public LastKeyErr           As Long
Public LastKeyErrDesc       As String


'--- Tag Key routines error constants. They are
'    made Public so that they may be used in
'    developers error trapping procedures.
Public Const fsTagKeyCreateFailed  As Long = 51000
Public Const fsTagKeyIsInvalid     As Long = 51001
Public Const fsTagKeyExists        As Long = 51002
Public Const fsTagKeyNotLoaded     As Long = 51003
Public Const fsTagKeyNotExist      As Long = 51004
Public Const fsTagKeyNotUpdated    As Long = 51005
Public Const fsTagEmpty            As Long = 51006
Public Const fsTagNotSaved         As Long = 51007
Public Const fsObjectNotAnArray    As Long = 343
Public Const fsObjectNotInRegistry As Long = 5

Private sDQuote As String



Public Function CreateKey _
    (ByVal sOrigKeyStr As String, _
     ByVal sKey As String, _
     ByVal sKeyValue As String, _
     Optional ByVal sKeyDefault As String = "") _
  As String
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Nothing
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Creates a unique key with which to store
'              and retrieve the value passed in sKeyValue
'              parameter and stores it in the .Tag property
'              of the oObjTag object.
'
' Parameters : sOrigKeyStr - The string from the .Tag property of the
'                            control in which you wish to add the
'                            newly created TagKey and value.
'
'              sKey        - The name you wish to use to reference
'                            the key. It cannot be empty or Null.
'
'              sKeyValue   - The value that you wish to store with
'                            this key. It can be any numerical or
'                            string value. No objects or arrays.
'
'              sKeyDefault - The default value you wish for the key to
'                            always be reset to. The default value for
'                            this parameter is an empty string ("").
'
' Example    :
'
'     '--- Sets the key named "FontName" to value "Ariel" with a default
'     '    value of "Ariel" in the .Tag property of the Label1 control.
'     '
'     Label1.Tag = CreateKey(Label1.Tag, "FontName", "Ariel", "Ariel")
'===================================================
  On Error GoTo Error_CreateKey
 
  sDQuote = Chr$(34)
  sOrigKeyStr = Trim$(sOrigKeyStr)

    If Len(sKey) Then
        If InStr(UCase$(sOrigKeyStr), UCase$(sKey)) Then
          Error fsTagKeyExists
         
        Else
          sKey = Trim$(sKey)
          sOrigKeyStr = sOrigKeyStr & "{[" & sKey & "~|" & sKeyValue
          sOrigKeyStr = sOrigKeyStr & "|~D|" & sKeyDefault & "]}"
        End If
    Else
      '--- You can't have an empty key name.
      Error fsTagKeyIsInvalid
    End If

  LastKeyErr = 0
  LastKeyErrDesc = ""
         
Exit_CreateKey:
  CreateKey = sOrigKeyStr
  On Error GoTo 0
  Exit Function
 
Error_CreateKey:
  CreateKey = False
 
    Select Case Err
      Case fsTagKeyIsInvalid
        LastKeyErr = fsTagKeyIsInvalid
        LastKeyErrDesc = "The key " & sDQuote & sKey & sDQuote & _
                         " is an invalid TagKey value."

      Case fsTagKeyExists
        LastKeyErr = fsTagKeyExists
        LastKeyErrDesc = "The key " & sDQuote & sKey & sDQuote & _
                         " already exists. " & _
                         "Use UpdateKey() to change the value of existing keys " & _
                         "or use RemoveKey() to remove it, then re-create it."
 
      Case Else
        LastKeyErr = Err
        LastKeyErrDesc = Err.Description
    End Select
   
  Resume Exit_CreateKey
End Function  '--- CreateKey()

Public Function CreateKeyList _
    (ByVal sOrigKeyStr As String, _
     asTagKeys() As String) _
  As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Nothing
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Creates an array of the keys that exist in the
'              .Tag property of the oObjTag object.
'
' Parameters : sOrigKeyStr - The string from the .Tag property of the
'                            control from which you wish to build a key
'                            list.
'
'              asTagKeys() - The array in which you wish to store the
'                            key list. It must be a string array.
'
' Example    :
'     If CreateKeyList(Label1.Tag, asKeyList()) then
'       ...
'       ...
'  or
'     Call CreateKeyList(Label1.Tag, asKeyList())
'  or
'     CreateKeyList Label1.Tag, asKeyList()
'===================================================
Dim iCount As Integer
Dim iFoundIt As Integer

  sOrigKeyStr = Trim$(sOrigKeyStr)
  iFoundIt = InStr(sOrigKeyStr, "]}")
 
    '--- Count the number of keys we need to store
    '    in the array.
    While iFoundIt
      iCount = iCount + 1
      iFoundIt = InStr(iFoundIt + 1, sOrigKeyStr, "]}")
    Wend
   
    '--- If there are valid keys in the tag property
    '    then we need to parse them into the array.
    If iCount Then
      ReDim asTagKeys(1 To iCount)
      iCount = 0
     
        While Len(sOrigKeyStr)
          iFoundIt = InStr(sOrigKeyStr, "]}")
         
            If iFoundIt Then
              iCount = iCount + 1
              asTagKeys(iCount) = Left$(sOrigKeyStr, iFoundIt + 1)
              sOrigKeyStr = Mid$(sOrigKeyStr, iFoundIt + 2)
             
            Else
              sOrigKeyStr = ""
            End If
        Wend
       
      CreateKeyList = True
      LastKeyErr = 0
      LastKeyErrDesc = ""
     
    Else
      CreateKeyList = False
    End If
End Function  '--- CreateKeyList()

Public Function DestroyAppKeys() As Boolean
  On Error Resume Next
  DeleteSetting App.Title, "Tag Keys"
 
  DestroyAppKeys = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
End Function  '--- DestroyAppKeys()

Public Function LoadAllTags(frmWho As Form) As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Loads the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to load with saved TagKey
'                         values.
'
' Example    :
'     If LoadAllTags(Me) then
'       ...
'       ...
'  or
'     Call LoadAllTags(frmOptions)
'  or
'     LoadAllTags frmMain
'===================================================
Dim oCtrl As Control
Dim sForm As String
Dim sKey  As String

  On Error GoTo Error_LoadAllTags
 
  sForm = ReadKey(frmWho.Tag, "FormIndex")
   
    If Len(sForm) Then
      sForm = frmWho.Name & "(" & sForm & ")" & "."
     
    Else
      sForm = frmWho.Name & "."
    End If
     
    For Each oCtrl In frmWho
      sKey = oCtrl.Name & _
             "(" & oCtrl.Index & ")"
   
      sKey = sForm & sKey
     
      oCtrl.Tag = LoadTag(oCtrl)
    Next
 
  LoadAllTags = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_LoadAllTags:
  On Error GoTo 0
  Exit Function
 
Error_LoadAllTags:
  LastKeyErr = Err
 
    Select Case Err
      Case fsObjectNotAnArray
        sKey = oCtrl.Name
        LastKeyErr = 0
        Resume Next
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  LoadAllTags = False
  Resume Exit_LoadAllTags
End Function  '--- LoadAllTags()

Public Function LoadTag(oObject As Object) As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Loads the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file. If .Tag property is empty then no
'              registry entry is created. This keeps registry
'              bloat to a minimum.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to load with saved TagKey
'                         values.
'
' Example    :
'     If LoadTag(Me) then
'       ...
'       ...
'  or
'     Call LoadTag(frmOptions)
'  or
'     LoadTag frmMain
'===================================================
Dim sForm As String
Dim sKey  As String

  On Error GoTo Error_LoadTag
 
    If TypeOf oObject Is Form _
    Or TypeOf oObject Is MDIForm Then
      sForm = ReadKey(oObject.Tag, "FormIndex")
   
        If Len(sForm) Then
          sForm = oObject.Name & "(" & sForm & ")"
         
        Else
          sForm = oObject.Name
        End If
   
    Else
      sForm = ReadKey(oObject.Parent.Tag, "FormIndex")
   
        If Len(sForm) Then
          sForm = oObject.Parent.Name & "(" & sForm & ")."
         
        Else
          sForm = oObject.Parent.Name & "."
        End If
   
      sKey = oObject.Name & _
             "(" & oObject.Index & ")"
    End If
   
  sKey = sForm & sKey
 
  oObject.Tag = GetSetting(App.Title, "Tag Keys", sKey, "NoTag")
 
    If oObject.Tag = "NoTag" Then
      oObject.Tag = ""
     
      Error fsTagNotSaved
    End If
   
  LoadTag = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_LoadTag:
  On Error GoTo 0
  Exit Function
 
Error_LoadTag:
  LastKeyErr = Err
   
    Select Case LastKeyErr
      Case fsObjectNotAnArray
        sKey = oObject.Name
        LastKeyErr = 0
        LastKeyErrDesc = ""
        Resume Next
     
      Case fsTagNotSaved, fsObjectNotInRegistry
        LastKeyErrDesc = "The tag key " & sKey & " does not exist " & _
                         "in the system registry."
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  LoadTag = False
  Resume Exit_LoadTag
End Function  '--- LoadTag()

Public Function RawKeyList _
    (ByVal sOrigKeyStr As String, _
     asTagKeys() As String) _
  As Integer
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Nothing
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Creates an array of the keys that exist in the
'              .Tag property of the oObjTag object.
'
' Parameters : sOrigKeyStr - The string from the .Tag property of the
'                            control from which you wish to build a key
'                            list.
'
'              asTagKeys() - The array in which you wish to store the
'                            key list. It must be a string array.
'
' Example    :
'     If RawKeyList(Label1.Tag, asKeyList()) then
'       ...
'       ...
'  or
'     Call RawKeyList(Label1.Tag, asKeyList())
'  or
'     RawKeyList Label1.Tag, asKeyList()
'===================================================
Dim sKey     As String
Dim iCount   As Integer
Dim iFoundIt As Integer

  sOrigKeyStr = Trim$(sOrigKeyStr)
  iFoundIt = InStr(sOrigKeyStr, "]}")
 
    '--- Count the number of keys we need to store
    '    in the array.
    While iFoundIt
      iCount = iCount + 1
      iFoundIt = InStr(iFoundIt + 1, sOrigKeyStr, "]}")
    Wend
   
    '--- If there are valid keys in the tag property
    '    then we need to parse them into the array.
    If iCount Then
      ReDim asTagKeys(1 To iCount)
      iCount = 0
     
        While Len(sOrigKeyStr)
          iFoundIt = InStr(sOrigKeyStr, "{[")
         
            If iFoundIt Then
              iCount = iCount + 1
              sKey = Mid$(sOrigKeyStr, iFoundIt + 2)
              sKey = Left$(sKey, (InStr(sKey, "~|") - 1))
              asTagKeys(iCount) = sKey
              sOrigKeyStr = Mid$(sOrigKeyStr, (InStr(sOrigKeyStr, "]}") + 2))
             
            Else
              sOrigKeyStr = ""
            End If
        Wend
       
      RawKeyList = iCount
      LastKeyErr = 0
      LastKeyErrDesc = ""
     
    Else
      RawKeyList = 0
    End If
End Function  '--- RawKeyList()

Public Function ReadKey _
    (ByVal sOrigKeyStr As String, _
     ByVal sKey As String, _
     Optional ByVal bDefault As Boolean = False) _
  As String
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Nothing
'
' Returns    : A string.
'
' Purpose    : Retrieves the value of the key specified in sKey
'              from the oObjTag object's .Tag property.
'
' Parameters : sOrigKeyStr - The string from the .Tag property of the
'                            control from which you wish to read the
'                            TagKey value.
'
'              sKey     - The name of the key whose value you
'                         wish to retrieve. It cannot be empty
'                         or Null.
'
' Example    :
'
'     '--- Create the key FontName with a value of Ariel.
'     Call CreateKey(Label1, "FontName", "Ariel")
'
'     '--- Assigns the value of FontName, which is "Ariel"
'     '    to the variable sMyVar.
'     sMyVar = ReadKey(Label1.Tag, "FontName")
'===================================================
Dim sWorkKey As String
Dim iFoundIt As Integer
Dim sTempKey As String

  On Error GoTo Error_ReadKey
 
  sWorkKey = sOrigKeyStr
  sTempKey = UCase$("{[" & sKey & "~|")
  iFoundIt = InStr(UCase$(sWorkKey), sTempKey)
 
    If iFoundIt Then
      '--- We are looking to read the default value for the key
      '    instead of the current value.
      If bDefault Then
        '--- The key was found, so extract the default key value
        '    from the middle of the Tag values.
        iFoundIt = InStr((iFoundIt + Len(sTempKey)), sWorkKey, "|~D|")
        sWorkKey = Mid$(sWorkKey, iFoundIt + 4)
        iFoundIt = InStr(sWorkKey, "]}")
     
      Else
        '--- The key was found, so extract the key value from
        '    the middle of the Tag values.
        sWorkKey = Mid$(sWorkKey, iFoundIt + Len(sTempKey))
        iFoundIt = InStr(sWorkKey, "|~D|")
      End If
     
             
      If iFoundIt Then
        '--- Get just the key value.
        sWorkKey = Mid$(sWorkKey, 1, iFoundIt - 1)
      End If
   
    Else
      Error fsTagKeyNotExist
    End If
   
  ReadKey = sWorkKey
  LastKeyErr = 0
  LastKeyErrDesc = ""

Exit_ReadKey:
  On Error GoTo 0
  Exit Function
 
Error_ReadKey:
  LastKeyErr = Err
  ReadKey = ""
 
    Select Case Err
      Case fsTagKeyNotExist
        LastKeyErrDesc = "The key " & sDQuote & sKey & sDQuote & _
                         " does not exist."
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select

  Resume Exit_ReadKey
End Function  '--- ReadKey()

Public Function RemoveAllTags(frmWho As Form) As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Clears the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to clear of TagKey values.
'
' Example    :
'     If RemoveAllTags(Me) then
'       ...
'       ...
'  or
'     Call RemoveAllTags(frmOptions)
'  or
'     RemoveAllTags frmMain
'===================================================
Dim oCtrl As Control
Dim sForm As String
Dim sKey  As String

  On Error GoTo Error_RemoveAllTags
 
  sForm = ReadKey(frmWho.Tag, "FormIndex")
   
    If Len(sForm) Then
      sForm = frmWho.Name & "(" & sForm & ")" & "."
     
    Else
      sForm = frmWho.Name & "."
    End If
     
    For Each oCtrl In frmWho
      sKey = oCtrl.Name & _
             "(" & oCtrl.Index & ")"
   
      sKey = sForm & sKey
     
      oCtrl.Tag = RemoveTag(oCtrl)
    Next
 
  RemoveAllTags = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_RemoveAllTags:
  On Error GoTo 0
  Exit Function
 
Error_RemoveAllTags:
  LastKeyErr = Err
 
    Select Case Err
      Case fsObjectNotAnArray
        sKey = oCtrl.Name
        LastKeyErr = 0
        Resume Next
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  RemoveAllTags = False
  Resume Exit_RemoveAllTags
End Function  '--- RemoveAllTags()

Public Function RemoveKey _
    (ByVal sOrigKeyStr As String, _
     ByVal sKey As String) _
  As String
Dim sWorkKey      As String
Dim sTempKey      As String
Dim iFoundItStart As Long
Dim iFoundItEnd   As Long

  On Error GoTo Error_RemoveKey

  sWorkKey = sOrigKeyStr
  sTempKey = UCase$("{[" & sKey & "~|")
  iFoundItStart = InStr(UCase$(sWorkKey), sTempKey)
 
    If iFoundItStart Then
      '--- The key was found, so get the entire key length.
      iFoundItEnd = (InStr((iFoundItStart + Len(sTempKey)), sWorkKey, "]}") + 2)
     
      sWorkKey = Mid$(sOrigKeyStr, 1, iFoundItStart - 1) & _
                 Mid$(sOrigKeyStr, iFoundItEnd)
     
    Else
      Error fsTagKeyIsInvalid
    End If
 
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_RemoveKey:
  RemoveKey = sWorkKey
 
  On Error GoTo 0
  Exit Function
 
Error_RemoveKey:
  RemoveKey = sKey
  LastKeyErr = Err
 
    Select Case LastKeyErr
      Case fsTagKeyNotLoaded
        LastKeyErrDesc = "The specified TagKey: " & _
                         sKey & _
                         " does not exist in the registry or key file."
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  Resume Exit_RemoveKey
End Function  '--- RemoveKey()

Public Function RemoveTag(oObject As Object) As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Loads the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file. If .Tag property is empty then no
'              registry entry is created. This keeps registry
'              bloat to a minimum.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to load with saved TagKey
'                         values.
'
' Example    :
'     If RemoveTag(Me) then
'       ...
'       ...
'  or
'     Call RemoveTag(frmOptions)
'  or
'     RemoveTag frmMain
'===================================================
Dim sForm As String
Dim sKey  As String
Dim sTag  As String

  On Error GoTo Error_RemoveTag
 
    If TypeOf oObject Is Form _
    Or TypeOf oObject Is MDIForm Then
      sForm = ReadKey(oObject.Tag, "FormIndex")
   
        If Len(sForm) Then
          sForm = oObject.Name & "(" & sForm & ")"
         
        Else
          sForm = oObject.Name
        End If
   
    Else
      sForm = ReadKey(oObject.Parent.Tag, "FormIndex")
   
        If Len(sForm) Then
          sForm = oObject.Parent.Name & "(" & sForm & ")."
         
        Else
          sForm = oObject.Parent.Name & "."
        End If
   
      sKey = oObject.Name & _
             "(" & oObject.Index & ")"
    End If
   
  sKey = sForm & sKey
  sTag = Trim$(oObject.Tag)
 
    '--- Don't attempt to delete a non-existant key.
    If Len(sTag) Then
      DeleteSetting App.Title, "Tag Keys", sKey
     
    Else
      Error fsTagEmpty
    End If
   
  RemoveTag = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_RemoveTag:
  On Error GoTo 0
  Exit Function
 
Error_RemoveTag:
  LastKeyErr = Err
 
    Select Case LastKeyErr
      Case fsTagNotSaved, fsObjectNotInRegistry
        LastKeyErrDesc = "The tag key " & sKey & _
                         " does not exist " & _
                         "in the system registry."
                         
      Case fsObjectNotAnArray
        sKey = oObject.Name
        LastKeyErr = 0
        LastKeyErrDesc = ""
        Resume Next
     
      Case fsTagEmpty
        LastKeyErrDesc = "The specified .Tag property has " & _
                         "no defined keys to remove."
                         
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  RemoveTag = False
  Resume Exit_RemoveTag
End Function  '--- RemoveTag()

Public Function ResetAllKeys(frmWho As Form) As Boolean
Dim oCtrl       As Control
Dim asRawKeys() As String
Dim sKey        As String
Dim sKeyDefault As String
Dim iKey        As Integer
Dim iKeys       As Integer
Dim iFoundIt    As Long

  On Error GoTo Error_ResetAllKeys
'If Len(sOrigKeyStr) Then Stop
 
    For Each oCtrl In frmWho
      iKeys = RawKeyList(oCtrl.Tag, asRawKeys())
     
        For iKey = 1 To iKeys
          sKey = asRawKeys(iKey)
          oCtrl.Tag = ResetKey(oCtrl.Tag, sKey)
'          sKeyDefault = ReadKey(sOrigKeyStr, sKey, True)
'          oCtrl.Tag = UpdateKey(sOrigKeyStr, sKey, sKeyDefault)
        Next
    Next

  ResetAllKeys = True
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_ResetAllKeys:
  On Error GoTo 0
  Exit Function
 
Error_ResetAllKeys:
  ResetAllKeys = False
  LastKeyErr = Err
 
    Select Case LastKeyErr
      Case 0
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
 
  Resume Exit_ResetAllKeys
End Function  '--- ResetAllKeys()

Public Function ResetKey _
    (ByVal sOrigKeyStr As String, _
     ByVal sKey As String) _
  As String
Dim sKeyDefault As String

  sKeyDefault = ReadKey(sOrigKeyStr, sKey, True)
  ResetKey = UpdateKey(sOrigKeyStr, sKey, sKeyDefault)
End Function  '--- ResetKey()

Public Function SaveAllTags(frmWho As Form) As Integer
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Loads the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file. If .Tag property is empty then no
'              registry entry is created. This keeps registry
'              bloat to a minimum.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to load with saved TagKey
'                         values.
'
' Example    :
'     If SaveAllTags(Me) then
'       ...
'       ...
'  or
'     Call SaveAllTags(frmOptions)
'  or
'     SaveAllTags frmMain
'===================================================
Dim sForm As String
Dim sKey  As String
Dim sTag  As String
Dim oCtrl As Control
Dim Count As Integer

  On Error GoTo Error_SaveAllTags
 
  sForm = ReadKey(frmWho.Tag, "FormIndex")
   
    If Len(sForm) Then
      sForm = frmWho.Name & "(" & sForm & ")."
     
    Else
      sForm = frmWho.Name & "."
    End If
     
    For Each oCtrl In frmWho
      sKey = oCtrl.Name & _
             "(" & oCtrl.Index & ")"
      sKey = sForm & sKey
      sTag = Trim$(oCtrl.Tag)
       
        '--- Don't save an empty .Tag property to the registry.
        '    This will just bloat the size of th registry for
        '    no useful reason.
        If Len(sTag) Then
          Count = Count + 1
          SaveSetting App.Title, "Tag Keys", sKey, sTag
        End If
    Next
 
  LastKeyErr = 0
  LastKeyErrDesc = ""
 
Exit_SaveAllTags:
  SaveAllTags = Count
  On Error GoTo 0
  Exit Function
 
Error_SaveAllTags:
  LastKeyErr = Err
 
    Select Case Err
      Case fsObjectNotAnArray
        sKey = oCtrl.Name
        LastKeyErr = 0
        LastKeyErrDesc = ""
        Resume Next
     
      Case Else
        LastKeyErrDesc = Err.Description
    End Select
   
  Resume Exit_SaveAllTags
End Function  '--- SaveAllTags()

Public Function SaveTag(oObject As Object) As Boolean
'===================================================
' Tested Date: 03/11/1998
' Platforms  : Windows 3.1x, Windows 95,
'              Windows NT 3.51, Windows NT 4.0
'
'
' Assumes    : Possibility of pre-existing .Tag key named "FormIndex"
'              for MDI child or multiple instance forms. This key will
'              have a value equal to the loaded index of the specified
'              form, if it is used.
'
' Returns    : A Boolean value. True if successful,
'              False if failed.
'
' Purpose    : Loads the .Tag property for all objects on a
'              form with values stored in the registry/.INI
'              file. If .Tag property is empty then no
'              registry entry is created. This keeps registry
'              bloat to a minimum.
'
' Parameters : frmWho   - The form whose object.Tag properties
'                         you wish to load with saved TagKey
'                         values.
'
' Example    :
'     If SaveTag(Me) then
'       ...
'       ...
'  or
'     Call SaveTag(frmOptions)
'  or
'     SaveTag frmMain
'===================================================
Dim sForm As String
Dim sKey  As String
Dim sTag  As String

  On Error GoTo Error_SaveTag
 
    If TypeOf oObject Is Form _
    Or TypeOf oObject Is MDIForm Then
      sForm = ReadKey(oObject.Tag, "FormIndex")
   
        If Len(sForm) Then
          sForm = oObject.Name & "(" & sForm & ")"
         
        Else
          sForm = oObject.Name
        End If
   
    Else
      sForm = ReadKey(oObject.Parent.Tag, "FormIndex")
       
        If Len(sForm) Then
          sForm = oObject.Parent.Name & "(" & sForm & ")."
         
        Else
          sForm = oObject.Parent.Name & "."
        End If
   
      sKey = oObject.Name & _
             "(" & oObject.Index & ")"
    End
0
aidan_gillAuthor Commented:
FreeInce

I apologise for rejecting this but it is huge, if you could alter my ? with your ans I would be grateful

Sorry again
AIdan
0
mcriderCommented:
I still say just define a Public or Global variable in a module and you can use the variable anywhere in your program... It's a 1 line definition and you're done...

Cheers!
0
freelnceCommented:
Hello again adian_gill,

I don't mind that you rejected the answer if it does not fit your particular needs, but you might want to take a look at all the capabilites contained in this class before waving it off as not being viable because of it's size.  You might find that you can expand your original concept of capabilites and features far above and beyond those you thought possible.

The class is not as big as it may look and you will write a good amount of code anyway to store and retrieve multiple values in a single Tag property.  Even though mcrider is correct that you could declare Public variables, this method uses more resources needed by your program than the class method would, especially if you had many such variables you had to use.    The true beauty of this class is that it can make variables for non-speed intensive areas of your code completely optional and this will save you a huge amount of resources. This is especially true if you wanted to store information in many different Tags on many different objects.  The class does contain a lot of code but the benefit of what it can do far surpasses the negligible resource use it causes.  In your particular case, where you want to store only a couple of values, it might be overkill, but if you determined that you would like to store many such values, using the same Tag reference but containing different values, this is where this class far surpasses the ability of Public variables, for example:

You have several forms in you app and they all are end user customizable in some form or fashion. The user can change the Backcolor of each control individually for faster location and reference on the screen and can even change the font name, size and foreground color.  This gives you four values for each field that you must be able to recall and store when your app begins and ends:

   Font Name
   Font Size
   Fore Color
   Back Color

With the class I provided you can create,  retrieve, update,and delete each of these values individually as well as save and retrieve the entire Tag property to and from the system registry so they can be used each time your application is started.  This allows your app to retain these settings so the user does not have to re-enter them each time they start your app.
If you used Public variables then you would have to have four extra Public variables and the code to loop through every control, assign the current properties to these variables, and save/retrieve these values individually to/from the registry.  This also creates four seperate registry entries for each control instead of the single one the class creates.  This circle continues and increases the amount of code with each new level of customization you supply to your end user, the class does not require you to write any extra code outside of the class method references.


Hope this helps.
0
mcriderCommented:
aidan_gill,

Just checking back... Did any of the comments above help you?


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aidan_gillAuthor Commented:
mcrider

I used something else that I came up with my self, not tags, but you gave me some useful code and a lot of time,
so I am given you the points
thanks for your help
regards
Aidan
0
mcriderCommented:
Thanks for the points! Glad I could help you!  By the way, Please post what you did...


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.