URGENT : Picking a Picture

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    URGENT : Picking a Picture

    Hello all,
    I have a main folder name IMAGES and have sub folders of that name A,B,C,.....,Z.
    And the sub folders contain images with name like in Folder A : Apple, Anchor etc and in B : Ball, Bear, Bat

    I have 4 Image controls.

    Now i want that when ever i write a letter in a text box it automatically put a random picture from sub folder. Like if i write G then it goes to folder G and then fetch a random picture and load that in one of the image control.That one image control in which the picture has to be loaded also selected randomly. And in other 3 image controls from random folders random pictures will be loaded. I m also trying this but always my code is getting long and typical so i want a short way to solve this problem.

    Give me Logics, Code or any idea to do this task.

    Thanx
    >> ALI <<
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Hi ali
    What version of vb are you using
    my advice is to use a random integer function that returns a rounded value
    Between 1 and the count of files in the folder...

    Comment

    • Ali Rizwan
      Banned
      Contributor
      • Aug 2007
      • 931

      #3
      I m using VB6.

      I have used this code to generate Alphabet ASCII code:

      Code:
      Private Sub GNO()
      
      '===============================
      
              Randomize
                  lblP(0).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
              
                 
      '===============================
          
              Randomize
                  lblP(1).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  
              If lblP(1).Caption = lblP(0).Caption Then
                  
                  Do While Not lblP(1).Caption = lblP(0).Caption
                      Randomize
                          lblP(1).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
              
              End If
                      
      '===============================
              
              Randomize
                  lblP(2).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  
              If lblP(2).Caption = lblP(0).Caption Then
                  
                  Do While Not lblP(2).Caption = lblP(0).Caption
                      Randomize
                          lblP(2).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
                  
              End If
                  
              If lblP(2).Caption = lblP(1).Caption Then
                  
                  Do While Not lblP(2).Caption = lblP(1).Caption
                      Randomize
                          lblP(2).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
                      
              End If
                      
              
              
      '==============================
      
              Randomize
                  lblP(3).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  
              If lblP(3).Caption = lblP(0).Caption Then
                  
                  Do While Not lblP(3).Caption = lblP(0).Caption
                      Randomize
                          lblP(3).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
                  
              End If
                  
              If lblP(3).Caption = lblP(1).Caption Then
                  
                  Do While Not lblP(3).Caption = lblP(1).Caption
                      Randomize
                          lblP(3).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
                      
              End If
                  
              If lblP(3).Caption = lblP(2).Caption Then
                  
                  Do While Not lblP(3).Caption = lblP(2).Caption
                      Randomize
                          lblP(3).Caption = Int((25 - 1 + 1) * Rnd + 1) + 64
                  Loop
                      
              End If
                      
                              
      End Sub
      But the problem is that the alphabets are some time are same in boxes.
      I want that every time in every box of four boxes or labels there is a different alphabet and is selected randomly.

      And one thing more how can i convert that ASCII code to alphabets??

      Thanx
      >> ALI <<

      Comment

      Working...