displaying arrays of form1 in form2
hello guys
i have an important quetion
how can i take an array of strings or doubles that i process in form1 and displaying them in form2
ex: i have an array named
products(100)
and
prices(100)
i do some calulation on them in form1 after that i want to display them in form2 in this format:
product price
sugar 2.33
lamb 20.00
some can any one help
thanks
water 12.00
Re: displaying arrays of form1 in form2
i think there is something wrong with the first code
visual basic didnt eccept it
Re: displaying arrays of form1 in form2
In Form2:
Code:
Public ShowForm(strArray() As String)
' Code here to display what's in Array
End Sub
In Form1:
Code:
Call Form2.ShowForm(strArray)
Re: displaying arrays of form1 in form2
Re: displaying arrays of form1 in form2
where is Cimperiali
he is the man
can you respond Cimperiali
Re: displaying arrays of form1 in form2
Ooops, typo!
Try this:
In Form2:
Code:
Public Sub ShowForm(strArray() As String)
' Code here to display what's in Array
End Sub
In Form1:
Code:
Call Form2.ShowForm(strArray)
Re: displaying arrays of form1 in form2
thank you for helping mallyeo
but i want to display the in formation in form2 ....so is this correct
thanks
Re: displaying arrays of form1 in form2
this is doesnt work
this is what i did
in the first form:
Public Sub ShowForm(strArray() As String)
Dim counter As Integer
For counter = 1 To i
strArray() = price(i)
Print price(i)
counter = counter + 1
Next
End Sub
in the second form which should display the information
Private Sub Form_Click()
Call form1.ShowForm(strArray)
End Sub
Re: displaying arrays of form1 in form2
Quote:
Originally Posted by vipo1
this is doesnt work
That's because you have it backwards.
Put the following code in the Form that you want to show the information:
Code:
Public Sub ShowForm(strArray() As String)
Dim counter As Integer
For counter = LBound(strArray) To UBound(strArray)
'strArray() is the array that you pass to the form that you want to display it in. Use price() in the first form (see below)
Print strArray(counter)
'You don't need to increment counter, the For Loop does that for you
'counter = counter + 1
Next i 'You don't have to put the variable name after the Next, but I find it easier to read
End Sub
Put this code into the Form that you use to gather the info. I assume from your post that you stuff all your data into the array called price() in the 1st Form and you want to display the contents of price() in a 2nd Form.
Code:
Private Sub Form_Click()
Call form1.ShowForm(price)
End Sub
Re: displaying arrays of form1 in form2
this is not working at all
ok i will explain more
i have two forms
form1 which i use to calculate information for products by
entering the product code
after getting the prices from a database
the prices will be assigned to an array named price (100)
i calculate the total
and know what i want is to display the
product name and product price in the form2
so it would look like a receipt
form2 would look like a receipt
i am facing difficulty to reach this point
can any one help
thanks
Re: displaying arrays of form1 in form2
Open a new project. Click Project, Add Form. Click Open to choose 'Form'. Open Form1 and add a Command Button. Open Form2 and add a Label. Leave the names of all the controls as what they default to.
Open the Code window for Form1 and delete whatever code is there. Paste this code:
Code:
Option Explicit
Dim price(5) As Double
Private Sub Command1_Click()
Call Form2.ShowForm(price)
End Sub
Private Sub Form_Load()
price(0) = 100
price(1) = 225.5
price(2) = 300
price(3) = 400
price(4) = 500
price(5) = 600
End Sub
Open the Code window for Form2 and delete whatever code is there. Paste this code:
Code:
Option Explicit
Public Sub ShowForm(dblArray() As Double)
Dim counter As Integer
For counter = LBound(dblArray) To UBound(dblArray)
Label1.Caption = Label1.Caption & dblArray(counter) & vbCrLf
Next counter
Me.Show
End Sub
This will give you an idea of how it works. Now you have to modify the rest to suit your needs.
If you're going to post a question here and expect to get a code example, you have to know how to debug and tweak the code to make it work for you.
1 Attachment(s)
Re: where is Cimperiali...
Cimperiali is busy, or might be have read the answers you got and thought
they are enough for you to start trying by yourself.
In any case: malleyo helped you a lot, and you should thank
him. Moreover, herearound is full of people who are even better than
"Cimperiali" in writing helpful code, so do not ask for me directly...
As you seem a bit in difficoulty, to help you more, here how it could
be (see the notes I wrote in FrmStart). Note that the way array is passed
is quite the same as malleyo suggested...
Btw:
My wife is having a baby (our first baby), so you will not see me
very often in next days.
Re: displaying arrays of form1 in form2
thanks alot guys for helping especially malleyo ;)
Re: displaying arrays of form1 in form2
and thank you Cimperiali
you all guys are helpful
and i love this forum it is the best