Tech Support > Computers & Technology > Programming > vb 6.0 passing arguments
vb 6.0 passing arguments
Posted by Tone Southerland on October 31st, 2003


Hi everyone,

I need help passing arguments in VB 6.0. I have set up a program to
dynamically create buttons and also access an EXE path from a database
to run a program. My problem lies in passing a string (xxx) variable
instead of an integer or literal string. I am trying to pass the var
xxx simply as a test, so if that works then I can pull actual path
from DB and put it into another variable. I get the error 'Object
variable or with block variable not set.' The error comes from where
I try to put the string into the array(or collection I forget which
one). I don't understand why it will take a literal string but not
string variable. A snippet of my code is below. Thanx for anyone
who can help!

Tone




Private Sub Form_Load()
lblTitle.Width = 8750
LoadControl Me, "VB.PictureBox", "picObj", "", Me.Height - 400,
Me.Width - 400, 450, 0

Dim z As Integer

Dim xxx As String
xxx = "123"

For z = 0 To 3
intTop = intTop + 360
LoadControl Me, "VB.CommandButton", xxx, "Command" & z, 315,
2000, intTop, intLeft

Next z

End Sub

Sub LoadControl(frm As Form, strControlType As String, strControlName
As String, strPathName As String, intHeight As Integer, intWidth As
Integer, intTop As Integer, intLeft As Integer)

On Error Resume Next

Dim newBtn As Control

Set newBtn = frm.Controls.Add(strControlType, strControlName)
' Set lblTitle.Container = newBtn
With newBtn
.Height = intHeight
.Width = intWidth
.Top = intTop
.Left = intLeft
.Visible = True
End With

ReDim Preserve clsBtn(UBound(clsBtn) + 1)
If Err Then ReDim Preserve clsBtn(0): Err.Clear

Set clsBtn(UBound(clsBtn)) = New clsControl
clsBtn(UBound(clsBtn)).Index = UBound(clsBtn)

If (TypeOf newBtn Is CommandButton) Then
newBtn.Caption = strControlName
Set newBtn.Container = frm.Controls("picObj")
Set clsBtn(UBound(clsBtn)).btn = newBtn
End If

If Err Then
MsgBox Err.Number & ": " & Err.Description, vbExclamation
Err.Clear
End
End If
End Sub

Posted by Programmer Dude on October 31st, 2003


Tone Southerland wrote:

Hard to tell from the information presented, but it might be the
old ".Key requires an obvious string" problem. The .Key property
of a Collection *MUST* be an obvious string, it cannot be a number
in string form. For example, your...

Dim xxx As String
xxx = "123"

Will look like the number 123 -- not a legal .Key property. When
you use a literal string, it's obviously a string and works. If
you must plug numeric keys into objects, a trick I use is to prepend
a non-numeric. I use "#". You might seem something like this in
my code:

some_object.Add (some_object, "#" & numeric_key_value)


(p.s.
The reason for this requirement is so that VB can distinquish
between:

some_collection(42) -- numeric .Index
some_collection("foobar") -- string .Key

Which seems clear enough, but what about:

Dim x As Variant, y As Variant
some_collection(x) -- numeric .Index ???
some_collection(y) -- string .Key ???
)

--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|


Similar Posts