mem arrays
#7
I'd like to do it like below:
very flexible and easy to read/understand

Code: (Select All)
DefInt A-Z

Type orderType
  amount As Long
  status As _Byte
End Type
Type detailType
  prodid As String * 10
  amount As Long
End Type
ReDim Shared order(1) As orderType
ReDim Shared detail(1, 1) As detailType

For o = 1 To 100
  onr = addOrder
Next o

Function addOrder% ()
  onr = UBound(order) + 1: ReDim _Preserve order(onr) As orderType
  order(onr).amount = 0
  For d = 1 To 6
    dnr = addDetail(onr, Right$(String$(10, " ") + LTrim$(Str$(d)), 10), d * 10)
  Next d
  addOrder = onr
End Function

Function addDetail (onr, id$, amount)
  oo = UBound(detail, 1): dd = UBound(detail, 2)
  If onr > oo Then
    ReDim _Preserve detail(onr, dd) As detailType
  Else
    For dnr = 1 To dd
      If _Trim$(detail(onr, dnr).prodid) = "" Then Exit For
    Next dnr
  End If
  If dnr > dd Then ReDim _Preserve detail(onr, dnr) As detailType
  detail(onr, dnr).prodid = id$
  detail(onr, dnr).amount = amount
  order(onr).amount = order(onr).amount + amount
  addDetail = dnr
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply


Messages In This Thread
mem arrays - by James D Jarvis - 08-23-2022, 04:45 AM
RE: mem arrays - by Jack - 08-23-2022, 11:49 AM
RE: mem arrays - by James D Jarvis - 08-23-2022, 12:43 PM
RE: mem arrays - by Jack - 08-23-2022, 12:50 PM
RE: mem arrays - by James D Jarvis - 08-23-2022, 02:08 PM
RE: mem arrays - by SpriggsySpriggs - 08-31-2022, 01:14 PM
RE: mem arrays - by mdijkens - 08-31-2022, 02:37 PM



Users browsing this thread: 6 Guest(s)