這里有段VB6.0的,你可以參考。
站在用戶的角度思考問題,與客戶深入溝通,找到廣安網(wǎng)站設(shè)計與廣安網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋廣安地區(qū)。
注意添加引用。
Private Sub Command6_Click()
Dim i, j As Integer
Dim xlApplication As Excel.Application, xlWorkbook As Excel.Workbook, xlSheet
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApplication = GetObject(, "滲運Excel.Application")
Set xlApp = CreateObject("Excel.Application")
If MsgBox("確認(rèn)將文件信息導(dǎo)出到EXCEL中??", vbExclamation + vbYesNo, "警告") = vbYes Then
If Err.Number 0 Then Set xlApplication = CreateObject("Excel.Application")
Set xlWorkbook = xlApplication.Workbooks.Add
Set xlSheet = xlWorkbook.ActiveSheet
xlSheet.Cells(1, 2) = lblcl.Caption
xlSheet.Range("A1:E1").MergeCells = True
xlSheet.Range("A1:E1").HorizontalAlignment = xlCenter
xlSheet.Cells(2, 2).ColumnWidth = 18
For i = 1 To DataGrid1.Columns.Count
xlSheet.Cells(2, 1) = "槐喊拍編號"
xlSheet.Cells(2, i + 1) = DataGrid1.Columns(i).Caption
For j = 0 To DataGrid1.VisibleRows - 1
xlSheet.Cells(j + 3, 1) = j + 1
xlSheet.Cells(j + 3, i + 1) = DataGrid1.Columns(i).CellText(DataGrid1.RowBookmark(j))
Next j
Next i
xlApplication.Visible = True
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApplication = Nothing
'xlApp.Range("A2:L2").Columns.Interior.ColorIndex = 40
'xlApp.Range("A2:L2").Borders.LineStyle = xlContinuous
'xlApp.Visible = True
'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Columns.Interior.ColorIndex = 40
'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Borders.LineStyle = xlContinuous
Else
MsgBox "無信息可供您導(dǎo)出,請確鉛羨認(rèn)!", vbExclamation + vbOKOnly, "警告"
End If
End Sub
以下示例一次從文件中讀取一行首族,然后跡前將每行文本姿芹清打印到控制臺。
Sub ReadTextLinesFromFile()
Dim file As New System.IO.StreamReader("c:test.txt")
Dim oneLine As String
oneLine = file.ReadLine()
While (oneLine "")
Console.WriteLine(oneLine)
oneLine = file.ReadLine()
End While
file.Close()
End Sub
方法1:
Open "c:\1.txt" For Output As #1 '褲鍵c:\1.txt為保存文件
Print #1, Text1 Text2 Text3 ..... '將多個文本框內(nèi)容用合并在一起 寫入內(nèi)容
Close #1 '關(guān)賀脊閉文件
方法2:
Dim aa As String
aa =Text1 Text2 Text3 ..... '將多個文本框內(nèi)容用合并到變量aa
Open "c:\1.txt"胡拍巧 For Output As #1 'c:\1.txt為保存文件
Print #1, aa '寫入內(nèi)容
Close #1 '關(guān)閉文件
首先執(zhí)行Sub Main()
①定義兩個變量a=45 b=18
②將a和b作為sum過程的兩個參數(shù)x=45(按值傳遞),y=18(按地址傳遞,將在過程中改變b的初始值)
③xy滿足條件,將 x-y=45-18=27 賦值給衡皮桐x ;將 x+y=27+18=45 賦值給y,此時改變了b值為咐坦45.
④輸出x的值27 y的值45
⑤輸出a的值45 b的值握困45