|
-
Nov 14th, 1999, 11:59 AM
#1
Thread Starter
New Member
I am having trouble randomizing message boxes the code i am currently using does not work so well. can someone give me one that they know with work for vb 3?
i have a list of message boxes to play and i want it to randomly play 1 of them.
can someone help
thanx
-
Nov 14th, 1999, 12:05 PM
#2
Hyperactive Member
could you assign each of the boxes a number and randomize that number and display the message box that corresponds?
-
Nov 14th, 1999, 10:37 PM
#3
What do you mean by "I have a list of message boxes to play...." Does that mean that you have one message box and you want it to show one of several messages? If it is something else, please let me know.
------------------
Marty
-
Nov 14th, 1999, 11:20 PM
#4
Guru
I think I know what you mean... Try this: (I THINK it works in VB3)
Code:
Option Explicit
Private Type MsgBoxTemplate
Prompt As Variant
Buttons As VbMsgBoxStyle ' = VBOkOnly
Title As Variant
HelpFile As Variant
Context As Variant
End Type
Dim m_mbTemplates() As MsgBoxTemplate
Function InBounds(ByVal nIndex As Long) As Boolean
InBounds = (nIndex >= LBound(m_mbTemplates) And nIndex <= UBound(m_mbTemplates))
End Function
Sub SetMsgBoxTemplate(ByVal nIndex As Long, ByVal Prompt, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal Title, Optional ByVal HelpFile, Optional ByVal Context)
If nIndex = UBound(m_mbTemplates) + 1 Then ReDim Preserve m_mbTemplates(1 To nIndex)
If Not InBounds(nIndex) Then Call Err.Raise(Number:=380, Description:="Invalid Template Index.")
With m_mbTemplates(nIndex)
.Prompt = Prompt
.Buttons = Buttons
.Title = Title
.HelpFile = HelpFile
.Context = Context
End With
End Sub
Function ShowMsgBoxFromTemplate(ByVal nIndex As Long) As VbMsgBoxResult
If Not InBounds(nIndex) Then Call Err.Raise(Number:=380, Description:="Invalid Template Index.")
ShowMsgBoxFromTemplate = MsgBox(m_mbTemplates(nIndex).Prompt, m_mbTemplates(nIndex).Buttons, m_mbTemplates(nIndex).Title, m_mbTemplates(nIndex).HelpFile, m_mbTemplates(nIndex).Context)
End Function
Function RandomShowMsgBoxFromTemplate() As VbMsgBoxResult
Call Randomize(Timer)
RandomShowMsgBoxFromTemplate = ShowMsgBoxFromTemplate(Rnd * (UBound(m_mbTemplates) - 1) + LBound(m_mbTemplates))
End Function
Private Sub Form_Load()
Dim I As Long
AutoRedraw = True
' This must be done before using SetMsgBoxTemplate:
ReDim m_mbTemplates(1 To 1)
' Example of how to use the MsgBox templates:
Call SetMsgBoxTemplate(1, "Prompt #1", vbExclamation, "Title #1")
Call SetMsgBoxTemplate(2, "Prompt #2", vbQuestion Or vbYesNo, "Title #2")
Call SetMsgBoxTemplate(3, "Prompt #3", vbCritical Or vbAbortRetryIgnore, "Title #3")
Call SetMsgBoxTemplate(4, "Prompt #4", vbSystemModal Or vbYesNoCancel, "Title #4")
Call SetMsgBoxTemplate(5, "Prompt #5") ' MsgBox #5 is blank except prompt
' Display the MsgBoxes:
For I = 1 To 5
Print "MsgBox #" & I & " result: " & ShowMsgBoxFromTemplate(I)
Next
' Display a random one:
Print "Random MsgBox result: " & RandomShowMsgBoxFromTemplate
' The result is a number. This is what each number means:
' 1 = OK
' 2 = Cancel
' 3 = Abort
' 4 = Retry
' 5 = Ignore
' 6 = Yes
' 7 = No
End Sub
------------------
Yonatan
Teenage Programmer
E-Mail: [email protected]
ICQ: 19552879
AIM: RYoni69
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|