Results 1 to 7 of 7

Thread: 2 Dim Arrays

  1. #1
    Guest

    Question

    I am a 'newbie' to VB5. My last programming was about 10 years ago. I wrote a program then in QBASIC to help out in my work. I am now trying to rewrite it in VB5 but I am having problems.

    Can anyone help out ?

    The part of my rewrite I am having difficulty with is an interpolation routine. The routine needs to read in several items of data in a two-dimension array.

    I.e.
    0.01 5 10 15 20 25 30 35
    0.611 0.872 1.227 1.704 2.337 3.166 4.241 5.622

    The number in the top row is temperature and the number in the bottom row is vapour pressure at the temperature above. The two lines of data are therefore related.

    I cannot see how to rewrite this in VB as data, which the routine can access, and then use for the calculation.

    A simplified interpolation routine is below which is in BASIC.

    The data here is arranged thus on the same principle:

    1 2 3 4 6
    1 2 3 4 6

    DEMONSTRATION INTERPOLATION ROUTINE


    LIST

    10 PRINT “LAGRANGIAN INTERPOLATION FOR H GIVEN T”
    11 PRINT
    12 DIM T (5), H (5)
    13 FOR N = 0 TO 4
    14 READ T (N), H (N)
    15 NEXT N
    16 PRINT “ WHAT IS VALUE OF T FOR INTERPOLATION?”
    17 INPUT A
    18 B=0
    19 FOR J = 0 TO 4
    20 X=1
    21 FOR N = 0 TO 4
    22 IF N = J THEN GOTO
    23 X=X (A-T (N))/(T (J))-T (N))
    24 NEXT N
    25 B=B+X*H (J)
    26 NEXT J
    27 PRINT “ RESULT AT THE GIVEN VALUE OF T, Y = “: B
    28 REM DATA FOR INTERPOLATION
    29 DATA 1, 1
    30 DATA 2, 2
    31 DATA 3, 3
    32 DATA 4, 4
    33 DATA 6, 6
    34 END


    ‘SCREEN DUMP RESULTS’


    RUN
    LAGRANGIAN INTERPOLATION FOR H GIVEN T

    WHAT IS THE VALUE OF T FOR INTERPOLATION?
    ? 5
    RESULT AT THE GIVEN VALUE OF T, Y = 5

    STOP AT 34


  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    It sounds like the problem you are having is in the reading of the input data.

    You didn't mention how you are actually going to GET this data into VB considering that writing it in VB means its in a Graphical User Interface.

    1. Is this data kept in a file with 2 seperate lines written to it?
    2. Do you type this data directly into the VB application somehow?
    3. Are you trying to simply redirect the data as strings to the Standard Input of the VB app?

    Without knowing this people won't be able to help you...

    Remember... previously your QBASIC program was a DOS based application that could take Standard Input/Ouput but now you have written it in VB is runs in a windows environment which doesn't exactly have that available.

  3. #3
    Guest

    It sounds like the problem you are having is in the reading of the input data.

    You didn't mention how you are actually going to GET this data into VB considering that writing it in VB means its in a Graphical User Interface.

    1. Is this data kept in a file with 2 seperate lines written to it?
    2. Do you type this data directly into the VB application somehow?
    3. Are you trying to simply redirect the data as strings to the Standard Input of the VB app?

    Without knowing this people won't be able to help you...

    Remember... previously your QBASIC program was a DOS based application that could take Standard Input/Ouput but now you have written it in VB is runs in a windows environment which doesn't exactly have that available.

  4. #4
    Guest
    Thanks for your reply.

    The data is in the body of the program. It will not, and does not need to be changed once it has been written into the program.

    The idea is that when the user enters a value in response to a question, such as what temperature, the interpolation routine then calculates the actual properties based on the data referencing the users input. The resuts of the interpolation is then used further in the overall program.

    Thanks for your help

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I think that's what Gen-X meant.

    How are you going to store this data then? I mean if you just want to keep the data as constants in the code, then what is wrong with the code you have, apart from changing the INPUT statements?

    If you want to keep it in a text file, then you can use OPEN and CLOSE, and GET and PUT statements to read and write data from and to files.

    If you want to keep it in a database, then look at recordsets and data controls.

    How are you planning on storing this data, if you don't want to keep it in the code anymore?
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    You can use a type eg.
    Code:
    Private Type MyType
        Temp As Long
        TheOtherValue as long
    End Type
    
    Private m_Values() As MyType
    
    ' and then, when you fill it...
    Redim Preserve m_Values(10)
    m_Values(0).Temp = 10
    m_Values(0).TheOtherValue = 19
    Something like that...
    Hth
    Hope this helps

    Crazy D

  7. #7
    Guest

    Interpolation Routine QBasic to VB5

    Just a note to say thanks to everyone who replied to my problem. Problem fixed. I am in the process of rewriting the code now, and will post it on the board in the near future.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width