How to know if there are elements in a dynamic array 50 points .

Updated on technology 2024-04-13
21 answers
  1. Anonymous users2024-02-07

    Dynamic arrays generally have elements, and as long as you use redim, then there must be elements.

    If you do need to judge, use the isempty function.

    The procedure is as follows. private sub form_load()dim amsgbox isempty(a)end sub

    Returns true.

    The procedure is as follows. private sub form_load()dim aredim a(0)

    msgbox isempty(a)

    end sub

    Returns false.

    So you can see that as long as you use redim, no matter how big it is, there are elements. It's only after the dynamic array (dim) is declared, and before the redim is used, that the array has no elements.

  2. Anonymous users2024-02-06

    Oh, I don't know how to judge, usually, I define a global icount variable to record the number of dynamic arrays, sometimes you need to clear the data of a(), but you can only use redim a(0), in fact, there is no data in it after this operation, at this time I usually set icount to -1, used to mark a() without any elements in it, use ** to control icount and a() so that you know whether a() has data, How much data is there.

    It's a stupid idea, but so far I haven't found a direct judgment, and as for isempty, I can't judge at all.

    dim a()

    redim a(1)

    a(0) = 1

    msgbox isempty(a) "Returns false, but I've already assigned a value.

    redim a(0)

    msgbox isempty(a)< - false is also returned here, so can't tell.

  3. Anonymous users2024-02-05

    In this case, it is better to use a set to solve it, and the array cannot determine whether there are elements or not!

    dim x as new collectionif then msgbox"There are no elements"

    That's it!

  4. Anonymous users2024-02-04

    I have a better way, you can judge by a function, it's convenient and fast, and you can use it as you like when you put it in a public module.

    function isarrayempty(a) as boolean

    on error resume next

    b = lbound(a)

    isarrayempty =

    end function

  5. Anonymous users2024-02-03

    The only way at the moment:

    option explicit

    dim a()

    private sub command1_click()static i as integer

    redim preserve a(i)

    a(i) = i

    print a(i)

    i = i + 1

    end sub

    private sub command2_click()on error goto errarr

    msgbox "array is used, and the maximum subscript is" & ubound(a)exit sub

    errarr:

    msgbox "The array is not initialized. "

    end sub

  6. Anonymous users2024-02-02

    It's also a good way to judge by the wrong trap:

    Here's exactly right.

    private sub command2_click()on error goto 1

    dim ii = ubound(a)

    msgbox "Arrays are not empty! "

    exit sub

    msgbox "The array is empty! "

    end sub

  7. Anonymous users2024-02-01

    The only way at the moment:

    option explicit

    dim a()

    private sub command1_click()static i as integer

    redim preserve a(i)

    a(i) =i

    print a(i)

    i = i + 1

    end sub

    private sub command2_click()on error goto errarr

    msgbox "array is used, and the maximum subscript is" &ubound(a)exit sub

    errarr:

    msgbox "The array is not initialized.

    end sub

  8. Anonymous users2024-01-31

    dim a() If you remove the () here, the following sentence redim preserve is problematic.

    private sub command1_click()static i as integer

    redim preserve a(i) 'I don't know how big the dynamic array is, so I have to use preserve

    a(i) =i

    print a(i)

    i = i + 1

    end sub

    private sub command2_click()on error goto 1

    dim ii = ubound(a)

    msgbox "Arrays are not empty! "

    exit sub

    msgbox "The array is empty! "

    end sub

  9. Anonymous users2024-01-30

    Let's give you a **, take a look at the annotation specifically:

    #include

    include needs to include this header file, which is used later by the malloc library function.

    void main()

  10. Anonymous users2024-01-29

    C, that's not going to work.

    Only dynamic allocation of memory can be used.

    int *a;

    a = (int *)malloc(sizeof(int)*n);

    c++int *a = new int[n];

  11. Anonymous users2024-01-28

    The default is 0, so all the arrays we define start at 0, and if you set it to option base 1, the first element of the array is 1

    i.e.: option base 0

    dim atest(2) 'The first element is atest(0)option base 1

    dim atest(2) 'The first element is atest(1).

  12. Anonymous users2024-01-27

    Originally, the default minimum subscript for declared arrays was 0, for example.

    dim s(5)as string

    There are 6 elements in total.

    I used it. option base 1

    After that, dim s(5)as string

    There are only 5 elements.

  13. Anonymous users2024-01-26

    Set the cardinality to 1, which means that the first element of the array is stu(1).

  14. Anonymous users2024-01-25

    Why are the annotations all garbled? You copy it to the VC and delete the comment. The language type is not specified, so it is made in C.

    #include

    #include

    #include

    void swap(int *a, int *b)void array(int *arr, int n) bubble sorting.

    for(i = 0; i < n; i++)int main()

    free(arr);

    return 0;}

  15. Anonymous users2024-01-24

    Here's my answer.

    dim n as integer

    dim b() as integer 'Your teacher told you to fill in the blanks, so don't merge 2 sentences into one sentence.

    n = 0for i = 1 to 10

    if a(i) <80 then

    n = n + 1

    redim preserver b(n) 'Upstairs, the result of not adding is that every time you redim, all the previous values are cleared to 0

    b(n) =a(i)

    end if

    next i

    print

  16. Anonymous users2024-01-23

    dim n as integer, b() as integern = 0for i = 1 to 10

    if a(i) <80 then

    n = n + 1

    redim preserve b(n) 'Note the preserver parameter, changing the dimension of the array will not destroy the contents of the array.

    b(n) =a(i)

    end if

    next i

  17. Anonymous users2024-01-22

    One-dimensional array loop shift is not reliable, you are better off using queues. The location of the queue function is shown in the following figure.

    Here's how it works:

    1) Create a queue reference outside the while loop collecting data, and set the queue size to 100

    2) In the loop, use "lossy elements in the column" to send the data into the queue.

    3) Get the queue status, take out the elements in the queue, and make an average.

    4) When the while loop ends, the queue reference is released outside the while loop.

    See screenshot below.

    When the queue reaches the set size, the new data will be pushed out, for example, when the 101st element is enlisted, the first element will be cleared from the queue.

    There is another method, which seems relatively simple, but if it is run for a long time, it may cause memory leaks, and the program will take up more and more memory. The idea is:

    1) Create an empty array, add data to the array every time you collect, 2) Then check the array size, if the array size <=100, directly find the average value of the data in the array, if the array size is greater than 100, delete the first element, and then find the average.

    See the picture below that both methods are placed in the attachment, and you can choose the one you like.

  18. Anonymous users2024-01-21

    Don't be so troublesome, there is a question is, how many data does your serial port receive per second. If your serial port has 1000 data per second, then the average number you have to calculate in the second is from 101 to 200, or from 1001 to 1100. My method is updated every second, which is 1001 to 1100 in the second second

    This 1000 for loop simulates that I take 1000 data every second, and every second, I take out the latest 1000 data and index the top 100 for averaging.

    The bottom half of the block diagram is your idea, if you use a one-dimensional loop shift, the array will get bigger and bigger, of course, your computer memory is large enough to not let the array exceed the memory each time it runs.

  19. Anonymous users2024-01-20

    In the case of the average, add an array sum - divide by the length, and that's it.

    In addition, this should be placed in a loop, and the shift register will do.

  20. Anonymous users2024-01-19

    You use vectors. That's fine. Simple and convenient to use.

    If you add it directly, there's no way, right? The array doesn't provide a similar function. You can rewrite a function yourself. Reallocate the space and copy it to the new space. This function is also easy to write. (This is also done in vectors).

  21. Anonymous users2024-01-18

    You can't change the size of an array dynamically.

    int *p = new int[5];

    int *q = new int[10];

    for(i = 0; i < 5; +i) q[i] = p[i];

    delete p;

    p = q;Remember to delete p when you finish using the array that p points to

