Im struggling with a project that uses VB. Im working with some code i found online as its proven to work (as a base point).

First, when i load the source in my VB 5.0, I get this message:

"The Project File PICCALC.VBP contains invalid key 'Retained'. -- Continue Loading Project?"

I have no other option but continue if i want to work with the source. I have no clue what this error is, and may be part of my bigger problem.

The source is rather small. It a calculator, that takes 6 bytes from a form, and sends them via USB to my usb hardware device, where it will sum it up and return the sum to the PC. Before you give up on me, I can say the USB chip works! The source comes with an already compiled EXE and it works perfectly. Only if I want to modify the vb source im having problems getting it to compile.

I have installed the OCX control that it uses. And have narrowed down the problem a bit. The object is called HIDComm and all functions that return a "SafeArray" data type is were I hit the wall. It appears that while VB implicitly uses safearrays for all its array work, it doesn understand the type itself??? Good going M$ :rolleyes: . The fucntion:

HIDComm1.ReadFrom() returns a SafeArray type (as registerd in the OCX) but VB continously spitts out this error to me:

"Compile Error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic"

I can say that this source was written on VB6.0 but I would think that safe array types are still ok in any version.

The Inteface is defined in the OCX as:

[] SafeArray ReadFrom ( Size:Ptr I4 )

To me this is too dumb for VB to behave like this. Its not that my CPU doesnt have properly installed controls. Its does, and the EXE that comes with this source proves all is working properly. So why i can't 'recompile' and run the same source, without modification, is beyond me. To make matters worse is I cant seem to find a straight answer online using google and "Visual Basic 5.0 SafeArray". They all say it should work, but it doesn't?

I would be very greatful if someone can set me straight on what all this jibberish it trying to say to me :rolleyes:

:confused:
:NaN:
:stupid:
Posted on 2004-04-09 11:29:41 by NaN
Oh Ya, here is the source page where I found this working example (at the top is a download link for the OCX control, at the bottom is the download link for the full source for this package):

http://www.alecmcnamara.freeserve.co.uk/piccalc/

And the source in particular (if you dont want to download the project from the page):
Option Explicit




Private Sub Command1_Click()
Dim buffer() As Byte
'define buffer to use for data
'in this configuration you can only send 8 bytes at a time
ReDim buffer(8)

'trap errors if non numeric data in
'text box, or textbox empty
On Error Resume Next

'disable send button until result received
Command1.Enabled = False

'setup buffer to send data to PIC
buffer(0) = Text1.Text
buffer(1) = Text2.Text
buffer(2) = Text3.Text
buffer(3) = Text4.Text
buffer(4) = Text5.Text
buffer(5) = Text6.Text
'write data to PIC
HIDComm1.WriteTo buffer(), 8

[b][color=red]'read data back from PIC
buffer() = HIDComm1.ReadFrom(8)[/color][/b]

'put result in textbox
Text7.Text = 256 * buffer(6) + buffer(7)

'enable send button, result received
Command1.Enabled = True

End Sub


Private Sub Form_Load()
'connect to the USB device as the program starts
HIDComm1.Connect

End Sub

Private Sub Form_Terminate()
'disconnect from the USB device as prgoram ends
HIDComm1.Uninit

End Sub

Private Sub HIDComm1_ConnectSuccess(ByVal Status As Long)
'enable button when device is connected
Command1.Enabled = True
Caption = "Pic Calc - Connected"

End Sub

Private Sub HIDComm1_Disconnected(ByVal Status As Long)
'disable button when device unplugged
Command1.Enabled = False
Caption = "Pic Calc - Disconnected"

End Sub


Private Sub Timer1_Timer()
'try and reconnect PIC
If HIDComm1.Connected = False Then
HIDComm1.Connect
End If

End Sub


