#99092 - 2003-03-05 04:15 AM
Off Topic - VB and ActiveX Dlls
|
maciep
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
|
|
|
|
#99097 - 2003-03-05 05:42 AM
Re: Off Topic - VB and ActiveX Dlls
|
Shawn
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 735 anonymous users online.
|
|
|