-
November 20th, 2004, 08:04 PM
#1
adding arrays
hello guys
i have a quick question
how can i add an array to each other ................ for example
i created an array like ...... price(100)
and it collect the prices which is added fron text box
and i want to add them to each other and asign the total to a variable called ......total and print it in a form
thanks
-
November 21st, 2004, 05:22 AM
#2
-
November 21st, 2004, 06:15 AM
#3
Re: adding arrays
I suppose you could iterate through the array with a simple loop.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
November 21st, 2004, 12:15 PM
#4
Re: adding arrays
wizbang
how lets say that i have a hundred array
price (100)
how to get the total of them
i did this:
for counter = 0 to 100
total = price(counter) + price (counter)
next counter
but this gave me the wrong summtion
any one has more ideas
-
November 21st, 2004, 12:49 PM
#5
Re: adding arrays
do you want a single total for the 101 prices?
then simply:
Code:
Dim Total as double
Dim Counter as Long
For Counter =lbound(price) to ubound(price)
Total= Total+price(Counter)
Next
msgbox format(Total,"@,@@@,@00.00")
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
November 21st, 2004, 01:17 PM
#6
Re: adding arrays
thanks man it is working fine
now i have anthor quetion
how can i set them prices and the total to zero..... i mena by this to clear the variable price(counter) and set it to zero
thanks again
-
November 21st, 2004, 01:27 PM
#7
Re: adding arrays
the total:
A single cell:
the whole array (if it was a fixed length one, like in:
Dim Price(100) as Double
If it is not a fixed length array (or if it is not
a numeric one and you want a zero inside each cell)
then:
Code:
Dim Counter as long
for Counter=lBound(Price) to Ubound(Price)
Price(Counter)=0
next
Last edited by Cimperiali; November 21st, 2004 at 01:36 PM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
November 21st, 2004, 07:07 PM
#8
Re: adding arrays
thanks cimperiali
it worked
i have some more quetions
now what i am buliding is a program which connect to database that is local to my hard drive using ado like this
Set adoCon = New ADODB.Connection
Set adoRecordset = New ADODB.Recordset
connectString = "Provider = Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=fatabase\sample.mdb"
adoCon.Open connectString
adoRecordset.Open "product", adoCon
so now if i want to compile my program and use it as an exe, what should ido
note this"Data Source=fatabase\sample.mdb" .....how can i use it universally
thanks
-
November 22nd, 2004, 04:49 AM
#9
Re: adding arrays
Many ways.
You could have an ini file (or a registry key) where to put the path of db.
Or, more easily, you could have the db in same folder of your exe and code
like the following (it will work also in develope if you open your project by
doubleclicking on it via resource explorer. It will not work fine if you open Vb
ide and then open the last opened project...) :
Code:
connectString = "Provider = Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & AddSlash(App.Path) & "sample.mdb"
where addSlash is a function like the following:
Code:
Public Function AddSlash(ByVal sPath As String) As String
sPath = Trim(sPath)
If Len(sPath) > 0 Then
If Right$(sPath, 1) <> "/" Then
If Right$(sPath, 1) <> "\" Then
sPath = sPath & "\"
End If
End If
AddSlash = sPath
End If
End Function
By the way: you could put the db in a subfolder. Ie:
Code:
connectString = "Provider = Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & AddSlash(App.Path) & "DataBase\sample.mdb"
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|