473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:

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.
Feb 12 '08 #1
1 1998
Bum
19
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
Feb 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: SUPER_SOCKO | last post by:
Suppose I have a matrix M x N dimension. Normally, to print all of the elements in the matrix. I write the following codes: Suppose M = 5, N = 4: for(int j=0; j<5; ++j) { for(int k=0; k<4;...
1
by: Newbie1000 | last post by:
Hi all, I have a piece of code that I can't seem to get to work. It compiles OK, but crashes when run :confused: Simplified the code is: Matrix::Matrix(int size){ // Constructor definition...
1
by: shauncarter1 | last post by:
I was recently given this assignment in my introduction to C programming class. I have been working on this problem for hours and I am at my wits end. The following code needs to be produced. ...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
5
by: mohammaditraders | last post by:
Write a program which overloads a binary Minus (-) operator, The program will contain a class Matrix, This class will contain a private data member Array which store int values. The class will...
3
by: crazygrey | last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but it is important to me. I'm implementing a simple code to find the forward kinematics of a robot: #include "stdafx.h"...
1
by: Erik Lind | last post by:
I see a more complicated thread on a similar sounding question, but my question is simpler, I hope. I have a large numpy matrix, initially created as: Mat = zeros((a,b), int) and a smaller...
2
by: Prime8 | last post by:
I've been researching so much about arrays and matrices and such, but it hasn't helped me at all on my program. Everything is either over my head or doesn't help with the specific program I have to...
2
Parul Bagadia
by: Parul Bagadia | last post by:
IDE used is Microsoft Visual C++ 6.0 in the inner loop even when the value of second is 3 it executes that for loop... that should not happen even when we use to conditions for validity of for loop....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.