Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays

Status
Not open for further replies.

deboe

Technical User
Sep 28, 2006
18
US
Hello Guys,

Here is my problem:

I have a document that will contain six columns of data (all numeric). Column headings are (acct, control, cus, shr, nave, ndf). I would like my program to read the acct field until it reaches the value of "0094950" but along the way i would like it to count all of the rows that it passed in order to reach this particular row with "0094950" . When it reaches that field I would like to store all six of those columns in an array named "direct" in which 0 = acct; 1 = control ...etc . I would then like to make calculations based on the fields for instance shr * nave = calcvalu and store it as number seven in the array. I know that I would probably have to ReDim those statements in order for this to work.

Could someone please give me some ideas or a jump start on this project?

I appreciate any ideas

Thanks

Ric
 




Hi,

Is your source data document a TEXT file or something else?

You mention nothing about the terminal emulator. What are you going to do with this data?



Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
my data document will be a excel csv file.

This data will be hopefully stored, used to make calculations, and finally used to make entires in a database
 



So why are you using a terminal emulator?

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
The solutions have to be input into Attachmate. Using an internal entry code.
This is the only way it can be done.

Is it doable?
 




Your question was about arrays.

You can use ReDim to change the dimension. Check Attachmate Help for specifics.

Open a file for Input. Loop thru the records til EOF. Close the file.

Do you have ANY code so far?

IMHO, this appears that it would be a far sight easier done in Excel VBA. Where are you dumping the data?

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
do
Input #1, bin, acct, control#, cusip, tradedt, shares, netduefund, nav


if acct <> "00949500" then


elseif acct = "00949500" then

ReDim allifunds(control#, cusip, shares, netduefund, nav)


end if


x = x + 1

Loop




That's all I had so far
I just want to find a way to store this data while I make the proper calculations then store that value.
I want to be able to count the numbers of rows it took before I found the item I was looking for.
 
Also, if you're writing in in VBA, IMO a class would be better suited than an array. Are you just going to hold 5 pieces of data in the array (always), or could you hold more than one set of size?

Code:
Dim allifunds(4)
allifunds(0) = control#
allifunds(1) = cusip
allifunds(2) = shares
allifunds(3) = netduefund
allifunds(4) = nav

If you have to hold more than one set, you probably want a dynamic array...
Code:
Dim allifunds
ReDim allifunds(4, 0)
Sub SetAllifunds(control, cusip, shares, netduefund, nav)
  If allifunds(0, 0) = "" Then
    allifunds(0, 0) = control
    allifunds(1, 0) = cusip
    allifunds(2, 0) = shares
    allifunds(3, 0) = netduefund
    allifunds(4, 0) = nav
  Else
    ReDim Preserve allifunds(4, UBound(allifunds) + 1)
    allifunds(0, UBound(allifunds)) = control
    allifunds(1, UBound(allifunds)) = cusip
    allifunds(2, UBound(allifunds)) = shares
    allifunds(3, UBound(allifunds)) = netduefund
    allifunds(4, UBound(allifunds)) = nav
  End If
End Sub

I'm pretty sure with multi-dimensional arrays, that UBound will return the last dimension. In addition, I think you can only redim the last dimension.

I think EB has something similar to a class, I believe it's called type. Basically, it'd works something like this...
Code:
Type AlliFunds_Type
  Control As String
  Cusip As String
  Shares As String
  NetDueFund As String
  Nav As String
End Type

Dim AlliFunds As AlliFunds_Type
Sub SetAlliFunds(sControl, sCusip, sShares, sNewDueFund, sNav)
  AlliFunds.Control = sControl
  AlliFunds.Cusip = sCusip
  AlliFunds.Shares = sShares
  AlliFunds.NetDueFund = sNewDueFund
  AlliFunds.Nav = sNav
End Sub

Sub Main
  SetAlliFunds("1", "2", "3", "4", "5")
  MsgBox AlliFunds.Control
End Sub

Now, if you need it to be an array of AlliFunds_Type, you can do that. This would make it like Array(0).Control.

By doing this, it's a lot easier to figure out what each piece of data is. You don't end up down in your code going... "Was 4 the nav or the newduefund?" Nope, instead you just say, for this record gimme the .Nav.

Classes in VBA are similar to this but more powerful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top