Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

VB6 Loadpicture Problem/String Problem

loadpicture() vb6 code

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1 McHugh75

McHugh75

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts

Posted 06 March 2013 - 07:41 AM

I'm trying to output a picture to an imagebox. This is my code

path = "E:\gallows" & Str(lives) & ".jpg"
MsgBox (path)
imggallows.Picture = LoadPicture(path)

As you can see, I'm trying to concatenate a string and then use that string to loadpicture(). I've realized that my problem is that there should be an extra set of quotes around path. When the messagebox comes out, it says "E:\gallows2.jpg" as it should, but what I need in the third line of code is imggallows.picture = loadpicture(""path"") but obviously that doesn't work. I think this truly is a string problem.



#2 zeroGiven

zeroGiven

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 06 March 2013 - 08:22 AM

have you tried imggallows.Picture = LoadPicture(""" & path & """)

 

Don't have vb6 installed to try it out but you should be able to concatenate them onto the string variable.

 

Also,

  • path = "E:\gallows" & Str(lives) & ".jpg" appears to be missing a backslash after gallows. Unless of course your filenames are gallows{somenumber}.jpg

Edited by zeroGiven, 06 March 2013 - 08:24 AM.


#3 McHugh75

McHugh75

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts

Posted 06 March 2013 - 08:31 AM

I just tried

imggallows.Picture = LoadPicture(""" & path & """)

and it gave me a "path/file access" error. And yes, my file actually is "E:\gallows(#here).jpg".



#4 zeroGiven

zeroGiven

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 06 March 2013 - 08:37 AM

I might have the wrong number of quotes for it to wrap your string. I think it's 4 on each side of the path

 

However, I'm not sure that's the issue. If the path does not have any spaces, I don't think it's an issue to just pass the string without enclosing it in quotes.

 

 

Can you manually browse to E:\{a picture} in the image property and set it for testing purposes? I just want to make sure E is indeed accessible.


Edited by zeroGiven, 06 March 2013 - 08:40 AM.


#5 McHugh75

McHugh75

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts

Posted 06 March 2013 - 09:04 AM

The E drive is accessible. I am also able to explicitly write imggallows.Picture = LoadPicture("E:\gallows1.jpg") and it works. It seems that once I try using a variable everything crumbles. BTW, I have 7 imggallows(1-7) and I do increment lives so a new picture should appear each time.


Edited by McHugh75, 06 March 2013 - 09:16 AM.


#6 zeroGiven

zeroGiven

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 06 March 2013 - 09:16 AM

hmmm, doesn't make sense. Your code should work.

 

The only other thing I could think to try is to debug.print the built string (path) and then copy that and paste it into the LoadPicture method (inside quotes) and make sure there's not some issue with a space or something that isn't readily apparent.

 

Another thing for testing is instead of ...& str(Lives) & ... try ...& "1" & ... and see if we can narrow it down to something in the string conversion.



#7 McHugh75

McHugh75

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts

Posted 06 March 2013 - 09:40 AM

You're right. It doesn't make sense, and I've been wrapping my brain all morning long. I'm about ready to just brute force it and right out an if test with 7 possibilities. Also, I'd lied before. I'm actually running this on vba but that shouldn't really matter, should it?



#8 zeroGiven

zeroGiven

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 06 March 2013 - 10:48 AM

Well, at first I was going to say I wouldn't think so but...

 

Just so you don't think you're going crazy, I just created a VBA form and image and button and I can't get it to work either.

 

I keep getting file not found even though everything checks out.

 

I'm going to play around with it. I'll keep you updated.

 

 

LOL and 3 seconds later!!!

 

OK, change str(Lives) to CStr(Lives)



I just looked it up, Str() places a leading space for a positive number so that a negative number will have the same length.


Edited by zeroGiven, 06 March 2013 - 10:45 AM.


#9 McHugh75

McHugh75

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts

Posted 06 March 2013 - 01:55 PM

HAHAHA Wow! Thanks man, your awesome. I literally never would have figured that one out. It's actually moments like these that I think that VB is too high level of a language because it attempts to do too much for you. Once again, Thank You. I owe you one.