I know that I have approached you with this question before. This code I am presenting reflects my continued efforts to find a solution to my original query. Is there an answer to be given? Is there a solution? It eludes me. Any further pointers would be appreciated. Thank you.
It's always better to ask stupid questions; stupid questions have been known to reduce the frequency of stupid mistakes. )
Code:
Dim Name1() As String
Dim NewFruit() As String
sub main
Dim obj as object
Dim objWorkbook as object
Dim Fruit() As String
Set obj=CreateObject("Excel.Application")
Set obj = Getobject("C:\Temp\Snack.xls")
set objWorkbook=obj.Worksheets("Sheet2")
CntMax=obj.ActiveSheet.Rows.Count
ReDim Fruit(30)
ReDim Name1(30)
ReDim NewFruit(20)
Cnt=1
CntA=3
CntB=1
NewCnt=0
For i = CntA To CntMax
Fruit(CntA)=Trim(objWorkBook.Range("A" + CntA))
IF CntA > 3 Then
If Fruit(CntA)=Fruit(CntA-1) then
NewFruit(CntB)=Fruit(CntA)
CntB=CntB+1
End If
ElseIF CntA = 3 then
NewFruit(CntB)=Fruit(CntA)
End If
NewFruit(CntB)=NewFruit(CntB) + Chr$(9)
CntA=CntA+1
Next i
FCEnd="No fruit to Offer"
NewFruit(CntB)=NewFruit(CntB) & FCEnd
Begin Dialog dlgOptions 154, 11, 182, 188, "Fruit to Offer"
OkButton 130, 6, 50, 14, .btnOK
CancelButton 130, 23, 50, 14, .btnCancel
Text 48, 37, 70, 10, "Fruits"
DropComboBox 46, 112, 73, 40, NewFruit(), .CB1 'CntB), .CB1
End Dialog
Dim MyDialog As dlgOptions
Dialog MyDialog
If Err=102 then
Stop
End If
Dim GiveFruit As String
Dim Recipient As String
GiveFruit=MyDialog.CB1
CntC=3
MaxCnt=CntB
If GiveFruit=FCEnd then
Msgbox "You don't have any fruit to give, do you?"
Else
For i = CntC To CntMax
Givee(CntC)=Trim(objWorkBook.Range("A" + CntC))
If Givee(CntC)<>GiveFruit then
CntC=CntC+1
ElseIf Givee(CntC)=GiveFruit
For n=1 to MaxCnt
Name1(CntB)=Trim(objWorkBook.Range("C" + CntC))
CntC=CntC+1
Name1(CntB)=Name1(CntB) + Chr$(9)
CntB=CntB+1
CntMax=CntC
Next n
End If
Next i
End If
Begin Dialog dlgOptwo 154, 11, 182, 188, "Fruit to Offer"
OkButton 130, 6, 50, 14, .btnOK
CancelButton 130, 23, 50, 14, .btnCancel
Text 48, 37, 70, 10, GiveFruit
DropComboBox 46, 112, 73, 40, Name1(), .CB1 'CntA), .CB1
End Dialog
Dim NewDlg As dlgOptwo
Dialog NewDlg
If Err=102 then
Stop
End If
Recipient=NewDlg.CB1
msgbox Recipient & " will be receiving a " & GiveFruit & " today!"
end sub
It's always better to ask stupid questions; stupid questions have been known to reduce the frequency of stupid mistakes. )