Results 1 to 11 of 11

Thread: This is (BLEEP)'ed up!

  1. #1
    Guest

    Angry

    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.

  2. #2

  3. #3
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post 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

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    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!

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    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...

  6. #6
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Unhappy sorry

    I bow my head and appologize.

    Now I know better.

    Appearantly you can pass an array as argument, although I have never done that without making the argument an variant.

    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Question

    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!)

  8. #8
    Guest

    "£&^%%*£( 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 !!!!!!!???????

  9. #9

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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!)

  11. #11
    Guest
    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
  •  



Click Here to Expand Forum to Full Width