Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2012, 08:47 AM
JohnWilson JohnWilson is offline Randomly generate numbers, Macro? Windows 7 64bit Randomly generate numbers, Macro? 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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to recap data of same numbers Jasa P Word VBA 0 06-28-2012 02:41 AM
Randomly generate numbers, Macro? Formatting changing randomly Franuzz Word 1 07-14-2011 04:12 PM
black text randomly changing to white when run macro G DeBree PowerPoint 0 03-16-2011 09:23 AM
Randomly delayed emails Colinest84 Outlook 1 01-14-2011 02:32 AM
Documents Randomly Corrupting the IT Guy Word 0 02-06-2009 09:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft