Results 1 to 2 of 2

Thread: this is interesting....

Threaded View

  1. #1

    Thread Starter
    Member ariel_au's Avatar
    Join Date
    Mar 2001
    Posts
    48
    well, the following code is interesting, all u need is a folder that contains pictures and named the pics as
    pic1, pic2, pic3, etc.... and run the program.
    also, u must have a imagebox named "imgControl" with index property 0.
    now, my problem is dealing with the random function. i wanted pics of the same to be appeared only twice.
    i do not allow pics of the same to be appeared once or more then twice. see code below: (especially the random function).
    how can i solve that?

    Code:
    Option Explicit
    
    ' Global variables hold the total number of columns and rows
    Private TotalCols As Integer
    Private TotalRows As Integer
    '-----------------------------------------------------------------------------------------
    Private Sub Form_Load()
        ' You must have an image on the form with the following properties:
        ' .Name = imgControl
        ' .Index = 0
        ' .Visible = False
        ' .Strech = True
        ' Set the picture property to something (a bitmap, icon, etc.)
        
        TotalCols = InputBox("How many columns do you want?", "Set Columns", "4")
        TotalRows = InputBox("How many rows do you want?", "Set Rows", "4")
        
        Call LoadImagesOnForm
    End Sub
    '--------------------------------------------------------------------------------------
    Private Sub LoadImagesOnForm()
        Dim ImgCount As Integer
        Dim RowCount As Integer
        Dim ColCount As Integer
        Dim FrmScalHghtDiff As Integer
        Dim FrmScalWdthDiff As Integer
    
        Dim i As Integer, num As Integer, k As Integer
        Dim filepath As String
            
        With Me
            ' Get the difference between (Form1.Height and Form1.ScaleHeight)
            ' and (Form1.Width and Form1.ScaleWidth) for use in resizing form
            FrmScalHghtDiff = .Height - .ScaleHeight
            FrmScalWdthDiff = .Width - .ScaleWidth
            
            ' Set width and height of form so that it resizes to the
            ' number of images the user requested to display
            .Height = (imgControl(0).Height * TotalRows) + FrmScalHghtDiff
            .Width = (imgControl(0).Width * TotalCols) + FrmScalWdthDiff
        
        ' These loops load images by rows first, then columns, like this:
        ' 1 2 3
        ' 4 5 6
        ' 7 8 9
        For RowCount = 1 To TotalRows
            For ColCount = 1 To TotalCols
                ImgCount = ImgCount + 1
                
                Load imgControl(ImgCount)
    '-----------------------------------------------------------
                Randomize Timer    'here is the problem...
                k = TotalRows * TotalCols
                num = 1 + Int(Rnd * k)
                filepath = "C:\Unzipped Files\memory2\Icons" & "\im" & num & ".ico"
                imgControl(ImgCount).Picture = LoadPicture(filepath)
    '------------------------------------------------------------
                With imgControl(ImgCount)
                    .Move (ColCount - 1) * imgControl(0).Width, _
                          (RowCount - 1) * imgControl(0).Height
                
                   
                    .Visible = True
                End With ' imgControl(ImgCount)
            Next ' ColCount
        Next ' RowCount
        
    
    End Sub
    Last edited by ariel_au; Apr 1st, 2001 at 02:08 AM.

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