Harvey
Wed Oct 15 11:38:55 CDT 2008
Another apprach:
Private Sub Form_Load() ' sample
AddVariable "Animal", "Dog"
MsgBox GetValue("Animal")
PutValue "Animal", "Cat"
MsgBox GetValue("Animal")
End Sub
How to (short version):
- Add new dll activex project
- Instancig of class1: GlobalMultiUse
(name os class1 is optional)
- Add this code to class:
Option Explicit
Private Type structVariable
Name As String
Value As String
End Type
Private a() As structVariable
Private n As Long
Public Sub AddVariable(Name As String, Optional Value As String = "")
n = n + 1
ReDim Preserve a(1 To n)
a(n).Name = Name
a(n).Value = Value
End Sub
Public Function GetValue(Name As String) As String
Dim i As Long
For i = 1 To n
If a(i).Name = Name Then
GetValue = a(i).Value
End If
Next
End Function
Public Sub PutValue(Name As String, v As String)
Dim i As Long
For i = 1 To n
If a(i).Name = Name Then
a(i).Value = v
End If
Next
End Sub
<Harvey Triana>
http://vexpert.mvps.org
"Larry Serflaten" <serflaten@usinternet.com> escribió en el mensaje
news:exe8DWfLJHA.468@TK2MSFTNGP06.phx.gbl...
>
> "DevonWerkheiser" <DevonWerkheiser@discussions.microsoft.com> wrote
>
>> It's quite complex, but it does the job. At least I have something to
>> play
>> with. :)
>
> You can do a similar task using intrinsic VB objects. Add a class to a
> new project and add in the next two lines into its code module:
>
> Public Name As String
> Public Value As String
>
>
> Then paste this into your form:
>
> Option Explicit
> Public Vars As Collection
>
> Private Sub Form_Initialize()
> Set Vars = New Collection
> End Sub
>
> Private Sub Form_Load()
> NewVariable "Textbox", "Hello World"
> MsgBox Vars("Text" & "Box").Value
> End Sub
>
> Sub NewVariable(Name As String, Value As String)
> Dim v As New Class1
> v.Name = Name
> v.Value = Value
> Vars.Add v, v.Name
> End Sub
>
> Private Sub Form_Terminate()
> Set Vars = Nothing
> End Sub
>
>
> Just another way to do that job...
> LFS
>
>