2017-03-27 2 views
0

Je viens de rejoindre et espère apprendre tout ce que je peux ici et contribuer où je peux.Impossible d'afficher les valeurs numériques

J'ai des problèmes majeurs avec les trois dernières sections de mon script VBA. Les correctes, incorrectes et les valeurs de score en pourcentage ne sont pas affichées sur des lames 40 & 41.

La diapositive 42 Je ne peux pas la zone de texte ou l'étiquette pour afficher le nom d'utilisateur, la date et leur score global de pourcentage.

Toute aide sur la diapositive 40 serait super et je peux faire de l'exercice pour le reste.

**Sub shapeTextHappySmile()**strong text** 
Sub ShapeTextSadSmile() 
Sub CertificateBuld()** 


Option Explicit 
Dim UserName As String 
Dim numberCorrect As Integer 
Dim numberIncorrect As Integer 
Dim numberPercentage As Integer 
Dim numberTotal As Integer 

Private Sub CertDate() 
Dim Rdate As Variant 
Rdate = Date 
Rdate = Format((Date), "mmmm dd, yyyy") 
End Sub 

Sub Initialise() 
numberCorrect = 12 
numberIncorrect = 8 
numberPercentage = 58 
numberTotal = 20 
numberTotal = (numberCorrect + numberIncorrect) 
numberCorrect = (numberTotal - numberIncorrect) 
numberIncorrect = (numberTotal - numberCorrect) 
numberPercentage = Round(numberCorrect/numberTotal) * 100 
End Sub 

Sub TakeQuiz() 
UserName = InputBox(Prompt:="Type Your Name! ") 
MsgBox "Welcome To The Academic Online Tutorial Quiz " + UserName, vbApplicationModal, " Academic Online Tutorial Quiz" 
ActivePresentation.SlideShowWindow.View.Next 
End Sub 

Sub Correct() 
numberCorrect = numberCorrect + 1 
MsgBox ("Great well Done! That's the correct answer") 
ActivePresentation.SlideShowWindow.View.Next 
End Sub 

Sub Incorrect() 
numberIncorrect = numberIncorrect + 1 
MsgBox ("Sorry! That was the incorrect answer") 
ActivePresentation.SlideShowWindow.View.Next 
End Sub 

Sub shapeTextHappySmile() 
ActivePresentation.Slides(40).Shapes(Label1).TextFrame.TextRange.Text = 12 
'numberCorrect 
ActivePresentation.Slides(40).Shapes(Label2).TextFrame.TextRange.Text = numberPercentage & "%" 
MsgBox "Great Job, Well done " + "," & "Please print a copy of your completion certificate" 
MsgBox "After printing or saving a copy of your certificate, you can exit the presentation" 
With SlideShowWindows(1).View 
.GotoSlide 42 
End With 
End Sub 

Sub ShapeTextSadSmile() 
ActivePresentation.Slides(41).Shapes("AnsweredIncorrectly").TextFrame.TextRange.Text = numberIncorrect 
ActivePresentation.Slides(41).Shapes("InCorrectPercentage").TextFrame.TextRange.Text = numberPercentage & " %" 
MsgBox "Your score was below 70%, in order to pass the quiz and receive a certificate of completion you need to score 70% or more." 
MsgBox "Please retake the quiz, and good luck" 
With SlideShowWindows(1).View 
.GotoSlide 1 
End With 
' I will add the option of redoing the entire presentation or just the quiz. 
'see slide 19 action buttons 
End Sub 

Sub CertificateBuld() 
MsgBox "Great Job, Well done " + "," & "Plese print a copy of your completion certificate" 
MsgBox "After printing or saving a copy of your certificate, please exit the presentation" 

