2017-03-27 6 views
0

私はここに参加でき、私ができるところに貢献することを願っています。数字の値を表示できません

私のVBAスクリプトの最後の3つのセクションに大きな問題があります。 スライドに正しく、間違っている、パーセント値が表示されていません40 & 41.

スライド42では、ユーザー名、日付、および全体のパーセンテージスコアを表示するテキストボックスまたはラベルを取得できません。

スライド40についてのヘルプはすばらしく、残りの部分は練習できます。

**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 

答えて

0

コメントをインラインで参照してください。

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

は、提案された変更をお願い致します。 [ユーザー名、日付、パーセンテージ]などの選択した変数をフォームに挿入するときまで、スクリプトを変更することができました。そのフォームで私は3つのアイテムのためのlablesを作成していますが、まだフォーム上にそれらを得ることはできません。これは私の新しいコードです。スライド42のフォームに情報を挿入するには、ラベルやテキストボックスを使用しますか?私は、Correct()サブセクションの情報が私の問題を解決することを期待していましたが、そうしませんでした。新しいアイデア。私は日付の形式がオフになっていることを知っている..私のコードのためのスペースが残っていない。 – CBiscuit

+0

コメント内のコードが混乱してしまいます。元の投稿を編集してそこにコードを追加したり、新しい質問を開始したりします。しかし、あなたの他の質問に答えて、あなたのコードを変更したのは、あなたがテキストを設定するために.Captionプロパティを使うラベルコントロールを使っていたという仮定に基づいていました。 TextBoxコントロールに変更する場合は、代わりに.Textプロパティを使用します。 –

+0

さて、私はすべてを試しています。私は物事を行う方法についてVBAの記事を読む日のほとんどを過ごしました。私が働くものが見つかるまで。新しい小さなプロジェクトが始まります。私は何を使うべきか分からない。私はすぐにログオンし、私の最後の投稿を削除します。 – CBiscuit

関連する問題