View Single Post
 
Old 03-22-2017, 04:49 AM
physicsphilosopher physicsphilosopher is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Posts: 5
physicsphilosopher is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
This looks fun, but it will take some thought how to record who has which version, but something along the lines of the following may help get you started.

Code:
Option Explicit
Private Const sName As String = "Billy|Bobby|John|Susan|Ted"
Private Const sPlace As String = "Cliff|Tower|Bridge"
Private Const sItem As String = "Stone|Rock|Wrench"
Private vName As Variant, vPlace As Variant, vItem As Variant
Private iPlace As Integer, iName As Integer, iItem As Integer
Private iHeight As Integer, iMass As Integer
Private sText As String

Private Function RandomNumber(Lowest As Long, Highest As Long, _
                              Optional Decimals As Integer) As Integer
    If IsMissing(Decimals) Or Decimals = 0 Then
        Randomize
        RandomNumber = Int((Highest + 1 - Lowest) * Rnd + Lowest)
    Else
        Randomize
        RandomNumber = Round((Highest - Lowest) * Rnd + Lowest, Decimals)
    End If
End Function

Sub Macro1()
    vName = Split(sName, "|")
    vPlace = Split(sPlace, "|")
    vItem = Split(sItem, "|")
    iHeight = RandomNumber(1, 50, 0)
    iMass = RandomNumber(1, 5, 0)
    iPlace = RandomNumber(0, UBound(vPlace))
    iName = RandomNumber(0, UBound(vName))
    iItem = RandomNumber(0, UBound(vItem))
    sText = vName(iName) & " dropped a " & vItem(iItem) & " off a " & iHeight & " meter-high " & _
            vPlace(iPlace) & ". The " & vItem(iItem) & " has a mass of " & iMass & " kilograms."
    Selection.TypeText sText
End Sub
Thank you!!! This looks amazing and is way better than what i could of come up with on my own! Was thinking about which version and decided to try adding in code to duplicate the process x times and put it on a new page each time, and number it each time. This way i could have one document that has 130 different versions of the same quiz and just print the document once to get all i'll need for the day. Once i get that working i'm going to get it to add the answers by version number to either the end of the same document or another, whichever i figure out how to do faster.

I'll update again once i make progress. Thanks again for giving me such a solid foundation!!!
Reply With Quote