Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2007, 01:57 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use array

Hi
I am Continously generating a random numbers using Timer.
How Can it be possible to strore numbers in say array & then take a Average of Suppose 30 or 50 readings but this operation is done whiile system is running.

Manoj :)
 
Old July 2nd, 2007, 02:53 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

If you dimension an array without specifying how many elements it has (Dim MyArr() As Integer), then you cna add elements to it dynamically.

Changing the size of an array deletes the array's contents unless you explicitly tell VB to preserve the results:
Code:
    Dim MyArr() As Integer

    ReDim MyArr(5)          ' The array will have 6 elements equal 
                            ' to zero (the default value of an Integer)
    ReDim Preserve MyArr(5) ' If the array had any non-zero elements, 
                            ' they are still there (as long as they
                            ' were between 0 and 4, of course...)
                            So, using this, you can add elements to your array everytime you generate a new random number:
Code:
    Redim Preserve MyArr(UBound(MyArr + 1))
Code:
    MyArr(UBound(MyArr)) = <YourNewValue>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
Array to Array comparison pavel Pro VB 6 0 March 24th, 2004 06:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.