Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with loop and matrix in VB6

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 12 '08
Hi there people.
I'm a newbie in using Visual Basic and need help with my college project I'm working on. I'm developing a program based on a MATLAB program.

The situations are:

1. How do I sort a matrix using VB6? i.e if I have 2 variables, d1 and d2, I want
sort it that it'll become
[d1 d2]

2. if I have this command:

Expand|Select|Wrap|Line Numbers
  1. For m = 3 To txtNmbrOfSleeper.Text Step 1
  2.   DeflecRHS(m) = (2 + (T / k)) * DeflecRHS(m - 1) - DeflecRHS(m - 2)
  3. Next DeflecRHS
  4.  
  5. For n = 2 To txtNmbrOfSleeper.Text Step 1
  6.   ForceRHS(m) = k * (DeflecRHS(m) - DeflecRHS(m - 1))
  7. Next ForceRHS
  8.  
  9. StifnessRHS = ForceRHS / DeflecRHS
Will the calculation of StifnessRHS be using the values from the loop?
Because there are a lot of calculations in this program that are using values from the loop.

3. How to do a column summation in a matrix?

That's all. Your helps will be greatly appreciated.

Bum Bum is offline
Newbie
 
Join Date: Jan 2008
Posts: 19
#2: Feb 14 '08

re: Help with loop and matrix in VB6


Use a bubble sort:

Expand|Select|Wrap|Line Numbers
  1. Sub BubbleSort(List() As Long, ByVal min As Integer, _
  2.     ByVal max As Integer)
  3. Dim last_swap As Integer
  4. Dim i As Integer
  5. Dim j As Integer
  6. Dim tmp As Long
  7.  
  8.     ' Repeat until we are done.
  9.     Do While min < max
  10.         ' Bubble up.
  11.         last_swap = min - 1
  12.         ' For i = min + 1 To max
  13.         i = min + 1
  14.         Do While i <= max
  15.             ' Find a bubble.
  16.             If List(i - 1) > List(i) Then
  17.                 ' See where to drop the bubble.
  18.                 tmp = List(i - 1)
  19.                 j = i
  20.                 Do
  21.                     List(j - 1) = List(j)
  22.                     j = j + 1
  23.                     If j > max Then Exit Do
  24.                 Loop While List(j) < tmp
  25.                 List(j - 1) = tmp
  26.                 last_swap = j - 1
  27.                 i = j + 1
  28.             Else
  29.                 i = i + 1
  30.             End If
  31.         Loop
  32.         ' Update max.
  33.         max = last_swap - 1
  34.  
  35.         ' Bubble down.
  36.         last_swap = max + 1
  37.         ' For i = max - 1 To min Step -1
  38.         i = max - 1
  39.         Do While i >= min
  40.             ' Find a bubble.
  41.             If List(i + 1) < List(i) Then
  42.                 ' See where to drop the bubble.
  43.                 tmp = List(i + 1)
  44.                 j = i
  45.                 Do
  46.                     List(j + 1) = List(j)
  47.                     j = j - 1
  48.                     If j < min Then Exit Do
  49.                 Loop While List(j) > tmp
  50.                 List(j + 1) = tmp
  51.                 last_swap = j + 1
  52.                 i = j - 1
  53.             Else
  54.                 i = i - 1
  55.             End If
  56.         Loop
  57.         ' Update min.
  58.         min = last_swap + 1
  59.     Loop
  60. End Sub
  61.  
Hope this helps,

B
Reply


Similar Visual Basic 4 / 5 / 6 bytes