⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 函数与插值.frm

📁 本小程序主要是用VB编程进行函数和插值的运算
💻 FRM
📖 第 1 页 / 共 2 页
字号:
        
        str1 = "name," + Trim(Px_Name) + "," + Trim(Py_Name)
        Print #File_No, str1
        
        str1 = "no,x,y"
        Print #File_No, str1
            For i = 0 To Data_N - 1
            str1 = Str(i + 1)
            str1 = str1 + "," + Str(Data_X(i))
            str1 = str1 + "," + Str(Data_Y(i))
            Print #File_No, str1
            Next i
        Close #File_No
    
End Sub

Private Sub Cmd_Input_Click()
    Dim i As Long, j As Long, k As Long, m As Long, N As Long
    Dim str1 As String, str2 As String, str3 As String, str4 As String
    Dim File_No As Integer, strData
    Dim d1 As Double, d2 As Double
    
        str1 = App.Path
        str2 = "数据文件(*.csv)|*.csv"

            With CDlg_File
            .InitDir = str1
            .FileName = ""
            .DialogTitle = "打开"
            .CancelError = False
            .Filter = str2
            .Flags = &H1004
            .ShowOpen
                If Len(.FileName) = 0 Then
                Exit Sub
                End If
            str3 = .FileName
            End With

            
        On Error Resume Next
        
'--------------------------------------------------------
        File_No = FreeFile(1)
        Open str3 For Input As #File_No
        
        Line Input #File_No, str1
        strData = Split(str1, ",")
        Pic_Title = strData(1)
        str2 = strData(2)
        Data_N = Val(str2)
        
        ReDim Data_X(0 To Data_N - 1)
        ReDim Data_Y(0 To Data_N - 1)
        
        Line Input #File_No, str1
        strData = Split(str1, ",")
        str2 = strData(1)
        Px_min = Val(str2)
        str2 = strData(2)
        Py_min = Val(str2)
        
        Line Input #File_No, str1
        strData = Split(str1, ",")
        str2 = strData(1)
        Px_max = Val(str2)
        str2 = strData(2)
        Py_max = Val(str2)
        
        Line Input #File_No, str1
        strData = Split(str1, ",")
        str2 = strData(1)
        Px_step = Val(str2)
        str2 = strData(2)
        Py_step = Val(str2)
        
        Line Input #File_No, str1
        strData = Split(str1, ",")
        str2 = strData(1)
        Px_Name = Trim(str2)
        str2 = strData(2)
        Py_Name = Trim(str2)
        
        
        Line Input #File_No, str1
'        str1 = "no,x,y"
        
            For i = 0 To Data_N - 1
            Line Input #File_No, str1
            strData = Split(str1, ",")
            str2 = strData(1)
            Data_X(i) = Val(str2)
            str2 = strData(2)
            Data_Y(i) = Val(str2)
            
            Next i
        Close #File_No
        
'-----------------------------------------------
        Call Plot_Data(Pic_Func, RGB(0, 0, 255))

End Sub

Private Sub Form_Load()
    Dim i As Long, j As Long, k As Long, m As Long, N As Long
    Dim str1 As String, str2 As String, str3 As String, str4 As String
    
        PI = 3.1415926535
        
        Lbl_Prg.Visible = False
        
'--------------------------------------------------------------
        W_x0 = 70
        W_y0 = 50
        W_xl = 390
        W_yl = 390
        
        Pic_Func.ScaleMode = 3
        Pic_Func.Width = (W_x0 + W_xl + 20) * 15
        Pic_Func.Height = (W_y0 + W_yl + 60) * 15
        Pic_Func.AutoRedraw = True
        
        Pic_Rest.ScaleMode = 3
        Pic_Rest.Top = Pic_Func.Top
        Pic_Rest.Left = Pic_Func.Left + Pic_Func.Width + 20 * 15
        Pic_Rest.Width = Pic_Func.Width
        Pic_Rest.Height = Pic_Func.Height
        Pic_Rest.AutoRedraw = True

End Sub

