Help with loop and matrix in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erykewell
    New Member
    • Feb 2008
    • 1

    Help with loop and matrix in VB6

    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:

    [CODE=vb]
    For m = 3 To txtNmbrOfSleepe r.Text Step 1
    DeflecRHS(m) = (2 + (T / k)) * DeflecRHS(m - 1) - DeflecRHS(m - 2)
    Next DeflecRHS

    For n = 2 To txtNmbrOfSleepe r.Text Step 1
    ForceRHS(m) = k * (DeflecRHS(m) - DeflecRHS(m - 1))
    Next ForceRHS

    StifnessRHS = ForceRHS / DeflecRHS[/CODE]

    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.
    Last edited by Killer42; Feb 12 '08, 09:44 PM. Reason: Added CODE=vb tag
  • Bum
    New Member
    • Jan 2008
    • 19

    #2
    Use a bubble sort:

    [CODE=vb]Sub BubbleSort(List () As Long, ByVal min As Integer, _
    ByVal max As Integer)
    Dim last_swap As Integer
    Dim i As Integer
    Dim j As Integer
    Dim tmp As Long

    ' Repeat until we are done.
    Do While min < max
    ' Bubble up.
    last_swap = min - 1
    ' For i = min + 1 To max
    i = min + 1
    Do While i <= max
    ' Find a bubble.
    If List(i - 1) > List(i) Then
    ' See where to drop the bubble.
    tmp = List(i - 1)
    j = i
    Do
    List(j - 1) = List(j)
    j = j + 1
    If j > max Then Exit Do
    Loop While List(j) < tmp
    List(j - 1) = tmp
    last_swap = j - 1
    i = j + 1
    Else
    i = i + 1
    End If
    Loop
    ' Update max.
    max = last_swap - 1

    ' Bubble down.
    last_swap = max + 1
    ' For i = max - 1 To min Step -1
    i = max - 1
    Do While i >= min
    ' Find a bubble.
    If List(i + 1) < List(i) Then
    ' See where to drop the bubble.
    tmp = List(i + 1)
    j = i
    Do
    List(j + 1) = List(j)
    j = j - 1
    If j < min Then Exit Do
    Loop While List(j) > tmp
    List(j + 1) = tmp
    last_swap = j + 1
    i = j - 1
    Else
    i = i - 1
    End If
    Loop
    ' Update min.
    min = last_swap + 1
    Loop
    End Sub
    [/CODE]
    Hope this helps,

    B
    Last edited by Killer42; Feb 15 '08, 02:26 AM.

    Comment

    Working...