Sie sind auf Seite 1von 11

Sub hieuchinhsolieuthuyvan_khoavu_txt()

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'***doi ten worksheets

Worksheets("sheet1").Name = "tinhthuyvan"

Worksheets("sheet2").Name = "bangtra"

Worksheets("tinhthuyvan").Range("E2:G13").BorderAround _

LineStyle:=xlDashDot, ColorIndex:=3, Weight:=xlThick

'***doi mau vao vung du lieu minh vua lua chon

Dim mycolumns As Range

For Each mycolumns In Range("E2:G13").Columns

'*** doi mau

mycolumns.Interior.Color = RGB(0, 255, 0)

Next mycolumns

'***hien thi noi dung Comment

Dim mycommen As Comment

For Each mycommen In Worksheets("tinhthuyvan").Comments

MsgBox mycommen.Text

Next mycommen

Range("G1").AddComment "vu tran khoa:luu luong khao sat duoc theo cac nam"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'***lay tep tin chua file khoavu.txt

'***ten file can doc du lieu

Dim tenfile As String

tenfile = InputBox("nhap ten file can doc---Khoavu")


Dim filt As String

Dim filterindex As Integer

Dim title As String

Dim filename As String

Dim a As String

Dim Temp

Dim Row As Long

Row = 0

'*** gan bo loc tep

filt = "text files (*.txt),*.txt," & "comma separated files (*.csv), *.csv," & "all files (*.*),*.*"

'***hien thi cac tep *.txt la mac dinh

filterindex = 1

'***gan tieu de cho hop thu thoai

title = "chon tep khoavu"

'***lay ten tep

filename = Application.GetOpenFilename(filefilter:=filt, filterindex:=filterindex, title:=title)

'***thoat neu nhan nut cancel

If filename = "false" Then

MsgBox "khong tep tin nao duoc chon"

Exit Sub

End If

'***hien thi ten tep day du

MsgBox "ban vua chon tep: " & filename

Open filename For Input As 1

Do While Not (EOF(1))


Line Input #1, a

Temp = Split(a, ",")

Row = Row + 1

ThisWorkbook.Worksheets("tinhthuyvan").Cells(Row, 5).Value = Temp(0)

ThisWorkbook.Worksheets("tinhthuyvan").Cells(Row, 6).Value = Temp(1)

ThisWorkbook.Worksheets("tinhthuyvan").Cells(Row, 7).Value = Temp(2)

Loop

Close 1

chonlai1:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''

'***thiet lap va xu ly loi,bo qua tat ca cac loi va cau lenh tiep theo

On Error Resume Next

'***lua chon cot tinh luu luong

Dim cot As Range

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''

Set cot = Application.InputBox(" thu tu giam dan cua Qi ", Type:=8)

cot.Sort cot.Columns(1).Cells, xlDescending

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''

Set cot = Application.InputBox("Lua chon cot tinh luu luong thuy van Qi ", Type:=8)

If Err.Number <> 0 Then

MsgBox "Lua chon co loi :" & Err.Description, vbCritical, " Thong bao loi cho nguoi dung "

GoTo chonlai1

End If

cot.Sort cot.Columns(1).Cells, xlAscending

'***tinh luu luong trung binh


Dim Q As Double

Q = Application.WorksheetFunction.Average(cot)

'***dung de gan gia tri Q tinh duoc cua moi o vao o duoi cung cua cot

cot.Cells(cot.Rows.Count + 1, 1) = Q

cot.Cells(cot.Rows.Count + 1, cot.Columns.Count - 1) = "Qtb = "

cot.Cells(cot.Rows.Count + 1, cot.Columns.Count - 1).Font.Color = RGB(255, 0, 0)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim mycomment As Comment

For Each mycomment In Worksheets("tinhthuyvan").Comments

MsgBox mycomment.Text

Next mycomment

Range("G14").AddComment "vu tran khoa:luu luong trung binh vua tinh duoc"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim cot1 As Range

Dim i As Integer

Dim j As Integer

Dim tg As Double

Dim tg1 As Double

Dim tg2 As Double

Dim Tong1 As Double

Dim Tong2 As Double

ThisWorkbook.Worksheets("tinhthuyvan").Range("I1") = "Ki"

