Results 1 to 6 of 6

Thread: loading an array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Post

    is it possible to load an unknown amount of elements into different arrays like this
    r = 20
    l = 72
    For h = 1 To r
    v = (r ^ 2 * r)_
    - (r - h)
    v = l * v
    v = Format(v, "######.##")
    Load one array with h & v here
    load next array with h& v here

    Print one array(h,v) here & vbTab & otherarray(h,v) here
    Next h




    End Sub


  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    I'm not sure i understand fully what you want to do but here goes anyway:

    Using dynamic arrays and the redim statement. Oh, i think only VB6 supports redim.




    Dim FirstArray() As Single 'Or whatever
    Dim SecondArray() As Single
    Dim r As Integer
    Dim l As Integer
    Dim h As Integer
    Dim v As Single
    'then when you need to use the arrays:

    r = 20
    ReDim FirstArray(1 To 2, 1 To r)
    ReDim SecondArray(1 To 2, 1 To r)
    l = 72
    For h = 1 To r
    v = (r ^ 2 * r) _
    - (r - h)
    v = l * v
    v = Format(v, "######.##")
    FirstArray(1, h) = h
    FirstArray(2, h) = v
    SecondArray(1, h) = h
    SecondArray(2, h) = v

    'Print one; Array(h, v); here & vbTab & otherarray(h, v); here
    MsgBox FirstArray(1, h) & FirstArray(2, h) & vbCrLf & SecondArray(1, h) & SecondArray(2, h)
    Next h

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Post print or load

    r is the radius, so I want to print 1 thru 20, which is h, on left side of page,with results one tab to the right of that, then 21 thru 40,which is also h to the right side of the 1 - 20 with results, also with results one tab to the right.this wont show up right, but imagine 1 tab between the first two sets of numbers, then maybe a two or three tab space and then the next set ie. 21 thru 40

    1 58473463 21 8878765
    2 59678687 22 8956565
    3 60765556 23 9065754
    and so on. These are made up numbers just for examples.
    what would I call this sort of prolem so I can look it up.

  4. #4
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    I would do it all in two loops, with one array. The bit i don't understand is that you have "for h = 1 to r" where r is 20, but then you talk about radii of 21 to 40. But forgetting that:

    Dim ResultsArray() As Single 'Or whatever

    Dim r As Integer
    Dim l As Integer
    Dim h As Integer
    Dim v As Single
    'then when you need to use the arrays:

    r = 20
    ReDim ResultsArray(1 To 2 * r)
    l = 72
    For h = 1 To 2 * r
    v = (r ^ 2 * r) _
    - (r - h)
    v = l * v
    v = Format(v, "######.##")
    ResultsArray(h) = v

    Next h

    For h = 1 To r
    MsgBox h & Chr(9) & ResultsArray(h) & _
    Chr(9) & Chr(9) & Chr(9) & _
    h + 20 & Chr(9) & ResultsArray(h + 20)
    Next h


    That would give you the display you are after.


    Note, you don't have to use msgbox obviously, you could print it to a label, or textbox, or file. Whatever suits.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Post Thank you Funkyd77

    Thanks for the help. I messed with it a little bit, and it prints to the form just the way I wanted. I can't figure out how to get it into a textbox. paste it into a project and try it out. Number 40 results come up 0 though. Thanks again for the help. I am not so lost now.
    Option Explicit
    Private Sub Command1_Click()
    Dim ResultsArray() As Single 'Or whatever

    Dim r As Integer
    Dim l As Integer
    Dim h As Integer
    Dim v As Single
    'then when you need to use the arrays:

    r = 20
    ReDim ResultsArray(1 To 2 * r)
    l = 72
    For h = 1 To 2 * r - 1
    v = (r ^ 2 * (ArcCos((r - h) / r))) _
    - (r - h) * (Sqr(2 * (r * h) - h ^ 2))
    v = l * v / 231
    v = Format(v, "######.##")
    ResultsArray(h) = v

    Next h

    For h = 1 To r
    Print h & Chr(9) & ResultsArray(h) & _
    Chr(9) & Chr(9) & Chr(9) & _
    h + r & Chr(9) & ResultsArray(h + r)
    Next h



    End Sub

    'Inverse Cosine
    Function ArcCos(x As Double) As Double
    ArcCos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
    End Function






  6. #6
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post Putting it in a text box

    Just add a textbox to your form, it will be called text1 by default, as in this example. Make sure the "multiline" property is set to true and i would also set the "scrollbars" property to "2 - Vertical"

    then:

    Option Explicit
    Private Sub Command1_Click()
    Dim ResultsArray() As Single 'Or whatever

    Dim r As Integer
    Dim l As Integer
    Dim h As Integer
    Dim v As Single
    Dim TempStr As String
    'then when you need to use the arrays:

    r = 20
    ReDim ResultsArray(1 To 2 * r)
    l = 72
    For h = 1 To 2 * r - 1
    v = (r ^ 2 * (ArcCos((r - h) / r))) _
    - (r - h) * (Sqr(2 * (r * h) - h ^ 2))
    v = l * v / 231
    v = Format(v, "######.##")
    ResultsArray(h) = v

    Next h

    TempStr = ""
    For h = 1 To r

    TempStr = TempStr & h & Chr(9) & ResultsArray(h) & _
    Chr(9) & Chr(9) & Chr(9) & _
    h + r & Chr(9) & ResultsArray(h + r) & vbCrLf
    Next h

    Text1.Text = TempStr


    End Sub

    'Inverse Cosine
    Function ArcCos(x As Double) As Double
    ArcCos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
    End Function

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