Public Sub Plot_Data(Pic_Plot As PictureBox, Color As Long)
    Dim i As Long, j As Long, k As Long, m As Long, N As Long
    Dim d0 As Double, d1 As Double, d2 As Double, d3 As Double, d4 As Double
    
    Dim X_0 As Double, X_S As Double, Y_0 As Double, Y_S As Double
    
    Dim DX As Double, DY As Double
    Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single
        
        Pic_Plot.Cls
            
        Pic_Plot.CurrentX = W_x0 + 80
        Pic_Plot.CurrentY = W_y0 - 40
        Pic_Plot.FontSize = 20
        Pic_Plot.Print Pic_Title
        
'---- 坐标变换 --------------------------------------------
        X_S = W_xl / (Px_max - Px_min)
        X_0 = -Px_min * X_S + W_x0
        Y_S = -W_yl / (Py_max - Py_min)
        Y_0 = -Py_min * Y_S + W_y0 + W_yl
        
'---- X 轴 --------------------------------------------
        Pic_Plot.FontSize = 10
        y1 = Py_min * Y_S + Y_0
        y2 = y1 + 10
        
        x1 = Px_min * X_S + X_0
        x2 = Px_max * X_S + X_0
        Pic_Plot.Line (x1, y1)-(x2, y1), 0
            
            For DX = Px_min To Px_max + Px_step / 2 Step Px_step
            x1 = DX * X_S + X_0
            x2 = x1
            Pic_Plot.Line (x1, y1)-(x2, y2), 0
            
            Pic_Plot.CurrentX = x1 - 25
            Pic_Plot.CurrentY = y1 + 15
            Pic_Plot.Print Str(DX)
            Next DX
        
        Pic_Plot.FontSize = 15
        Pic_Plot.CurrentX = W_x0 + W_xl / 2 - 50
        Pic_Plot.CurrentY = y1 + 25
        Pic_Plot.Print Trim(Px_Name)
        
'---- Y 轴 --------------------------------------------
        Pic_Plot.FontSize = 10
        x1 = Px_min * X_S + X_0
        x2 = x1 - 10
        
        y1 = Py_min * Y_S + Y_0
        y2 = Py_max * Y_S + Y_0
        Pic_Plot.Line (x1, y1)-(x1, y2), 0

            For DY = Py_min To Py_max + Py_step / 2 Step Py_step
            y1 = DY * Y_S + Y_0
            y2 = y1
            Pic_Plot.Line (x1, y1)-(x2, y2), 0
            
            Pic_Plot.CurrentX = x1 - 65
            Pic_Plot.CurrentY = y1 - 6
            Pic_Plot.Print Str(DY)
            Next DY
            
        Pic_Plot.FontSize = 15
        Pic_Plot.CurrentX = W_x0 - 20
        Pic_Plot.CurrentY = W_y0 - 30
        Pic_Plot.Print Trim(Py_Name)

'---- 绘图 --------------------------------------------
        x1 = Data_X(0) * X_S + X_0
        y1 = Data_Y(0) * Y_S + Y_0
                
            For i = 0 To Data_N - 1
            x2 = Data_X(i) * X_S + X_0
            y2 = Data_Y(i) * Y_S + Y_0
            Pic_Plot.Line (x1, y1)-(x2, y2), Color
            x1 = x2
            y1 = y2
            Next i
        
'------------------------------------------------------
        Pic_Plot.Refresh
        
End Sub

Private Sub Timer1_Timer()

        Lbl_DT.Caption = "当前时间:" + Str(Now())
        
End Sub

'===========================================================================
Public Function Pk(Xn() As Double, N As Long, k As Long, x As Double) As Double
    Dim i As Long
    Dim d0 As Double

        d0 = 1
            For i = 1 To k - 1
            d0 = d0 * (x - Xn(i - 1)) / (Xn(k - 1) - Xn(i - 1))
            Next i
        
            For i = k + 1 To N
            d0 = d0 * (x - Xn(i - 1)) / (Xn(k - 1) - Xn(i - 1))
            Next i
        
        Pk = d0
        
End Function

