02-06-2026, 04:31 AM
Or this way:
Code: (Select All)
Type Menu
As String MName, MList
As Integer MlistCnt
End Type
M$ = "Fruits;Apple,Orange,Pear,Banana,Plum:" +_
"Veggies;Squash,Peas,Green Beans,Carrot,Celery:"+_
"Meats;Steak,Bacon,Chicken,Fish"
nM = StrCount(M$, ":") + 1
Dim foods(1 To nM) As Menu
For i = 1 To nM
s$ = GetItem$(M$, ":", i)
'Print s$
foods(i).MName = GetItem$(s$, ";", 1)
foods(i).MList = GetItem$(s$, ";", 2)
nList = StrCount(foods(i).MList, ",") + 1
Print i; ""; foods(i).MName; ":"
For j = 1 To nList
Print Space$(4); j; " "; GetItem$(foods(i).MList, ",", j)
Next
Print
Next
Input "enter: food type number, item number eg 2,4 for Veggies: Carrot"; c1, c2
Print " You chose: "; foods(c1).MName, GetItem$(foods(c1).MList, ",", c2)
Function GetItem$ (AString$, Delimiter$, Index As Long) ' alternate Item$() function
'use: Function StrCount& (AString$, Char$ )
'use: Function StrPlace& (AString$, Char$, Nth&)
ReDim cnt As Long, p1 As Long, p2 As Long
cnt = StrCount&(AString$, Delimiter$) + 1
p1 = StrPlace&(AString$, Delimiter$, Index - 1)
p2 = StrPlace&(AString$, Delimiter$, Index)
If Index > cnt Or Index < 1 Then
Exit Function ' beyond the limit of string
ElseIf Index = 1 Then
GetItem$ = Mid$(AString$, 1, p2 - 1)
ElseIf Index = cnt Then
GetItem$ = Mid$(AString$, p1 + Len(Delimiter$))
Else 'between
GetItem$ = Mid$(AString$, p1 + Len(Delimiter$), p2 - p1 - Len(Delimiter$))
End If
End Function
Function StrCount& (AString$, S$) ' Count S$ in Astring$
ReDim place As Long, cnt As Long, lenS As Long
place = InStr(AString$, S$): lenS = Len(S$)
While place
cnt = cnt + 1
place = InStr(place + lenS, AString$, S$)
Wend
StrCount& = cnt
End Function
Function StrPlace& (Astring$, S$, Nth As Long) ' Locate the place the Nth S$ is in Astring$
ReDim place As Long, cnt As Long, lenS As Long
place = InStr(Astring$, S$): lenS = Len(S$)
While place
cnt = cnt + 1
If cnt = Nth Then StrPlace& = place: Exit Function
place = InStr(place + lenS, Astring$, S$)
Wend
End Function
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever

