Results 1 to 2 of 2

Thread: Help with Sub Function and calling it from main Function

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default Help with Sub Function and calling it from main Function

    I am creating a program for tower. I have some cases 1 to 8. when I am calculating the FOS at that type I have to call those cases every time then the program is lenghty. I am writing my code. I want to convert it to cases through function and the calculating time How I call that function value like.... RMin, RMed, RMax, SEction & KgM. How will Code comes. Can somebody help me. Give me the sub to function procedure and How will I call them by Calculation time.


    Code:
    Private Sub SEcVar()
    Select Case Number    ' Evaluate Number.
    
    Case 1   ' Number is 1 and Section is 40x40x3
    RMin = 0.77
    RMed = 1.21
    RMax = 1.54
    SEction = "40x40x3"
    SqCm = 2.34
    KgM = 1.8
    
    Case 2   ' Number is 2 and Section is 40x40x4
    RMin = 0.77
    RMed = 1.21
    RMax = 1.53
    SEction = "40x40x4"
    SqCm = 3.07
    KgM = 2.4
    Case 3   ' Number is 3 and Section is 40x40x5
    RMin = 0.77
    RMed = 1.2
    RMax = 1.51
    SEction = "40x40x5"
    SqCm = 3.78
    KgM = 3#
    
    Case 4   ' Number is 4 and Section is 40x40x6
    RMin = 0.77
    RMed = 1.19
    RMax = 1.5
    SEction = "40x40x6"
    SqCm = 4.47
    KgM = 3.5
    
    Case 5   ' Number is 1 and Section is 45x45x3
    RMin = 0.87
    RMed = 1.38
    RMax = 1.74
    SEction = "45x45x3"
    SqCm = 2.64
    
    Case 6   ' Number is 2 and Section is 45x45x4
    RMin = 0.87
    RMed = 1.37
    RMax = 1.73
    SEction = "45x45x4"
    SqCm = 2.64
    
    Case 7   ' Number is 3 and Section is 45x45x5
    RMin = 0.87
    RMed = 1.36
    RMax = 1.72
    SEction = "45x45x5"
    SqCm = 2.64
    
    Case 8   ' Number is 4 and Section is 45x45x6
    RMin = 0.87
    RMed = 1.35
    RMax = 1.7
    SEction = "45x45x6"
    SqCm = 2.64
    
    Case Else    ' Other values.
    End Select
    
    End Sub
    and main sub (Calculation time)


    Code:
    Private Sub towerpoints1()
    Dim DesignLen As Variant
    DesignLen = ((Panelh1 / 4) / 10#)         'Calculate L
    Dim Curve As Integer
    Dim C As Variant
    Curve = TextBox3.Value
    C = TextBox2.Value
    Dim KLR As Variant
    
    Dim LR As Variant
    Dim ISec As Integer
    Number = 1
    Dim UCS As Variant
    Dim Fa As Variant
    'SEcVar
    Do While fos < 1.1     'And fos < 1.3
    SEcVar
    LR = DesignLen / RMin
    If Curve = 1 Then
    KLR = LR
    End If
    If Curve = 2 Then
    KLR = (30 + (0.75 * LR))
    End If
    If Curve = 3 Then
    KLR = (60 + (0.5 * LR))
    End If
    If Curve = 4 Then
    KLR = LR
    End If
    If Curve = 5 Then
    KLR = (28.6 + (0.762 * LR))
    End If
    If Curve = 6 Then
    KLR = (46.2 + (0.615 * LR))
    End If
    Fa = (2600 - (0.083969944 * (KLR ^ 2)))
    UCS = Fa * SqCm
    fos = UCS / C
    Number = Number + 1
    Loop
    Debug.Print "Section Selected is =  " & SEction
    Debug.Print "Design Length = " & DesignLen
    Debug.Print "KgM  =  " & KgM
    End Sub
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]
    Last edited by Opie; 2006-06-21 at 01:32 PM. Reason: [CODE] tags added, see moderator comment

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Help with Sub Function and calling it from main Function

    I had a little trouble understanding your question and the example you provided is not clear to me, but here's what I can tell you about creating a function.

    Code:
    'define the function
    Public Function CalcFOS (Rmin As Double, Rmed As Double, Rmax as Double, Section as String, SqCm as Double, Kgm as Double)
      'in your calculations, use the argument varibles as you would if you had Dim'ed variables
       'cause the function to return a value
       CalcFOS = Rmin * Rmax 'or whatever
    End Function
    
    'call the function, supplying values for the arguments
    Case 1 
      MyNewValue = CalcFOS( 0.77, 1.21, 1.54, "40x40x3", 2.34, 1.8)
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Replies: 8
    Last Post: 2018-08-18, 02:53 PM
  2. Calling a LISP function in many drawings
    By daniel.j.wright112877 in forum AutoLISP
    Replies: 12
    Last Post: 2012-10-05, 09:48 PM
  3. Change the F1 function key to perform some other function
    By Spanky in forum AutoCAD Customization
    Replies: 7
    Last Post: 2007-11-28, 04:14 PM
  4. Replies: 41
    Last Post: 2007-11-20, 12:32 AM
  5. IF Function
    By avinash00002002 in forum VBA/COM Interop
    Replies: 4
    Last Post: 2006-06-23, 12:46 PM

Posting Permissions

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