Results 1 to 18 of 18

Thread: Why am I getting a type mismatch here!? [resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265

    Question Why am I getting a type mismatch here!? [resolved]

    I'm using this code to display a random advert in a form (either ad1.bmp, ad2.bmp or ad3.bmp) but it keeps failing with a compile error - type mismatch at the last & sign in the code.

    Any ideas why?

    Simon

    Code:
    Private Function RandomInteger(Lowerbound As Integer, Upperbound As Integer) As Integer
        RandomInteger = Int((Upperbound - Lowerbound + 1) * Rnd + Lowerbound)
    End Function
    Code:
    Randomize
    picAdvert.Picture = (App.Path & "/ad" & RandomInteger(1, 3) & ".bmp")
    Last edited by simonp; Jul 20th, 2004 at 02:20 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    which line was the error on?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    picAdvert.Picture = (App.Path & "/ad" & RandomInteger(1, 3) & ".bmp")

    there!

  4. #4

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    would that solve the mismatch?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    Thanks Martin - same problem with the mismatch though

    I can get the random number ok - just doesn't seem to like it in that line

    Simon

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    maybe you should do this...


    VB Code:
    1. dim number as long
    2.  
    3. number = randominteger(1,3)
    4.  
    5. picAdvert.Picture = (App.Path & "\ad" & number & ".bmp")

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    type mismatch in exactly the same place!

    How bizarre?!

    Simon

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    at the point before oppening the app whats the value of the random number?

  10. #10

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    Same problem Martin (tried that before).

    Pino - not sure what you mean there - the random number part works fine (tested with a msgbox)

    SImon

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    Incidently, this works fine:

    Code:
    MsgBox App.Path & "\ad" & RandomInteger(1, 3) & ".bmp"

  13. #13

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    wow - this is driving me crazy!

    Here you go folks.

    Simon

    (attachment deleted - resolved)
    Last edited by simonp; Jul 20th, 2004 at 02:21 PM.

  15. #15
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    done...


    VB Code:
    1. picAdvert.Picture = LoadPicture(App.Path & "/ad" & RandomInteger(1, 3) & ".bmp")


  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    oh what a fool

    I can't believe I missed that!

    Thanks pino

    Simon

  17. #17
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    add resolved to your title .. Please

    edit - you beat me to it

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265
    already done

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