Tools Links Login

Random Picture Generator

This code simply generate a random picture and display. It also teaches beginners about random numbers.

Original Author: Yu Chang

Inputs

Create some pictures and name them as "pic1.jpg, "pic2.jpg", and so on. Enter the LowerBound and UpperBound of the picture number.

Returns

Displays a random picture.

Side Affects

The picture names are static.

Code

Option Explicit
Public Sub FormWinRegPos(pMyForm As Form, Optional pbSave As Boolean)
  'This Procedure will Either Retrieve or Save Form Posn values
  'Best used on Form Load and Unload or QueryUnLoad
  On Error GoTo EH
  
  With pMyForm
    If pbSave Then
      'If Saving then do this...
      'If Form was minimized or Maximized then Closed Need to Save Windowstate
      'THEN... set Back to Normal Or previous non Max or Min State then Save
      'Posn Parameters SaveSetting App.EXEName, .Name, "Top", .Top
      SaveSetting App.EXEName, .Name, "WindowState", .WindowState
      If .WindowState = vbMinimized Or .WindowState = vbMaximized Then
        .WindowState = vbNormal
      End If
      'Save AppName...FrmName...KeyName...Value
      SaveSetting App.EXEName, .Name, "Top", .Top
      SaveSetting App.EXEName, .Name, "Left", .Left
      SaveSetting App.EXEName, .Name, "Height", .Height
      SaveSetting App.EXEName, .Name, "Width", .Width
    Else
      'If Not Saveing Must Be Getting ..
      'Need to ref AppName...FrmName...KeyName (If nothing Stored Use The Exisiting Form value)
      .Top = GetSetting(App.EXEName, .Name, "Top", .Top)
      .Left = GetSetting(App.EXEName, .Name, "Left", .Left)
      .Height = GetSetting(App.EXEName, Name, "Height", .Height)
      .Width = GetSetting(App.EXEName, .Name, "Width", .Width)
      'Be Sure WindowState is set last (Can't Change POSN if vbMinimized Or Maximized
      .WindowState = GetSetting(App.EXEName, .Name, "WindowState", .WindowState)
    End If
  End With
  
  Exit Sub
EH:
  MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description
  
End Sub

Private Sub Form_Load()
  FormWinRegPos Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
  FormWinRegPos Me, True
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 88 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.