ThisWorkbook.Worksheets("tinhthuyvan").Range("J1") = "(Ki-1)^2"

ThisWorkbook.Worksheets("tinhthuyvan").Range("K1") = "(Ki-1)^3"

For Each cot1 In cot


i=i+1

tg = cot1.Value / Q

tg1 = (tg - 1) ^ 2

tg2 = (tg - 1) ^ 3

ThisWorkbook.Worksheets("tinhthuyvan").Range("I2").Resize(i, 1).Cells(i, 1).Value = tg

ThisWorkbook.Worksheets("tinhthuyvan").Range("J2").Resize(i, 1).Cells(i, 1).Value = tg1

ThisWorkbook.Worksheets("tinhthuyvan").Range("K2").Resize(i, 1).Cells(i, 1).Value = tg2

Tong1 = Tong1 + tg1

Tong2 = Tong2 + tg2

ThisWorkbook.Worksheets("tinhthuyvan").Range("I2").Resize(i + 1, 1).Cells(i + 1, 1) = "Tong="

ThisWorkbook.Worksheets("tinhthuyvan").Range("J2").Resize(i + 1, 1).Cells(i + 1, 1).Value = Tong1

ThisWorkbook.Worksheets("tinhthuyvan").Range("K2").Resize(i + 1, 1).Cells(i + 1, 1).Value = Tong2

Next cot1

'TINH Cs,Cv

Dim Cs As Double

Dim Cv As Double

Cs = Round((Tong1 / (i - 1)) ^ (0.5), 1)

Cv = Round(Tong2 / ((i - 1) * Cs), 1)

ThisWorkbook.Worksheets("tinhthuyvan").Range("I2").Resize(i + 2, 1).Cells(i + 2, 1) = "Cs="

ThisWorkbook.Worksheets("tinhthuyvan").Range("J2").Resize(i + 2, 1).Cells(i + 2, 1).Value = Cs

ThisWorkbook.Worksheets("tinhthuyvan").Range("I2").Resize(i + 3, 1).Cells(i + 3, 1) = "Cv="

ThisWorkbook.Worksheets("tinhthuyvan").Range("J2").Resize(i + 3, 1).Cells(i + 3, 1).Value = Cv

'***Chuyen doi vung du lieu trong Excel ra dang file text***

'***Change dimension to use late binding ***

Dim FSO As Object 'FSO As Scripting.FileSystemObject


Dim TextStr As Object 'TextStr As Scripting.TextStream

Dim Rng As Range

'***tao doi tuong su dung de tao ra mot FileSystemObject ***

Set FSO = CreateObject("Scripting.FileSystemObject")

'***Mo mot tap tin van ban cho appending***

'***Neu khong ton tai tap tin ta se tao ra mot tap tin moi duoi *txt ***

ForAppending = 8

Set TextStr = FSO.OpenTextFile(filename:="E:\Fileketqua.txt", _

IOMode:=ForAppending, Create:=True)

For Each Rng In Range("G1:G14")

If Rng.Value <> "" Then

TextStr.WriteLine Text:="The Value In: " & _

Rng.Address(False, False) & " is: " & Rng.Value

End If

Next Rng

For Each Rng In Range("I1:K16")

If Rng.Value <> "" Then

TextStr.WriteLine Text:="The Value In: " & _

Rng.Address(False, False) & " is: " & Rng.Value

End If

Next Rng

TextStr.Close

Set FSO = Nothing

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'***ve bieu do duong tan suat theo kinh nghiem:


'm:so tran lu

'n:so nam bang quan trac

Dim m As Range

Dim n As Double

Dim p As Double

Dim a1 As Double

a1 = ThisWorkbook.ActiveSheet.Range("A12").Value

n = a1 + 1

For Each m In Range("G2:G13").Rows

p = (1 / 100) * Val(m) / (n + 1)

' xuat ket qua

m.Cells(m.Columns.Count, 2) = p

Next m

ThisWorkbook.ActiveSheet.Range("H1").Value = " P%"

'***coppy du lieu

' Sheets("tinhthuyvan").[G1:H13].Copy: Sheets("dothi").[G1:H13].PasteSpecial _

' Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

' Dim chrt As ChartObject

