08-31-2022, 02:37 PM
I'd like to do it like below:
very flexible and easy to read/understand
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