如何在结构中输入结构

如何在结构中输入结构

本文介绍了如何在结构中输入结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这段代码有什么问题,因为每次我尝试运行此代码时都会给我一个错误:记录长度不足

I would like to know what's wrong with this code because each time I try to run this code it gives me an Error: Bad record length.

Public Structure WorkersSource
        <vbfixedstring(20)> Public Code As String
        <vbfixedstring(20)> Public FirstName As String
        <vbfixedstring(20)> Public LastName As String
        <vbfixedstring(20)> Public PhoneNumber As String
        <vbfixedstring(20)> Public Job As String
        Public Salary As Double
        Public Position As Integer
        <vbfixedstring(20)> Public UserName As String
        <vbfixedstring(20)> Public Password As String
        <vbfixedarray(6)> Public PayingDaliy() As WorkersPD
    End Structure

    Public Structure WorkersPD
        <vbfixedstring(20)> Public Day As String
        Public DateOfWeek As Date
        Public PayingOfDay As Double
        Public Present As Boolean
        Public Debts As Double
        Public Purchases As Double
        Public PayingNet As Double
    End Structure

    Public Sub AddWRecord(ByVal TmpRecordWorkerType As WorkersSource)
        Dim DataRecord As New WorkersSource
        Dim FileNum As Integer = FreeFile()

        FileOpen(FileNum, TmpFileName, OpenMode.Random, , , Len(DataRecord))

        With DataRecord
            .Code = TmpRecordWorkerType.Code
            .FirstName = TmpRecordWorkerType.FirstName
            .LastName = TmpRecordWorkerType.LastName
            .PhoneNumber = TmpRecordWorkerType.PhoneNumber
            .Job = TmpRecordWorkerType.Job
            .Salary = TmpRecordWorkerType.Salary
            .Position = TmpRecordWorkerType.Position
            .UserName = TmpRecordWorkerType.UserName
            .Password = TmpRecordWorkerType.Password

            For I = 0 To 6
                 .PayingDaliy(I).Day = TmpMonday.AddDays(I).ToString("dddd")
                 .PayingDaliy(I).DateOfWeek = TmpMonday.AddDays(I)
                 .PayingDaliy(I).PayingOfDay = 0.00
                 .PayingDaliy(I).Present = False
                 .PayingDaliy(I).Debts = 0.00
                 .PayingDaliy(I).Purchases = 0.00
                 .PayingDaliy(I).PayingNet = 0.00
            Next

        End With

            FilePut(FileNum, DataRecord, TotalWorkers.Count)

            FileClose(FileNum)

    End Function



这段代码应该保存关于worker的信息数组,在这个数组里面还有另一个工人的财务状况数组一周,并且假设全部信息保存到一个文件,其中包含其余的工人,这就是为什么有 TotalWorkers.Count



有什么解决方案吗?



谢谢



我尝试了什么:



在我给它值之前我曾试过ReDim PayingDaliy但它不起作用。


This code supposed to save the array of information about the worker and inside this array there's another array of the financial situation of the worker for a week and the whole information supposed to be saved to a file which will contain the rest of workers that's why there's "TotalWorkers.Count"

Is there any solution?

Thanks

What I have tried:

I have tried to ReDim the PayingDaliy before I give it the values but it didn't work.

推荐答案


这篇关于如何在结构中输入结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:29