vb 编译错误
以下代码编译错误,变量错误。小弟百思不得其解,希望各位达人帮帮小弟!
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
Dim i, j As Integer
i = i + 1
j = j + 1
Dim test As Variant
Dim filename As String
filename = Date
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
End Sub
Private Sub MSComm1_OnComm()
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Cells(i, j) = "yy"
xlapp.Visible = False
xlbook.SaveAs "d:\" & filename & Left(Time, 5) & "-" & Mid(Time, 7, 2) & "-" & Right(Time, 2)
xlbook.Close False
xlapp.Quit
End Sub
[解决办法]
Option ExplicitDim xlapp As Excel.ApplicationDim xlbook As Excel.WorkbookDim xlsheet As Excel.WorksheetDim test As VariantDim filename As StringDim i, j As IntegerPrivate Sub Command1_Click()MSComm1.CommPort = 1MSComm1.RThreshold = 1MSComm1.InputMode = comInputModeBinaryMSComm1.PortOpen = Truei = i + 1j = j + 1filename = DateEnd Sub