Related questions
11 answers2024-04-13

The method for dynamically defining a 2-dimensional array in C++ is: >>>More

6 answers2024-04-13

There is no restriction on the candidate's academic qualifications, and there is no restriction on the industry in which the FRM registration qualification is engaged, and college students in the school also meet the requirements of the FRM registration qualification. >>>More

12 answers2024-04-13

According to your description, 3000 kWh of electricity in 2 years should be within a reasonable range, you can calculate it, 3000 24 30 = 4, 4 kWh of electricity per day, if you have a load of 1000w per day, use 4 small poems per day and consume it. You have a lot of electrical equipment, although it is not commonly used, but a few more pieces can exceed 1000W. If there is a problem with the meter, the chance of going slow is greater than the chance of going fast! >>>More

15 answers2024-04-13

First of all, if there is rabies virus in the body, it is generally not detectable, unless it is waiting for it to attack, otherwise it is a pathological autopsy, of course, this is not feasible, so it can only be prevented. >>>More

7 answers2024-04-13

With the increasing demand for miniaturization of electronic devices, the functions of a single chip are increasing. In the prior art, in order to ensure the quality of the chip, the chip testing stage is usually included between the design molding and mass production. However, the traditional chip debugging technology is an additional set of function-specific test procedures developed based on the chip function, which can usually only detect whether the chip has errors or faults, and cannot accurately locate the errors in the chip terminal, and can only be judged by the experience of the inspectors, resulting in slow chip detection speed and low efficiency. >>>More