Public Function Fn(Xn() As Double, Yn() As Double, N As Long, x As Double) As Double
    Dim k As Long
    Dim d0 As Double

        d0 = 0
            For k = 1 To N
            d0 = d0 + Pk(Xn, N, k, x) * Yn(k - 1)
            Next k
         Fn = d0

End Function

Public Sub Plot_Data_P(Pic_Plot As PictureBox, Color As Long)
    Dim i As Long, j As Long, k As Long, m As Long, N As Long
    Dim d0 As Double, d1 As Double, d2 As Double, d3 As Double, d4 As Double
    
    Dim X_0 As Double, X_S As Double, Y_0 As Double, Y_S As Double
    
    Dim DX As Double, DY As Double
    Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single
        
        Pic_Plot.Cls
            
        Pic_Plot.CurrentX = W_x0 + 80
        Pic_Plot.CurrentY = W_y0 - 40
        Pic_Plot.FontSize = 20
        Pic_Plot.Print Pic_Title
        
'---- 坐标变换 --------------------------------------------
        X_S = W_xl / (Px_max - Px_min)
        X_0 = -Px_min * X_S + W_x0
        Y_S = -W_yl / (Py_max - Py_min)
        Y_0 = -Py_min * Y_S + W_y0 + W_yl
        
'---- X 轴 --------------------------------------------
        Pic_Plot.FontSize = 10
        y1 = Py_min * Y_S + Y_0
        y2 = y1 + 10
        
        x1 = Px_min * X_S + X_0
        x2 = Px_max * X_S + X_0
        Pic_Plot.Line (x1, y1)-(x2, y1), 0
            
            For DX = Px_min To Px_max + Px_step / 2 Step Px_step
            x1 = DX * X_S + X_0
            x2 = x1
            Pic_Plot.Line (x1, y1)-(x2, y2), 0
            
            Pic_Plot.CurrentX = x1 - 25
            Pic_Plot.CurrentY = y1 + 15
            Pic_Plot.Print Str(DX)
            Next DX
        
        Pic_Plot.FontSize = 15
        Pic_Plot.CurrentX = W_x0 + W_xl / 2 - 50
        Pic_Plot.CurrentY = y1 + 25
        Pic_Plot.Print Trim(Px_Name)
        
'---- Y 轴 --------------------------------------------
        Pic_Plot.FontSize = 10
        x1 = Px_min * X_S + X_0
        x2 = x1 - 10
        
        y1 = Py_min * Y_S + Y_0
        y2 = Py_max * Y_S + Y_0
        Pic_Plot.Line (x1, y1)-(x1, y2), 0

            For DY = Py_min To Py_max + Py_step / 2 Step Py_step
            y1 = DY * Y_S + Y_0
            y2 = y1
            Pic_Plot.Line (x1, y1)-(x2, y2), 0
            
            Pic_Plot.CurrentX = x1 - 65
            Pic_Plot.CurrentY = y1 - 6
            Pic_Plot.Print Str(DY)
            Next DY
            
        Pic_Plot.FontSize = 15
        Pic_Plot.CurrentX = W_x0 - 20
        Pic_Plot.CurrentY = W_y0 - 30
        Pic_Plot.Print Trim(Py_Name)

'---- 绘图 --------------------------------------------
        x1 = Data_PX(0) * X_S + X_0
        y1 = Data_PY(0) * Y_S + Y_0
                
            For i = 0 To Data_PN - 1
            x2 = Data_PX(i) * X_S + X_0
            y2 = Data_PY(i) * Y_S + Y_0
            Pic_Plot.Line (x1, y1)-(x2, y2), Color
            x1 = x2
            y1 = y2
            Next i
        
'---- 绘数据点 --------------------------------------------
            For i = 0 To Data_N - 1
            x1 = Data_X(i) * X_S + X_0
            y1 = Data_Y(i) * Y_S + Y_0
            Pic_Plot.Line (x1 - 3, y1 - 3)-(x1 + 3, y1 + 3), 0, BF
            Next i
        
'------------------------------------------------------
        Pic_Plot.Refresh
        
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -