Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / November 2004



Tip: Looking for answers? Try searching our database.

Converting array formula to work with datatables/dataset tia sal

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sal - 30 Nov 2004 03:43 GMT
Greets, All

Converting array formula to work with datatables/dataset tia sal

I finally completed a formula I was working on, see working code below.

I would like to change this code so it will work with a variable mutl-
row, 5 column datatable where the users select items. Anyone have any
suggestions on where to start?
Or changes in the current code that might be made.

Private Sub Arraylooptest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Arraylooptest.Click
       Dim arraya() As Integer = {15, 17, 20, 25} 'variable numbers
users can change

       Dim arrayb() As Integer
       Dim arrayc() As Integer
       Dim i, k As Integer, total As String
       Dim v As Object

       ReDim arrayb(arraya.GetUpperBound(0) - 1)
       arrayb(0) = arraya(0) + arraya(1)
       Console.WriteLine("Numbers used ")
       For Each v In arraya
           Console.WriteLine((v))
       Next

       Console.WriteLine(String.Format("a(0)->({0}) + a(1)->({1})= b
(0)->({2})", arraya(0), arraya(1), arrayb(0)))
       
       For i = 1 To arraya.GetUpperBound(0) - 1
           Console.WriteLine(String.Format("b({0})->({1}) + a({2})->
({3})= b({4})->({5})", i - 1, arrayb(i - 1), (i + 1), arraya(i + 1), i,
arrayb(i - 1) + arraya(i + 1)))
           arrayb(i) = arrayb(i - 1) + arraya(i + 1)
       Next

       ReDim arrayc(arrayb.GetUpperBound(0) - 1)
       'If statement to break if only two elements selected
       If (arrayc.Length) = 0 Then
           MessageBox.Show("only two elements use your calculator :-)")
           Exit Sub
       Else
       End If

       arrayc(0) = arrayb(0) + arrayb(1)
       Console.WriteLine("==Loop of Sums==")
       Console.WriteLine(String.Format("b({0})->({1}) + b({2})->({3})= c
({4})->({5})", 0, arrayb(0), 1, arrayb(1), 0, arrayb(0) + arrayb(1)))
       For k = 1 To arrayb.GetUpperBound(0) - 1
           arrayc(k) = arrayc(k - 1) + arrayb(k + 1)
           Console.WriteLine(String.Format("c({0})->({1}) + b({2})->
({3})= c({4})->({5})", k - 1, arrayc(k - 1), k + 1, arrayb(k + 1), k,
arrayc(k)))

       Next
       ReDim Preserve arrayc(k)
       'Show overall answer or puts answer in next open array slot
       If k = 1 Then
           Exit Sub
       Else
           arrayc(k) = arrayc(k - 2) + arrayc(k - 1)
           Console.WriteLine(String.Format("c({0})->({1}) + c({2})->
({3})= c({4})->({5})", k - 2, arrayc(k - 2), k - 1, arrayc(k - 1), k,
arrayc(k)))

       End If

   End Sub

This is the output
Numbers used
15
17
20
25
a(0)->(15) + a(1)->(17)= b(0)->(32)
b(0)->(32) + a(2)->(20)= b(1)->(52)
b(1)->(52) + a(3)->(25)= b(2)->(77)
==Loop of Sums==
b(0)->(32) + b(1)->(52)= c(0)->(84)
c(0)->(84) + b(2)->(77)= c(1)->(161)
c(0)->(84) + c(1)->(161)= c(2)->(245)

PS.  Thanks to everyone who got me this far.
I sure have learned alot.

TIA
Cor Ligthert - 30 Nov 2004 08:46 GMT
sal,

How many times have I written as answer on this kind of messages, that I
have made a complete sample special for you including the datatable in this
vbnet newsgroup

However it seems you drops only questions.

Cor

"sal" <sal@spp.net>

> Converting array formula to work with datatables/dataset tia sal
>
[quoted text clipped - 83 lines]
>
> TIA
Cor Ligthert - 30 Nov 2004 09:39 GMT
How many times have I written as answer "to you"
sal - 30 Nov 2004 13:33 GMT
I want to take time out to personally thank Cor Ligthert and everyone for
all their help on my issues.  To answer Cor question if I got his
responses the answer is yes.  And I'm also continuing to implement the
changes (to datatables) he/she and others have so kindly sent me into the
program.  The above message is a formula I had to make using arrary's
because I did not have the technical know how to loop through individual
columns in datatables.  That's what it really comes down to
1) not knowing how to loop through  datatables columns
2) not knowing the equivialent getupperbound method found in array's for
use in datatables.

If I offended anyone in anyway I sincerely apologize

I know the holiday season gets many people tense just remember.
"Don't sweat the little stuff, oh yea it's all little stuff"

;-)
Love and Joy
Sal

> sal,
>
[quoted text clipped - 97 lines]
>>
>> TIA
Cor Ligthert - 30 Nov 2004 15:00 GMT
Sal,

> 1) not knowing how to loop through  datatables columns

Than ask that in the same thread as is the first question.

It is now very unusefull sending you a sample and seeing you going another
direction and than come back with the same question you started the first
time and confirming my answer in a new message thread, while I spent time
making an sample special fitted on your question.

\\\
for i as integer = 0 to mydatatable.rows.count -1
   for y as integer = 0 to mydatatable.rows(i).columns.count - 1
       myvalue = datatable.rows(i).items(y)
   next
next
///

Seems quiet simple for me.

Cor
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.