这是我编写的一个程序 Sub Macro3() ' ' Macro3 Macro ' ºêÔÚ 2006-6-20 ÓÉ hmy ¼ÖÆ ' DIM a as single Dim b As Single Dim c As Single Dim d As Single Dim e As Single a = InputBox("a", "") b = InputBox("b", "") c = InputBox("c", "") d = InputBox("d", "") e = Round(a / b + c / d, 2) Selection.TypeText Text:="e" & "=" Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ PreserveFormatting:=False 'ʹÓÃÓò Selection.TypeText Text:="eq \f(a,b)+\f(c,d)" Selection.Fields.ToggleShowCodes 'Çл»Óò Selection.MoveRight Unit:=wdCharacter, Count:=2 'ʹÓÃÓÒ¹â±ê£¬Òƶ¯Á½¸ö×Ö·û Selection.TypeParagraph '»Ø³µ Selection.TypeText Text:=" =" Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ PreserveFormatting:=False Selection.TypeText Text:="eq \f(" & a & "," & b & ")+\f(" & c & "," & d & ")" Selection.Fields.ToggleShowCodes Selection.MoveRight Unit:=wdCharacter, Count:=2 Selection.TypeParagraph '»Ø³µ Selection.TypeText Text:=" =" & " " & e & "" End Sub 目的是求两个分数的和,有两个问题想请教大家:如果e算出来的值小于1的时候,显示出来的e值整数部分就没有了,例如,本来为0.06,结果电脑上显示成了.06,我不知道如何设置格式,可以使其能0.06的方式显示。还有一个问题是,我把程序中的几个变量定义成字符串格式,程序照样能运行,并且还正确,为什么呢,字符串格式和单精度浮点数格式应该多少有些差异吧 谢谢大家 |