2017-03-27 30 views
0

我剛加入,希望盡我所能學習,並盡我所能提供幫助。無法顯示數字值

我在我的VBA腳本的最後三個部分有重大問題。 幻燈片上未顯示正確,不正確和百分比值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

謝謝你的建議的更改。我能夠修改我的腳本到它的工作點,直到將[用戶名,日期,百分比]等選定變量插入到表單上。在這個表格上,我爲這三個項目創建了標籤,但仍然無法將它們放在表單上。這是我的新代碼。我是否使用標籤或文本框將信息插入到幻燈片42上的表單中。我希望sub Correct()中的信息能解決我的問題,但它沒有。任何新的想法。我知道日期格式是關閉的,沒有空間留給我的代碼。 – CBiscuit

+0

評論中的代碼變成了混亂的混亂;我會編輯您的原始帖子並在其中添加代碼或者開始一個新問題。但是在回答您的其他問題時,我對代碼的更改是基於您使用標籤控件的假設,您使用.Caption屬性設置其文本。如果您更改爲TextBox控件,請改用其.Text屬性。 –

+0

好吧,我正在嘗試一切。我大部分時間都在閱讀VBA文章,瞭解如何做事。直到我找到有效的東西。我將開始一個新的小項目。我不知道該用什麼。我將很快登錄並刪除我的最後一篇文章。 – CBiscuit