Attribute VB_Name = "KrissToys_rel" 'KrissToys.bas 'by Kris Knigga ' 'This just started as a project to save me some time, but why be 'selfish? So, Kris's Toys is now avalible free to the public. 'Remember to insert a Microsoft Common Dialog Control in a form or else 'an error will occur. Option Explicit 'The RndInt function generates a random integer. Use: ' RndInt(LowNumber, HighNumber) Public Function RndInt(ByVal intLowNumber As Integer, ByVal intHighNumber As Integer) As Integer RndInt = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber) End Function 'The PerfectSquare function checks a number to see if it is a perfect square. Use: ' PerfectSquare(Number) Public Function PerfectSquare(ByVal dblNumber As Double) As Boolean If Sqr(dblNumber) = Int(Sqr(dblNumber)) Then PerfectSquare = True Else PerfectSquare = False End If End Function 'This function is the word-wrap function. Use: ' SetWidth(String, Width) 'where Width is the max width of the string. Public Function SetWidth(Expression As String, Width As Integer) As String Dim sTemp As String sTemp = vbNullString Dim arWords arWords = Split(Expression, Space(1)) Dim iPos As Integer Dim iLen As Integer iLen = 0 For iPos = LBound(arWords) To UBound(arWords) iLen = iLen + Len(arWords(iPos)) sTemp = sTemp & arWords(iPos) & " " If iLen + Len(arWords(iPos)) > Width Then sTemp = sTemp & vbCrLf iLen = 0 End If Next iPos SetWidth = sTemp End Function 'StringPrint is the function that prints strings and has built in word-wrap. Use: ' StringPrint(MessageString, CommonDialog1) 'Just put "CommonDialog1" as the second argument. Public Function StringPrint(ByVal strMessage As String, cmmCommonDialogControl As CommonDialog) Const intSheetWidth As Integer = 75 Dim BeginPage, EndPage, NumCopies, i Dim strPrintFriendlyMessage As String strPrintFriendlyMessage = SetWidth(strMessage, intSheetWidth) If strPrintFriendlyMessage = "" Then MsgBox "Error!" strPrintFriendlyMessage = "Error!" End If cmmCommonDialogControl.CancelError = True cmmCommonDialogControl.ShowPrinter BeginPage = cmmCommonDialogControl.FromPage EndPage = cmmCommonDialogControl.ToPage NumCopies = cmmCommonDialogControl.Copies For i = 1 To NumCopies Printer.Orientation = 1 Printer.FontSize = 10 Printer.Print strPrintFriendlyMessage Printer.EndDoc Next i End Function 'This function, NWStringPrint, is the same as StringPrint except without wordwrap. Use: ' NWStringPrint(MessageString, CommonDialog1) Public Function NWStringPrint(ByVal strMessage As String, cmmCommonDialogControl As CommonDialog) Const intSheetWidth As Integer = 75 Dim BeginPage, EndPage, NumCopies, i Dim strPrintFriendlyMessage As String strPrintFriendlyMessage = strMessage If strPrintFriendlyMessage = "" Then MsgBox "Error!" strPrintFriendlyMessage = "Error!" End If cmmCommonDialogControl.CancelError = True cmmCommonDialogControl.ShowPrinter BeginPage = cmmCommonDialogControl.FromPage EndPage = cmmCommonDialogControl.ToPage NumCopies = cmmCommonDialogControl.Copies For i = 1 To NumCopies Printer.Orientation = 1 Printer.FontSize = 10 Printer.Print strPrintFriendlyMessage Printer.EndDoc Next i End Function 'EvenNumber checks a number to see if it is even. Use: ' EvenNumber(Number) Public Function EvenNumber(ByVal Number As Long) As Boolean If Number Mod 2 <> 0 Then EvenNumber = False Else EvenNumber = True End If End Function