' Set chrt = ThisWorkbook.Worksheets("dothi").ChartObjects.Add(100, 30, 400, 250)

' chrt.Name = "Bieu do"

'chrt.Chart.ChartWizard ThisWorkbook.Worksheets("dothi").Range("G1:H13"), xlLine, , xlRows, 1, 1,


True, "Bieu do duong tan suat", "Qi", "P%"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim ws As Worksheet

Dim chrt As Chart

Set ws = ThisWorkbook.Worksheets(1)
' tao moi mot chartsheet , nam sau worksheet hien hanh

Set chrt = Charts.Add(, ws)

' dat ten cho chartsheet

chrt.Name = "bieudotansuat"

' tao bieu do tan suat dung phuong thuc chartwizard

chrt.ChartWizard ws.Range("G1:H13"), xlLine, , xlColumns, 1, 1, True, " BIEU DO TAN SUAT THEO KINH
NGHIEM", "Q(m3/s)", "P%"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'***doan ma dung de dem thoi gian

startTime = Timer

For Z = 1 To 14

Cells(Z, 1) = Z

Next

EndTime = Timer

ttime = EndTime - startTime

hh = Int(ttime / 3600)

mm = Int((ttime - hh * 3600) / 60)

ss = Int(ttime - hh * 3600 - mm * 60)

ct = ttime - Int(ttime)

MsgBox "Thoi gian chay ket qua la: " & Chr(10) _

& ttime & "s" & Chr(10) _

& Format(hh, "00") & ":" & Format(mm, "00") & ":" _

& Format(ss, "00") & ":" & Format(ct * 100, "00")

End Sub
Public Sub TinhQp()

Dim Q1 As Double

Dim Q2 As Double

Dim Q3 As Double

Dim Q25 As Double

Dim Q70 As Double

Dim Q90 As Double

Dim Q99 As Double

Dim Cv As Double

Dim Delta1 As Double

Dim Delta2 As Double

Dim Delta3 As Double

Dim Delta4 As Double

Dim Delta5 As Double

Dim Delta6 As Double

Dim Delta7 As Double

Dim Qtb As Double

Cv = ThisWorkbook.Worksheets("tinhthuyvan").Range("J16").Value

Delta1 = ThisWorkbook.Worksheets("bangtra").Range("E16").Value

Delta2 = ThisWorkbook.Worksheets("bangtra").Range("F16").Value

Delta3 = ThisWorkbook.Worksheets("bangtra").Range("G16").Value

Delta4 = ThisWorkbook.Worksheets("bangtra").Range("H16").Value

Delta5 = ThisWorkbook.Worksheets("bangtra").Range("I16").Value

Delta6 = ThisWorkbook.Worksheets("bangtra").Range("J16").Value

Delta7 = ThisWorkbook.Worksheets("bangtra").Range("K16").Value
Qtb = ThisWorkbook.Worksheets("tinhthuyvan").Range("G14").Value

ThisWorkbook.Worksheets("bangtra").Range("D16").Value = " Kp% ="

ThisWorkbook.Worksheets("bangtra").Range("D17").Value = " Qp% ="

Q1 = (Delta1 * Cv + 1) * Qtb

Q2 = (Delta2 * Cv + 1) * Qtb

Q3 = (Delta3 * Cv + 1) * Qtb

Q25 = (Delta4 * Cv + 1) * Qtb

Q70 = (Delta5 * Cv + 1) * Qtb

Q90 = (Delta6 * Cv + 1) * Qtb

Q99 = (Delta7 * Cv + 1) * Qtb

ThisWorkbook.Worksheets("bangtra").Range("E17").Value = Q1

ThisWorkbook.Worksheets("bangtra").Range("F17").Value = Q2

ThisWorkbook.Worksheets("bangtra").Range("G17").Value = Q3

ThisWorkbook.Worksheets("bangtra").Range("H17").Value = Q25

ThisWorkbook.Worksheets("bangtra").Range("I17").Value = Q70

ThisWorkbook.Worksheets("bangtra").Range("J17").Value = Q90

ThisWorkbook.Worksheets("bangtra").Range("K17").Value = Q99

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

End Sub

Das könnte Ihnen auch gefallen