Page 1 of 1 1
Topic Options
#99092 - 2003-03-05 04:15 AM Off Topic - VB and ActiveX Dlls
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I was wondering if there are any VB gurus on this board. I would have posted this to a VB board, but it does concern kix, in a way.

I'm trying to teach myself VB and I thought a good first project would be to create a DLL that I could use with kix. Basically, once the dll is registered you can use createobject to make a poor-man's structure.

But I'm having problems passing strings from kix to my dll. I'm just hoping someone out there can show me the way. Here's the VB code for my class.

code:
  
'declarations
Private propertyNames() As Variant
Private propertyValues() As Variant
Private declared As Boolean

'intitialize class
Private Sub Class_Initialize()
declared = False
End Sub


'add properties to the struct
Public Sub addProps(props() As Variant)
If Not delcared Then
ReDim propertyNames(LBound(props) To UBound(props)) As Variant
ReDim propertyValues(LBound(props) To UBound(props)) As Variant
propertyNames = props
declared = True
End If
End Sub



'give a property a value
Public Sub setProperty(pName As Variant, data As Variant)
Dim size As Integer
size = UBound(propertyNames)
If declared Then
For j = 0 To size
If propertyNames(j) = pName Then
propertyValues(j) = data
Exit For
End If
Next
End If

End Sub



'retrieve a properties value
Public Function getProperty(pName As Variant) As Variant
Dim size As Integer
size = UBound(propertyNames)
If declared Then
For j = 0 To size
If propertyNames(j) = pName Then
getProperty = propertyValues(j)
Exit For
End If
Next
End If
End Function

And here is a sample kix script to use the dll

code:
break on

$employee1 = employeeStruct()
$employee1.setProperty("Name", "Eric")
$employee1.setProperty("ID", "1234567")
$tempName = $employee1.getProperty("Name")
? "name: " $tempName
exit

Function employeeStruct()
dim $myprops
dim $emp
$myprops = "Name", "ID", "Number"
$emp = createobject("kixStuff.kixStruct")
$emp.addProps($myprops)
$employeeStruct = $emp
endfunction

My problem, right now at least, is that the addProps method in the vb class doesn't seem to understand what kix is passing it. I'm new VB, so I hope someone more experienced may be able to spot what's wrong. And any other suggestions, shortcuts or Criticisms are welcome

Keep in mind I'm just playing around so the dll, as of right now, is not at all robust.
_________________________
Eric

Top
#99093 - 2003-03-05 04:52 AM Re: Off Topic - VB and ActiveX Dlls
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Giving your code a shot right now. However, noticed you have a typo in your code:

Public Sub addProps(props() As Variant)
If Not delcared Then

not sure if this is what is causing the problem.

-Shawn

Top
#99094 - 2003-03-05 05:00 AM Re: Off Topic - VB and ActiveX Dlls
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Shawn,

Actually, 'declared' is a private boolean in the class. Is that a keyword in Visual Basic?

-Eric
_________________________
Eric

Top
#99095 - 2003-03-05 05:15 AM Re: Off Topic - VB and ActiveX Dlls
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just noticed that you spelled Declared as Delcared as well.

Are you having a problem "seeing the strings" inside the component ? Are they showing-up as garbage ?

Top
#99096 - 2003-03-05 05:31 AM Re: Off Topic - VB and ActiveX Dlls
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Yeah, it seems to be garbage. For example, I was trying to see what is sitting the "props" array, so I added a line like "msgbox(props(0))". When I ran the kix script the message box displayed "??".

I wonder if it has anything to do with VB passing the parameter by reference as default. Maybe I'll try changing it to byval. But then again, it's an array. I'm going to sleep.

BTW, thanks for pointing out the spelling error. I need to start using single-character variable names.

[ 05. March 2003, 05:32: Message edited by: maciep ]
_________________________
Eric

Top
#99097 - 2003-03-05 05:42 AM Re: Off Topic - VB and ActiveX Dlls
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Its seems to be a non-UNICODE in ARRAYS vs MULTIBYTE thingy ... not too sure why kixtart ( or visual basic) (seems) to be passing data as unicode for strings and non-unicode for strings in arrays, not a VB expert either but give this modifed version of the AddProps a shot:

code:
'add properties to the struct
Public Sub addProps(props As Variant)
If Not declared Then
ReDim propertyNames(LBound(props) To UBound(props)) As Variant
ReDim propertyValues(LBound(props) To UBound(props)) As Variant
For i = 0 To UBound(props)
propertyNames(i) = StrConv(props(i), vbUnicode)
Next
declared = True
End If
End Sub

-Shawn

[ 05. March 2003, 05:47: Message edited by: Shawn ]

Top
#99098 - 2003-03-05 05:54 AM Re: Off Topic - VB and ActiveX Dlls
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Shawn,

You are my hero. It's working like a charm. Thanks for your help.

-Eric
_________________________
Eric

Top
#99099 - 2003-03-05 10:38 PM Re: Off Topic - VB and ActiveX Dlls
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I have also created a class called "kixList", which is just basically encapsulates the collection object in VB. Here is a sample of what kind of scripts can be written

code:
$list = createobject("kixStuff.kixList")
for $j = 1 to 10
? "Enter Name: "
gets $name
? "Enter ID: "
gets $id

$e = employeeStruct()
$ = $e.setProperty("Name", $name)
$ = $e.setProperty("ID", $id)
$list.addItem($e)
Next

Cls
at(1, 5) "Name"
at(1, 15) "ID"
for $j = 1 to $list.getLength()
at($j+2, 5) $list.getItem($j).getProperty("Name")
at($j+2, 15) $list.getItem($j).getProperty("ID")
Next
exit

Function employeeStruct()
dim $myprops
dim $emp
$myprops = "Name", "ID"
$emp = createobject("kixStuff.kixStruct")
$emp.addProps($myprops)
$employeeStruct = $emp
endfunction

Not a real-world example, but should show you what can be done. The script just creates a list of 10 "employees". The "employeeStruct()" function is one way to create a psuedo-structure.

I'm trying to think of more classes I can add to the dll. Any ideas are welcome.
_________________________
Eric

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 823 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.071 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org