If numberCorrect >= "14" Then 
ActivePresentation.Slides(42).Shapes(" ABCDEFGHIJKLMN ").TextFrame.TextRange.Text = " ABCDEFGHIJKLMN " 
ActivePresentation.Slides(42).Shapes("Rdate & Percentage").TextFrame.TextRange.Text = " ON " & Rdate & " WITH A SCORE OF " & numberPercentage & " %" 
ActivePresentation.Slides(42).Shapes(UserName).TextFrame.TextRange.Text = UserName 

'OR 

If numberCorrect <= "14" Then 
ActivePresentation.Slides(42).Shapes(8).TextFrame.TextRange.Text = ABCDEFGHIJKLMN " 
ActivePresentation.Slides(42).Shapes(9).TextFrame.TextRange.Text = Rdate & " ON " & Rdate & " WITH A SCORE OF " & numberPercentage & " %" 
ActivePresentation.Slides(42).Shapes(10).TextFrame.TextRange.Text = UserName 
Else 
ActivePresentation.SlideShowWindow.View.Save 
ActivePresentation.SlideShowWindow.View.Exit 
End If 
End Sub 

Répondre

0

Voir en ligne commentaires:

Sub shapeTextHappySmile() 
' This won't work: 
'ActivePresentation.Slides(40).Shapes(Label1).TextFrame.TextRange.Text = 12 
' Shapes have names that are strings, so you need to use .Shapes("Label1") 
' Assuming this is an ActiveX label, you get at its properties a bit 
' differently from regular PPT shapes, starting with: 
' .Shapes("Label1").OLEFormat.Object 
' And for a Label ActiveX control, the property you want is .Caption 
' And finally, Text/Caption properties take a String value so you want to 
' put the 12 in quotes or convert a numeric value to string using Cstr(x) 
' Final version: 

ActivePresentation.Slides(40).Shapes("Label1").OLEFormat.Object.Caption = "12" 

'numberCorrect 

' And make the same changes to this one: 
ActivePresentation.Slides(40).Shapes(Label2).TextFrame.TextRange.Text = numberPercentage & "%" 

' MsgBox "Great Job, Well done " + "," & "Please print a copy of your completion certificate" 

' and I think you probably want to do this instead of the above: 
MsgBox "Great Job, Well done" & ", " & "Please print a copy of your completion certificate" 


MsgBox "After printing or saving a copy of your certificate, you can exit the presentation" 
With SlideShowWindows(1).View 
.GotoSlide 42 
End With 
End Sub 
+0

Merci pour les changements proposés. J'ai été capable de modifier mon script au point où cela fonctionne jusqu'à ce qu'il soit temps d'insérer des variables sélectionnées telles que [nom d'utilisateur, date, pourcentage] sur un formulaire. Sur cette forme j'ai créé des étiquettes pour les trois articles et je ne peux toujours pas les obtenir sur le formulaire. c'est mon nouveau code. Est-ce que j'utilise une étiquette ou une zone de texte pour insérer l'information sur le formulaire sur la diapositive 42. J'espérais que l'information dans le sous Correct() résoudrait mon problème, mais ce n'était pas le cas. De nouvelles idées Je sais que le format de la date est éteint, loin de là. Il ne reste plus d'espace pour mon code. – CBiscuit

+0

Le code dans les commentaires se transforme en un désordre brouillé; Je modifierais votre message d'origine et ajouterais le code là ou commencerais une nouvelle question. Mais en réponse à votre autre question, mes modifications à votre code étaient basées sur l'hypothèse que vous utilisiez un contrôle d'étiquette, où vous utilisez la propriété .Caption pour définir son texte. Si vous passez à un contrôle TextBox, utilisez plutôt sa propriété .Text. –

+0

D'accord, j'essaye tout. J'ai passé la majeure partie de la journée à lire le post VBA sur la façon de faire les choses. jusqu'à ce que je trouve quelque chose qui fonctionne. Je vais commencer un nouveau petit projet. Je ne sais pas quoi utiliser. Je vais me connecter et supprimer mon dernier message sous peu. – CBiscuit