Vba 无法显示数字值

Vba 无法显示数字值,vba,powerpoint,Vba,Powerpoint,我刚刚加入,希望在这里学到我能学到的一切,并尽我所能做出贡献 我的VBA脚本的最后三个部分存在重大问题。 正确、不正确和百分比分数值未显示在幻灯片40和41上 在幻灯片42中,我无法让文本框或标签显示用户名、日期及其总百分比分数 幻灯片40上的任何帮助都会很好,剩下的我可以锻炼 **Sub shapeTextHappySmile()**strong text** Sub ShapeTextSadSmile() Sub CertificateBuld()** Option Explicit

我刚刚加入,希望在这里学到我能学到的一切,并尽我所能做出贡献

我的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
**子shapeTextHappySmile()**强文本**
子形状ExtSadSmile()
子证书BULD()**
选项显式
将用户名设置为字符串
Dim numberCorrect为整数
Dim numberIncorrect为整数
整数形式的数字百分比
作为整数的Dim numberTotal
私有子证书日期()
Dim Rdate作为变体
Rdate=日期
Rdate=格式((日期),“MM dd,yyyy”)
端接头
子初始化()
numberCorrect=12
numberIncorrect=8
数字百分比=58
总数=20
numberTotal=(numberCorrect+numberIncorrect)
numberCorrect=(numberTotal-numberIncorrect)
numberIncorrect=(numberTotal-numberCorrect)
numberPercentage=四舍五入(numberCorrect/numberTotal)*100
端接头
小测验()
用户名=输入框(提示:=“键入您的姓名!”)
MsgBox“欢迎参加学术在线教程测验”+用户名,VBApplicationModel,“学术在线教程测验”
ActivePresentation.SlideShowWindow.View.Next
端接头
次更正()
numberCorrect=numberCorrect+1
MsgBox(“干得好!这是正确的答案”)
ActivePresentation.SlideShowWindow.View.Next
端接头
子错误()
numberIncorrect=numberIncorrect+1
MsgBox(“对不起!回答不正确”)
ActivePresentation.SlideShowWindow.View.Next
端接头
子shapeTextHappySmile()
ActivePresentation.Slides(40).Shapes(Label1).TextFrame.TextRange.Text=12
“数字正确吗
ActivePresentation.Slides(40).Shapes(Label2).TextFrame.TextRange.Text=numberPercentage&“%”
MsgBox“干得好,干得好”+,“请打印一份结业证书”
MsgBox“打印或保存证书副本后,您可以退出演示文稿”
带幻灯片窗口(1)。查看
GotoSlide先生42
以
端接头
子形状ExtSadSmile()
ActivePresentation.Slides(41).Shapes(“正确回答”).TextFrame.TextRange.Text=numberIncorrect
ActivePresentation.Slides(41).Shapes(“不正确百分比”).TextFrame.TextRange.Text=numberPercentage&“%”
MsgBox“您的分数低于70%,为了通过测验并获得结业证书,您需要获得70%或更高的分数。”
MsgBox“请重新进行测验,祝你好运”
带幻灯片窗口(1)。查看
戈托斯里德1号酒店
以
“我将添加重做整个演示或只是测试的选项。
'请参见幻灯片19操作按钮
端接头
子证书BULD()
MsgBox“干得好,干得好”+,“请打印一份结业证书”
MsgBox“打印或保存证书副本后,请退出演示文稿”
如果数字正确>=“14”,则
ActivePresentation.Slides(42).Shapes(“ABCDEFGHIJKLMN”).TextFrame.TextRange.Text=“ABCDEFGHIJKLMN”
ActivePresentation.Slides(42).Shapes(“Rdate&Percentage”).TextFrame.TextRange.Text=“ON”&Rdate&”,分数为“&numberPercentage&%”
ActivePresentation.Slides(42).Shapes(用户名).TextFrame.TextRange.Text=UserName
”“或者
如果numberCorrect请参见注释内联:

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

感谢您提出的修改建议。我可以修改我的脚本,直到将[username,date,percentage]等选定变量插入表单为止。在那个表单上,我已经为这三个项目创建了标签,但仍然无法在表单上找到它们。这是我的新代码。我是否使用标签或文本框将信息插入幻灯片42的表单中。我希望sub Correct()中的信息能够解决我的问题,但事实并非如此。任何新的想法。我知道日期格式不对,太不对了。。我的代码没有空间了。注释中的代码变成了一团混乱;我会编辑你原来的帖子并在那里添加代码,或者开始一个新问题。但在回答您的另一个问题时,我对代码所做的更改是基于这样的假设:您使用的是label控件,在该控件中使用.Caption属性来设置其文本。如果您更改为TextBox控件,请使用其.Text属性。好的,我正在尝试所有操作。我花了一天的大部分时间阅读VBA关于如何做事的帖子。直到我找到有效的方法。我将开始一个新的小项目。我不知道该用什么。我将很快登录并删除我的最后一篇文章。