View Single Post
 
Old 08-11-2012, 08:47 AM
JohnWilson JohnWilson is offline Windows 7 64bit Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,913
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

"I would have to create seperate Modules in the VBA window of the presentation?"

Probably not. In 2010 you can name each shape in the selection pane (from the HOME Tab > Select on the right)say you named them
Current
totalResistance etc

Code:
Sub UpdateRandomNumber()
Dim Randval As Long
Dim current As Single
Dim voltDrop1 As Single
Dim voltDrop2 As Single
Dim ResTotal As Single
Dim osld As Slide
Randval = Random(1000, 10)
ResTotal = Randval + 100
current = 120 / ResTotal
voltDrop1 = current * Randval
voltDrop2 = current * 100
Set osld = SlideShowWindows(1).View.Slide 'The current slide
osld.Shapes("Current").TextFrame.TextRange = "The current is = " & CStr(current)
osld.Shapes("totalResistance").TextFrame.TextRange = "The total resistance is = " & CStr(ResTotal)
'etc
End Sub

Function Random(High As Long, Low As Long) As Long
Randomize
Random = Int((High - (Low - 1)) * Rnd) + Low
End Function
Few notes since you like learning

I used the type SINGLE for my variables. This is just in case you had decimal results. In your case I don't think that's possible and you could use LONG.
osld is an OBJECT variable (in this case a slide) With object variables you must use the SET word you cannot say

osld=SlideShowWindows(1).View.Slide
Cstr converts a number to text PowerPoint will usually do this for you and many people regard the Cstr as not needed. I would always use it. I don't trust usually (well not usually)
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote