Results 1 to 22 of 22

Thread: VB6 Image Puzzle shuffling

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    168

    VB6 Image Puzzle shuffling

    With the help of friends in this here Forum , l have made a Image Puzzle which works just fine .

    Have been trying for the last couple of days to find code for shuffling the images and move them aroung afterwards
    without success . All there is as code in the web for shuffling refers to numbers and things , not images .

    Could someone share his expertise

    Thanks in advance

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    Your original posts were split off into its own thread yesterday.
    Unfortunately, you continued to piggyback on the other thread, so probably didn't see what more was posted in your original thread yesterday.

    I posted a quick implementation of what I described in that thread in the following post, including shuffling of the puzzle.
    I haven't looked at your implementation, as I'm not allowed to download it at work and I didn't get back to it the other thread while I was at home.

    My implementation...
    http://www.vbforums.com/showthread.p...=1#post5387213

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    168

    Re: VB6 Image Puzzle shuffling

    Good Day passel,

    For some reason or another , l couldn't get in that thread or some of the posts weren't there , but l managed to see your implementation , and downloaded
    the zip . l added the code and it runs OK , and although the images seem to shuffle , they all gather in the upper-left corner one on top of the other ad the grid
    disappears . l am still trying to figure out why .

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    I assume if you run my program itself, it works fine?

    If they gather at the top corner, it is possible you have a scaling difference, i.e. one container is using pixels, and the other twips.
    My code has everything set to pixels scalemode, so the position calculation I had was hardcoded for pixels values.
    If you added some of my code to yours, perhaps you need to change the positioning logic to be more generic, or adapted to the scale you're using.

    Actually, since my shuffling just simulated clicking on tiles, and the moving code should move the tiles, if your code was already moving tiles based on which tile you clicked on, then the scaling shouldn't matter because it wasn't part of the shuffling logic itself.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    168

    Re: VB6 Image Puzzle shuffling

    The first leg of the program (populating the cells) runs fine . Picture1-the original image- is in pixels , the tiles are in twips. Now if l change the tiles to pixels
    a very small image of the original appears in tile(0) , the rest are empty .
    On clicking Command1 , some kind of shuffling takes place and like l said , all images are gathered in the upper-left corner of the screen , not the grid
    which is invisible .Also nothing happens on clicking a tile.
    Thanks for bothering and please easy on terminology , l started VB6 a few months ago .

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    Its still not clear to me.
    Are you saying my project (you chose my .vbp file to load in the IDE), is not shuffling the tiles correctly, i.e. you drag and drop a picture on the picturebox, then select scramble and the images end up in the corner?

    Or are you saying you've copy my code into your project, or another project, and it isn't working?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    168

    Re: VB6 Image Puzzle shuffling

    No , l merely copied the code into the previous code you suggested . The project is just your code , nothing else .

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    When you unzipped the attached file, you should have had two files, the .vbp file and the .frm file.
    If .vbp is associated with VB6, then double clicking on that file should have opened up the IDE with the .frm file loaded. You should see the form and can look at the code.

    The frm file has different settings from the IDE in it, which wouldn't be present if you just used the code I wrote. You need the IDE generated code as well. The way the pictureboxes are nested in the containers is also defined in the .frm file.

    If you run the program from the IDE, and drag and drop a jpg file on the picturebox, you should see the tiles in the window. Clicking the scramble button should shuffle those around.

    p.s. I also later added a checkbox, which if you check it prints the tile number (1 to 24) on the tiles, which makes it much easier to determine where the boxes need to go. Unchecking the checkbox, of course removes the numbers. Also, I added that once you've solved the puzzle, the tiles are hidden, showing the full image with out the tile lines and with the "hole" filled in.
    Last edited by passel; May 14th, 2019 at 12:12 PM.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    168

    Re: VB6 Image Puzzle shuffling

    l don't seem to be getting anywhere . " Run the program from the IDE ??? "
    From what l could understand
    l opened the zip file frm and all , l put a jpg image in Picture1. l could see the white tiles . l run the .vbp from there
    There two buttons Peek and Scrable . Clicked on Peek and when the picture1 and the tiles appeared presumably in place without covering the
    whole of picture1 , l clicked on Scrable and one(1) tile appeared with the part of picture1 , and then clicked it again an another tile appeared .
    Thats is how l can describe as to what l see . Confused as hell .

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    The IDE is the Integrated Development Environment.
    That is what you're using when you develop VB6 code.
    You can either double click on the .vbp file, which should open the VB6 IDE with the project loaded.
    Or you can start the IDE by selecting VB6.exe, then select to Open a project and select the .vbp file.
    You would then run the program, you don't load a picture in the picturebox.

    Once the program is running, Open Windows explorer and find a .jpg, or bmp, or .gif file (or other files that VB6 supports, e.g. VB6 doesn't support .png files natively).
    Once you find a file in the Windows explorer, if you click and drag it over to the running program, when the mouse is over the picturebox the cursor should change to indicate you can drop on the window. Release the mouse to "drop" the file you're dragging and it should be loaded into the picturebox, and the tiles loaded and shown in the picturebox.

    You should then be able to click scramble to see the tiles scrambled.
    Once you have the tiles showing, if you want to load a different picture, you have to start the program over, at this point.
    (technically you can select "peek", and if you're quick enough, drag another picture over while the peek is active to switch the picture).

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    Quote Originally Posted by vbgeobas View Post
    .., l clicked on Scrable and one(1) tile appeared with the part of picture1 , and then clicked it again an another tile appeared .
    Thats is how l can describe as to what l see . Confused as hell .
    I can see how that would be confusing.

    What I think is happening is because you didn't drop a picture on the picturebox when running, the loading and scaling never happens. When you click on Peek, you're looking at picture1 which has whatever picture you preloaded it in, and after the peek period, all the tiles are shown (along with Picture2) and since the tiles weren't loaded, they are all blank. You only see one small square of the image, because that is the missing tile, i.e. the hole, so your seeing the picture "below" the hole.

    When you scramble the image, or click on the tiles, the hole moves to different places, so you see different parts of the underlying image, but only one tile size piece.

    From the original post...
    ...rather than add code to have the user type in a filename, or add code to process a file selection dialog, I just accept a drag and drop from windows explorer, to drop a file on the picturebox. There are no safety checks done, so if the file is not something the LoadPicture can convert to a picture, I'm sure the program will crash.
    Perhaps you didn't understand what drag and drop from windows explorer meant. Hopefully, now you do.

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    @passel...I found all this thread mixup confusing, but I thought I'd give your little sample program a go. I got it from Post #7 from the thread from yesterday.

    I simply downloaded your PuzzleShuffle.zip, extracted the two files to a new directory and opened your project file. I ran it (i see your two buttons and the 'white' picturebox). I then opened Windows Explorer, grabbed a .jpg file, and attempted to drop it onto your picturebox (picture1---the 'white' one (and the only one I see before clicking on either of your two command buttons.)) I do not get an icon allowing me to drop the .jpg onto the pb...all I see is the Circle/Slash icon, indicating one can't move/copy a file to it. So, what am "I" missing? Something from some previous thread? I made absolutely no changes to your little project.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    If you're seeing white, probably the tiles are already showing. Either of the buttons, if pressed would cause that.
    I should have just enabled OLE Drag Droping on all the pictureboxes, but didn't think of it at the time.
    If you start the program, and then drag and drop it should work.
    I can't download the zip from the forum to test for myself, not allowed from work, but I tested the zip I submitted yesterday again, by copying it to a fresh directory, and it works.

    I guess I could upload a more foolproof version. I added a couple of useful things, i.e. tagging the tiles with numbers to make it much easier to reassemble the picture, and removing the times when you solve it, so you can drag another picture on top of the old picture to change it out.

    p.s. I just tested it, and what you described doesn't seem to be the case. If the picturebox is just the big white one, then that should be the one to be dropped on.
    If after you do a fresh start, you select peek, you get a black background (picture2) with all the tiles scattered in their initial position. You can't drag and drop in that case, even though on my machine is shows you can drop on the black areas (picturebox2), because OLE DragDrop was set to manual mode on that picturebox, like it should be on Picture1 because I copied one to make the other, I believe.

    Maybe I'll log off my connection to work, and see if I can download the zip if I'm not connected to the work network, and see if it works for me. It sounds like maybe OLEDragMode and OLEDropMode are not set to manual for picturebox1 for some reason.
    Unless there is some OS reason for OLEDragDrop not to work for VB6 on some systems.
    Last edited by passel; May 14th, 2019 at 05:54 PM.

  14. #14
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    Well, am using Windows 10, 64 Bit. I run the program...I get this:

    Attachment 168427

    I try to drag ANY jpg file to the white area (Picture1) and get the circle with the slash through it...does not drop the image.

    Then, I click on Command1 (Scramble)...I see no changes as I suspect this is just, er, excuse me, scrambling the tiles (all hidden).

    Then I click on command2 (Peek) and get this:

    Attachment 168431

    Didn't change any of your code, Passel. I see the properties, OLEDragMode and OLEDropMode are 0-Manual and 0-None, respectively.

    At NO time can I drag the jpg to the (white) picturebox (I know it is supposed to be done first, but can't do it there, so tried after clicking each of the command buttons.) I'm missing something.

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    This is the code in the zipped vbp file:

    Code:
    Option Explicit
    
    Private PeekCountDown As Integer
    Private Matrix(4, 4) As Integer
    
    
    Private holeX As Integer, holeY As Integer
    
    
    Private Sub Command1_Click()
     'Scramble
     
      Dim i As Integer
      Dim horizontal As Boolean
      Dim x As Integer, y As Integer
      
      For i = 1 To 100   'do 100 random clicks to scramble the puzzle
        horizontal = Not horizontal
        If horizontal Then
          y = holeY
          x = (holeX + Int(Rnd * 4) + 1) Mod 5
          tileClick x, y
        Else
          x = holeX
          y = (holeY + Int(Rnd * 4) + 1) Mod 5
          tileClick x, y
        End If
      Next
    End Sub
    
    
    Private Sub tileClick(x As Integer, y As Integer)
      Dim inc As Integer
      
      If x = holeX Then
        If y > holeY Then
          inc = 1
        ElseIf y < holeY Then
          inc = -1
        End If
        Do While holeY <> y
          Matrix(x, holeY) = Matrix(x, holeY + inc)
          holeY = holeY + inc
          Matrix(holeX, holeY) = 24  'the 25th tile (tile 24) should not be visible so is the hole
          DrawMatrix
        Loop
        
      ElseIf y = holeY Then
        If x > holeX Then
          inc = 1
        ElseIf x < holeX Then
          inc = -1
        End If
        Do While holeX <> x
          Matrix(holeX, y) = Matrix(holeX + inc, y)
          holeX = holeX + inc
          Matrix(holeX, holeY) = 24  'the 25th tile (tile 24) should not be visible so is the hole
          DrawMatrix
        Loop
        
      End If
    End Sub
    
    
    Private Sub Command2_Click()
      Picture2.Visible = False
      PeekCountDown = 100
    End Sub
    
    
    Private Sub Form_Load()
      Randomize
      Timer1.Interval = 15
      Timer1.Enabled = True
      Picture1.AutoRedraw = True
      Dim x As Integer, y As Integer
      Dim idx As Integer
      For y = 0 To 4
        For x = 0 To 4
          Matrix(x, y) = idx
          idx = idx + 1
        Next
      Next
      holeX = 4: holeY = 4
    
    
    End Sub
    
    
    Private Sub picTile_Click(Index As Integer)
      Dim x As Integer, y As Integer
      Dim px As Integer, py As Integer
      
      For x = 0 To 4
        For y = 0 To 4
          If Matrix(x, y) = Index Then
            px = x: py = y
          End If
        Next
      Next
      tileClick px, py
    End Sub
    
    
    Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
      
      Set HiddenPicBox.Picture = LoadPicture(Data.Files(1))
      With HiddenPicBox
        Picture1.PaintPicture .Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, 0, 0, .ScaleWidth, .ScaleHeight, vbSrcCopy
      End With
      
      Dim xSize As Integer, ySize As Integer
      xSize = 100
      ySize = 100
    
    
      Dim picIdx As Integer
      Dim YOffset As Integer, XOffset As Integer
      
      For y = 0 To 4
        YOffset = y * ySize
        For x = 0 To 4
          XOffset = x * xSize
          picTile(picIdx).PaintPicture Picture1.Image, 0, 0, xSize, ySize, XOffset, YOffset, xSize, ySize
          picTile(picIdx).Line (0, 0)-(99, 99), vbBlack, B  'draw blackline around edge
          picIdx = picIdx + 1  'paint the next portion in the next tile
        Next
      Next
      DrawMatrix
      Picture2.Visible = True
    End Sub
    
    
    Private Sub DrawMatrix()
      Dim x As Integer, y As Integer
      For y = 0 To 4
        For x = 0 To 4
          picTile(Matrix(x, y)).Left = x * 100
          picTile(Matrix(x, y)).Top = y * 100
        Next
      Next
    End Sub
    
    
    Private Sub Timer1_Timer()
      If PeekCountDown > 0 Then
        PeekCountDown = PeekCountDown - 1
        If PeekCountDown = 0 Then
          Picture2.Visible = True
        End If
      End If
    End Sub

  16. #16
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    @Passel...i responded to your PM...get the circle/slash in the the test project both times.

    (FYI others: Passel suggested I start a completely new project and attempt to drag-drop an image file to the form, first with nothing added to the project, then with "Form1.OLEDragMOde = 1" in Form_Load.)

  17. #17
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    In addition (after Googling some more), I attempted this (with Form1's OLEDragMode set to 1).

    Code:
    PrivateSub Form_OLEDragDrop(Data As DataObject, Effect AsLong, Button AsInteger, Shift AsInteger, X AsSingle, Y AsSingle)Dim intFile AsInteger
      With Data
        For intFile =1To.Files.Count
          Print Data.Files.Item(intFile)
        Next intFile
      EndWith'DataEndSub
    Selected three text files from windows explorer and 'dragged' them to the form (in a new Project)...still get that dreaded circle/slash. I am QUITE certain I have dragged/dropped files from windows explorer in the past on one or two projects (one of which I just tried and it 'failed' as well). So not certain if it is a Windows 10 thing (current version: 1803, OS build 17134.706), or something completely else. Because I get the circle.slash, the OLEDragDrop sub is never entered (in any of the testing the last couple of days).

  18. #18
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    Ok. I get a drop target indication with that test, so something must be different in the way your system works compared to the ones I've used so far. That isn't entirely unexpected with Windows. I've often found things that work fine on version of windows, only to fail horribly on another.

    I guess if you're curious to see the program in action, you'll need to load a picture into the hidden picturebox at some point in the program in place of the OLEDragDrop event, executing the rest of the code in that event as well to set things up.

    Sorry about that. It seemed like a convenient short cut for me, but if I can't count on it, or understand why it is failing, I guess I'll have to bite the bullet and use a file selection dialog in my examples when needed.

  19. #19
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    434

    Re: VB6 Image Puzzle shuffling

    Drag/drop does not work on an app "Run as Admin". Could that be what you're seeing? I know it's gotten me in the past. (My VB6 IDE is setup to "Run As Admin" so drag and drop features in my app don't work and can't be tested in the IDE. I need to compile my app and test the compiled EXE to test these features.)

    This is an intentional Windows security feature.

    https://blogs.msdn.microsoft.com/pat...trol-and-uipi/

  20. #20
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Image Puzzle shuffling

    Since I had already added some extra feature (primarily allowing a number in the upper left of the tile to help with solving the puzzle), I went ahead and added a Directory List control and File List control to the form as well, so you could choose a file using those if drag and drop don't work for you. I'll post that version.

    If you check the Numbers checkbox and hit scramble, then you'll be able to sort the tiles even if you didn't load a picture because the numbers are there to identify the tiles.
    Attached Files Attached Files

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    @ AAraya

    Hmmm....Ya learn something new every day! Simply amazing how MS sneaks in those little gotchas. DOES work fine in the EXE mode.

    Thanks AAraya

    Sam

  22. #22
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: VB6 Image Puzzle shuffling

    Quote Originally Posted by AAraya View Post
    Drag/drop does not work on an app "Run as Admin". Could that be what you're seeing? I know it's gotten me in the past. (My VB6 IDE is setup to "Run As Admin" so drag and drop features in my app don't work and can't be tested in the IDE. I need to compile my app and test the compiled EXE to test these features.)

    This is an intentional Windows security feature.

    https://blogs.msdn.microsoft.com/pat...trol-and-uipi/

    This post is just a test (have had issues with the site)---please ignore

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