I've also tried typecasting with VarPrtArray() but it did nothing as VB doesn recognize it. I copied a Private Declair statement pointing to the DLL that sources this function and it only put be back to the same problem described above :rolleye:
Posted on 2004-04-09 11:31:40 by NaN
According to the "What's new" section in VB6, procedures returning arrays is a new feature of VB6.

If you want to continue using VB5, you will need a DLL (can be OCX) with a wrapper function that returns the array via ByRef arguments.
Posted on 2004-04-09 19:20:03 by tenkey
I never had any luck getting HIDComm to work on my computer... its an old machine, so would have USB 1.0 ports I imagine, and definately runs W98 *first* edition.

I'm running into a wall using other USB tools (also for PIC stuff), so I'm finally forced to get a new machine.

YAHHH! (oops... but the wife will want one too... gosh, gotta buy two systems)
Posted on 2004-04-10 01:48:11 by Ernie
OK, I take it back. I just tried the new (looks to me like a Rev B in the link) HIDComm control and it worked perfectly, even searching out my device. I still have the problem of the write not working quite often ( like 1 out of 10 or so times) but adding a line for validating the new data (and re-sending if not correct) was trivial.

With VB.net out now VB6 should be cheap, huh? Been to a computer show lately? (I believe I just saw VB.net at one for $100 USD)
Posted on 2004-04-10 06:16:28 by Ernie
Na, i would rather convert it all to MASM before i shell out for another version. I paid in full for my VB5.0 and im still trying to get my money's worth out of it :rolleyes:

It would be nice to 'play' with the VB pseudo like code first before it get down in dirty with MASM coding. As well the PicKit has a software example that does compile with VB5.0. So i guess i will have to abandon this control.

The MSDN has some good tech articles on using the communications I/O as well, i think i will write my own object as it appears I can't have my cake and eat it too ;)

Thanks for you help!
Regards,
:NaN:
Posted on 2004-04-12 23:41:01 by NaN
From the IDL, I would guess it's a syntax issue.

Syntax form example:
HIDComm1.WriteTo buffer(), 8
Function, Pointer, Count

Change:
buffer() = HIDComm1.ReadFrom(8)
try a ByRef form:
HIDComm1.ReadFrom buffer(), 8
Function, Pointer, Count

I don't have VB5. So it's all guessing.

Regards, P1 :cool:
Posted on 2004-04-28 17:55:34 by Pone
Or:
Results = HIDComm1.ReadFrom(buffer(), 8)
Or:
Results = HIDComm1.ReadFrom buffer(), 8

Regards, P1 :cool:
Posted on 2004-04-29 08:16:32 by Pone
Thanks for your attempt Pone.

However VB is not budging :rolleyes: (just another reason why I dislike HLL ~ this is trivial in masm because DWORDS are DWORD are DWORDS)
Posted on 2004-04-30 16:43:21 by NaN

Or:
Results = HIDComm1.ReadFrom(buffer(), 8)
Or:
Results = HIDComm1.ReadFrom buffer(), 8
The first statement above is correct syntax, the second is incorrect, as you need to use the brackets if you are going to return anything.

NaN, without looking at the IDL, i would suggest it is a problem with parameter 1 (buffer), maybe it is not being passed correctly, it needs to be ByRef. Try putting the ByRef keyword in front of the parameter, like this:


HIDComm1.ReadFrom ByRef buffer(), 8


Can you post the IDL where this function is defined?
Posted on 2004-05-01 04:25:40 by sluggy
Your correct. Its because the return parameter is a SAFEARRAY type, which visual basic 5 lacks proper support for (dispite the fact that internally it uses this type for its string BSTR arrays :rolleyes: ).

I dont have the IDL off hand, i dont think. I posted the links at the top of the thread where you can download the control if your interested in the control. Im at a point where i simply programmed around this. I have a version that i wrote in MASM that is working better than this control could offer anyways.

I do appreciate everyone's interest is figuring this out however, but Im pretty sure at this point its a lost cause.

Regads,
:NaN:
Posted on 2004-05-01 16:20:39 by NaN