Sub Main()Dim K As Integer, L As Integer, N As Integer, M As Integer, I As Integer
Dim Temp As String, T As String, SS As Single
Dim ComePath As String, GoPath As String '文件路径
Dim FileHF As String  '来报文件名
Dim Filemix As String '加上路径
Dim newfile As String ' 新文件
Filename As String '加上路径的新文件Dim year As String, month As String, day As String, hour As String, min As String'动态定义数组
ReDim station(50) As String, weidu(50) As String
ReDim jingdu(50) As String, haiba(50) As String, yuliang(50) As String
ReDim ylsum(50) As Integer
Dim yl As Integer'Dim mytime, mydataDim tmpDate As Date, strFile As String, strTmp As String
Dim yearhalf As String
Dim realtime As String, ineedtime As String
' 设置工作盘与工作目录
ChDrive (Left$(App.Path, 2))
ChDir (App.Path)'读入配置文件 找到文件来源和文件目的地址
If Dir("autorain.cfg") = "" Then
   MsgBox "配置文件autorain.cfg不存在!", vbOKOnly + vbCritical, "警告信息"
   End
End If
N = FreeFile
Open "autorain.cfg" For Input As #N
  T = ""
  Line Input #N, T
  j = InStr(T, " ")
  ComePath = Trim(Mid$(T, j))
  
  T = ""
  Line Input #N, T
  j = InStr(T, " ")
  GoPath = Trim(Mid$(T, j))
  
Close #N
'检查网络设置情况
If (Dir(ComePath, vbDirectory) = "" Or Dir(GoPath, vbDirectory) = "") Then
   MsgBox "网络不通,请检查网络状况!", vbOKOnly + vbCritical, "警告信息"
   End
End If'设置时间,日期tmpDate = DateAdd("n", -0, Now())    '取当前的时间realtime = Format(tmpDate, "yyyymmddHHnn00")yearhalf = Mid(realtime, 3, 2)
month = Mid(realtime, 6, 2)
day = Mid(realtime, 9, 2)
hour = Mid(realtime, 12, 2)
min = Mid(realtime, 15, 2)
ineedtime = Left(realtime, 11) + "000"
'找文件,目录strFile = "Z_O_AWS_PRF_C_BEHF_"FileHF = strFile + ineedtime + "00.txt"Filemix = ComePath + "/" + FileHF
'打开文件,需要考虑跨年月日,找到前一次'strFile = "Z_O_AWS_PRF_C_BEHF_"
'找年月日
'mydate = Date
'mytime = Time'year = year(mydate)
'month = month(mydate) '小于10的,前面加0
'day = day(mydate)'FileHF = strFile + year + month + day + hour + min + "00.txt"
'Filemix = ComePath + "/" + FileHF'读入文件,把行文件内容读入
Open "Filemix" For Input As #N
I = 0    ' 数组变量
T = ""
Line Input #N, T 'NNNN判断是否是结尾
If T <> "NNNN" Then
'读第一行,找到站号,纬度,精度,海拔
            T1 = ""
           Line Input #N, T1
          station(I) = Left(T1, 5)
          weidu(I) = Mid(T1, 7, 6)
          jingdu(I) = Mid(T1, 14, 7)
          haiba(I) = Mid(T1, 22, 5)
          
'读入第2行,找到小时累计雨量
    
         T2 = ""
         Line Input #N, T2
         yuliang(I) = Mid(T2, 15, 5)'读入第3行,找到min累计雨量
         T3 = ""
         Line Input #N, T3
         I = 2
              If j < 22 Then
               yl = Right(T3, j)
               I = j + 2
               yl = CInt(yl)
              ylsum(I) = ylsum(I) + yl
              
              I = I + 1
              End If
              
 End If
 Close N#
 
 '重新定义数组
 
 ReDim station(I) As String, weidu(I) As String
 ReDim jingdu(I) As String, haiba(I) As String, yuliang(I) As String
 ReDim ylsum(I) As Integer
 
 
 '处理文件过程newfile = month + day + hour + min + ".000"
Filename = GoPath + "/" + newfile
Open FielName For Output As #N
'输入第一行
Print #N, "diamond 3 " + year + "年" + month + "月" + day + "日" + hour + "时" + min + "分" + "加密自动站分钟降雨量"'输入第二行Print #N, yearhalf + " " + month + " " + day + " " + hour + min + " " + " -1  2  0  0  1  0"'输入第三八行
Print #N, "39 122.7  37.3 122.5  36.7 120.8  36.2 119.3  35.0 120.4  34.3"
Print #N, "121.1  32.7 122.3  30.9 122.5  30.1 121.5  28.0 119.8  25.0"
Print #N, "116.1  22.6 111.0  21.0 111.0  18.6 109.6  18.1 108.3  18.5"
Print #N, "108.9  19.9 109.3  21.0 106.4  21.6 104.1  22.2 101.6  20.8"
Print #N, "98.7  22.0  97.1  24.1  97.7  27.0  91.7  26.6  85.7  27.7"
Print #N, "78.9  30.6  73.3  37.1  74.1  40.7  87.6  49.8  98.5  43.9"
Print #N, "110.4  44.3 122.0  54.7 135.7  48.3 131.5  42.2 125.2  39.4"
Print #N, "121.3  38.5 121.2  40.3 118.5  38.6 120.8  38.1"' 第九行 单站要素个数 总站数
Print #N, "1" + "    " + I'第十行 到N行 各站资料
For j = 0 To j = I
Print #N, 9999; " + "; " + jingdu(j) + "; " + weidu(j) + "; " + haiba(j) + "; " + ylsum(j)"
 Next j
 
 
 '第N+1行 NNNN
 Print #N, "NNNN"
 
 '关闭文件
 Close #N
 
 End Sub

解决方案 »

  1.   

    谢谢兄弟们
     这个小程序要求是:
     找到每整十分钟的生成的文件,如Z_O_AWS_PRF_C_BEHF_20060701091000.txt ,Z_O_AWS_PRF_C_BEHF_"20060701090000.txt
    打开里面的文件,把海拔,经纬度等信息存下来,创建一个新的文件如0607010910.000, 0607010900.000等  现在遇到的问题是:我对于这个要求的理解,已经编写出来相关的处理方法
    但是由于我第一次用VB,不知道 在填充这些处理方法的内容的时候,是否需要头尾补充点VB的规则什么?  那位可以将我的代码粘贴,运行下? 我怎么点击那个“前进” 的按键,没什么反应?
    是不是比较弱质的问题?
      

  2.   

    为什么不用from而用sub main
    c++过来的?