|
-
Jun 28th, 2000, 06:38 PM
#1
the scenario:
I have made an activex control which contains a subroutine.
This subroutine has only one argument, I would like that argument to be defined as an array of longs.
much like:
Code:
Public Sub SetLengths(ByRef Lengths() as long)
looks ok doesn't it?
When I try to call this sub from a command button with the following code:
Code:
Dim MyLens(0 to 5) as long
...
...
MyControl.SetLengths MyLens
I get a type mismatch error (13)
The error is occurring before the subroutine actually comes into effect, so it is actually the calling statement which is a bit ropey somehow!
I have tried changing the way the sub is declared but I sometimes get an error saying "array / UDT expected" (not a quote btw). This is driving me nuts, can anyone tell me what is wrong.
A nice new sports car to who-ever sorts this out.
-
Jun 28th, 2000, 07:03 PM
#2
This might not help you, but when I try to recreate the scenario as a class with SetLengths as a method of the class, it works perfectly.
-
Jun 28th, 2000, 07:06 PM
#3
Hyperactive Member
use variants
If you want to send an array as argument you have to
make the argument an variant.
form 1 with a button:
Private Sub Command1_Click()
Dim intx(1 To 5) As integer
intx(1) = 10
intx(2) = 12
intx(3) = 13
intx(4) = 14
intx(5) = 15
Call Module1.SetLengths(intx)
End Sub
In a module:
Public Sub SetLengths(ByRef Lengths As Variant)
Dim x As Integer
For x = LBound(Lengths) To UBound(Lengths)
MsgBox Lengths(x)
Next x
End Sub
[Edited by onerrorgoto on 06-29-2000 at 08:10 AM]
Onerrorgoto
Dont be to optimistic, the light at the end of the tunnel might be a train
-
Jun 28th, 2000, 07:21 PM
#4
Fanatic Member
WHAT? No you don't. Try it and see.
You CAN pass an array as an argument to a sub or funtion. Try writing your own join fuction, or sorting function to see.
Iain, thats with an i by the way!
-
Jun 28th, 2000, 07:45 PM
#5
Hyperactive Member
Iain is right you can pass any param arrary of any type, why would you constrain a language to only accept variants at their slow pace...
-
Jun 28th, 2000, 08:00 PM
#6
-
Jun 28th, 2000, 08:23 PM
#7
Fanatic Member
I just tried it and this works...
MyControl.SetLengths MyLens
And this works...
Call MyControl.SetLengths(MyLens)
But this doesn't...
MyControl.SetLengths(MyLens)
Maybe you've got that "***** up my program without asking me" option checked!
I get that sometimes. But I drink too much too, which may be the real problem 
This forum replaced the word "*****" with "****" in this post!!!! Censorship!!!, time for a scotch I think
[Edited by Paul282 on 06-29-2000 at 09:25 AM]
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 29th, 2000, 01:19 AM
#8
"£&^%%*£( loops!
Thanks guys, i got that to work!
now i have another problem
Code:
For i = 0 To UBound(Fields) - 1
Fields(i) = Fields(i) & Space(FieldLengths(i) - Len(Fields(i)))
Next i
the fields has elements 0 to 5 each has a string in it, When i run the program i get another f***ing error saying "invalid procedure call or argument".
the variable 'i' is a long value.
i can't find anything wrong with this f***ing for/next loop whatsoever, I think i have been staring at code too much today and i fear i may have a brain hemmorage any second.
ARRRGH what is wrong with this !!!!!!!???????
-
Jun 29th, 2000, 03:21 AM
#9
If Fields(i) is a string, you can't subtract something from it as you are attempting to do with "- Len(Fields(i))"
-
Jun 29th, 2000, 11:35 AM
#10
Fanatic Member
No, he's subtracting from FieldLengths(i) which is assumably and int or long.
Have you tried a watch or locals windows with the break point on the NEXT statement so you can see all the variable in each iteration? looks to me like there's a piece of data in one of the arrays which is too long or short and and maybe passing a negative to the space function.
Use you're debug windows, the imediate window won't tell you enough.
Put a bit more code up and we can test it for you be we'll need some values.
Paul
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 30th, 2000, 05:58 AM
#11
Ahh, the wonders of a good night's kip.
In the test file i was using, i had made up some fields like
aaaaa","bbbbbbbbbbbbb","ccccccccccccccccccccccccccccccccccccccccccc","dddd... etc
After hours of switching back and forth between control project and exe project (you know how it is with Activex development!) i had been cutting-and-pasting a sample of code from a notepad document. Earlier on in the day I had realised that one of the fields was 31 characters long, and I had been initialising the lengths array with 30 every time. DOH!!!
btw, Paul was right about the subtraction thing, the fieldlengths() is indeed a longs array.
Thanks guys, several heads are always better than mine! hehehe, if any of you are interested in testing this rickety lump of code for me than mail me. The Delimited-to-Fixed width now works perfectly (until someone else tries it i expect!). Now all i have to do is get it to go the other way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|