Solved

adding to an array

Posted on 2003-11-25
10
266 Views
Last Modified: 2010-05-03
This should be real easy, i just cant figure it out.

summary:

user enter 2 values. (example, 10001 and 15000)
program will create and array with all the number from 10001-15000.
10001
10002
10003
...

I need to store these all into an array.

----- Begin Code ------

dblCurrentFLN = dblFLNbegin
Do Until dblFLNbegin > dblFLNEnd
    strArray = Array(dblCurrentFLN)
    dblCurrentFLN = dblCurrentFLN + 1
Loop

----- End Code --------

That Array function isnt what i am looking for. it will jsut write the 1st line, then write the 2nd one over top of the 1st, and so on. I need the user to be able to put in another set of number after that and continue to write to the end of the array.  I will then write that whole array to a text file (i got that part down packed.)

Any ideas?

0
Comment
Question by:kmorris1186
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9816780
Dim strArray()

Dim i as integer
dblCurrentFLN = dblFLNbegin
Do Until dblFLNbegin > dblFLNEnd

    strArray(i) = Array(dblCurrentFLN)
    dblCurrentFLN = dblCurrentFLN + 1
Loop


0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9816789
Sorry. Hit tab at the wrong time.

Dim iArray() as integer

Dim i as integer
dblCurrentFLN = dblFLNbegin
Do Until dblFLNbegin > dblFLNEnd
    Redim Preserve iArray(i)
    iArray(i) = Array(dblCurrentFLN)  
     dblCurrentFLN = dblCurrentFLN + 1
Loop




0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9816799
& even that's not right.
iArray(i) = Array(dblCurrentFLN)  
should be
iArray(i) = dblCurrentFLN

I've used integers but you may want to use longs
     
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 9817351
OR

Option Explicit

Private Sub Command1_Click()
Dim arr() As Long

arr = getArr(10001, 10002)
End Sub

Private Function getArr(ByVal start As Long, ByVal endN As Long) As Long()
    Dim arr() As Long, I As Long
   
    On Error Resume Next
    I = endN - start + 1
    ReDim Preserve arr(I)
    For I = start To endN
        arr(I - start) = I
    Next
    getArr = arr
End Function
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9821358
EDDYKT,  you code comes back with an Overflow error.  I did leave one thing out, but delclaring these are Long, sould fix this problem and doesnt.  I just the FLN vars are actualy like this.  #############. ex, 9100331512345, all the way up to 9100331512349.  But that last 5 digits are the only ones that change.

I have to be doing somthing wrong, because i cant get any of this code to work.  It will just store the last number in the sequence into the array and that is it.
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9821936
ok. i figured out my problem.  I had to declare the array as a Double instead of a Long.  But i still need to add on to that array later in the program.  When i try to add onto it, it starts overwriting the old data in that array.
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9822105
ok i have changed the whole program..... instead of having that whole number stored as a double, i split it in half (as the 1st 8 numbes will not be changing. only the last 5 will)  i again, can get it it add to the array now problem.  this is actually using brand new code..

--------- Begin Code-------------
Dim I As Long
'Counter is initially 0 on program 1st run.
If Counter = 0 Then
    ReDim strArray(lngFLNEnd - lngFLNBegin)
    For I = 0 To lngFLNEnd - lngFLNBegin
        strArray(I) = lngCurrentFLN
        lngCurrentFLN = lngCurrentFLN + 1
    Next I
ElseIf Counter > 0 Then
    ReDim Preserve strArray(UBound(strArray))
    For I = UBound(strArray) + 1 To UBound(strArray) + lngFLNEnd - lngFLNBegin + 1
        strArray(I) = lngCurrentFLN
        lngCurrentFLN = lngCurrentFLN + 1
    Next I
End If
--------End Code---------

It blows up on the "strArray(I) = lngCurrentFLN" statement...
Subscript out of range.

so i am back to square one, and still cant add to an array...

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 35 total points
ID: 9822954
If you tell your array index to explicitly exceed the array bounds, then it will do so:

in " UBound(strArray) + lngFLNEnd - lngFLNBegin + 1"

is greater than UBound(strArray) unless lngFLNEnd is less than lngFLNBegin.
       
0
 

Expert Comment

by:leenapedenekar
ID: 9835079
i want to store the field values in the single recordset to
an array and check if any of the field is null in the recodset
how to do it
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9863486
It was actually a combination of all of GrahamSkan answers.

 EDDYKT,  yours sorta worked, but i found that GrahamSkan's was much easier to work with.

Thanks guys!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 2 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question