Results 1 to 22 of 22

Thread: how to use Module for functions/temp data?

  1. #1

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    how to use Module for functions/temp data?

    Hello, im still fresh in VB programming.

    I need help to use module.bas in VB6 to declare some repeated variables and functions in many forms and also to use module as temporary data storage.
    I' developing software to analyze and design torsion reinforcement in reinforced concrete.

    Is there anyone can provide tutorial/example for me to develop it myself?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to use Module for functions/temp data?

    Welcome to the forums.

    Using modules is a pretty fundamental part of Visual Basic....what specifically are you having problems with?

  3. #3

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    Thank You,

    1st,
    I got two or more forms that related to each other. Lets say, 1st form(ie. frm_input) is to calculate design requirement data and 2nd form(ie. frm_bar) is to calculate the required bar size from the requirement. So, how do i'm going to retrieve data from frm_input to be use in frm_bar?

    2nd,
    Is it possible to declare repeated variables in other forms in module?
    Variables such as "fck" and "fyk" are being use in many forms. I want to declare the variables in the module so that i dont have to repeat in many forms. Please show me code example to declare the variables.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to use Module for functions/temp data?

    You declare variables in a module the same way you do on a form. The only difference is that they are declared Public rather than Private.

    The same with Subs and Functions.

    Example: On Form1 you have a string variable called Hack
    Code:
    'on form1
    Option Explicit
    
    Private Hack As String
    This variable can now be used anywhere on your form.

    Now, lets take this one step further and make this a variable to that can be used anywhere in your whole project. That step is simple. Remove the declaration from Form1, and in a module simply do
    Code:
    'on Module.bas
    Option Explicit
    
    Public Hack As String

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to use Module for functions/temp data?

    Welcome to VBForums.

    Note that if you delare a Public Variable in a Module, that Variable will be the same througout the whole program, unlike the case where you declare Variables of the same NAME on each Form, in this case they are different!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    OK, now that i understand to declare variables in module, but my 1st question still unanswered. Is there a way for other form to retrieve information from other form?

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to use Module for functions/temp data?

    Yes
    for example you have on Form1 a variable named MyInteger. You can access this one from Form2 by using this syntax: Form1.MyInteger
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    Thank you, now i understand. I'll have to make the value into another variable so that it can be read from other form. I'll post again if other problems occur during the coding process

  9. #9

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    Quote Originally Posted by opus View Post
    Yes
    for example you have on Form1 a variable named MyInteger. You can access this one from Form2 by using this syntax: Form1.MyInteger
    It didn't work. There is a message error pop up displaying "Method or data member not found"

    this example of my code:

    from form_input
    Code:
    K = (m * 10 ^ 6) / (fck * b * d ^ 2)
    
    Else
    'check for bending
            If K <= Kbal Then
            form_checking.lbl_display1.Caption = "K = " & Format(K, "0.00") & " <= Kbal = 0.167" _
            & vbNewLine & "Tetulang mampatan tidak diperlukan."
            data_k = K
        Else
            form_checking.lbl_display1.Caption = "K = " & Format(K, "0.00") & " > Kbal = 0.167" _
            & vbNewLine & "Tetulang mampatan diperlukan dan dimasukkan di dalam rekabentuk." & _
            vbNewLine
                If d_ratio <= 0.171 Then
                fsc = 0.87 * fyk
                form_checking.lbl_display2.Caption = "Tetulang mampatan mengalami alahan, " _
                & vbNewLine & "fsc = " & Format(fsc, "0.00") & " " & "N/mm2" & vbNewLine
                Else
                fsc = (200 * 10 ^ 3) * eps_sc
                form_checking.lbl_display2.Caption = "Tegasan di dalam tetulang mampatan harus dikira," _
                & vbNewLine & "fsc = " & Format(fsc, "0.00") & " " & "N/mm2" & vbNewLine
                End If
            data_k = K
    End If
    from form_bar
    Code:
    K = form_input.data_k
    
    If K <= Kbal Then
        If A_req > bar_area Then
        form_checkbar.lbl_display1.Caption = "Sila sediakan saiz tetulang yang lebih besar"
        Else
        form_checkbar.lbl_display1.Caption = "Sediakan " & Format(No_bar, "##") & " " & _
        "bar" & "H" & Format(d_bar, "##") & " ,luas =" & Format(bar_area, "000") & " " & "mm2"
        End If
    Last edited by livedlooz; Apr 14th, 2009 at 12:41 PM.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to use Module for functions/temp data?

    What did you do that didn't work?

  11. #11

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    procedure for retrieving value K from form_input to form_bar does not occur

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to use Module for functions/temp data?

    I do not see where value K is ever declared or ever called for.

    Is it declared in a module that you are not showing?

  13. #13

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    yes, it declared in a module.

  14. #14

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    this is my whole coding for my project

    form_input
    Code:
    Option Explicit
    Dim wu As Single, h As Single, Leff As Single, xbal As Single, theta As Single, max_shear As Single, bcol As Single, _
    theta1 As Single, ved As Single, vrd_max As Single, d_ratio As Single, L As Single, _
    angle As Single, d1 As Single, fsc As Single
    Private Sub cmd_next_Click()
    
    'input data
    fck = Val(cbo_fck.Text)
    fyk = 500
    wu = Val(txt_load.Text)
    m = Val(txt_momendes.Text)
    b = Val(txt_b.Text)
    d = Val(txt_d.Text)
    L = Val(txt_span.Text)
    d1 = Val(txt_d1.Text)
    theta = Val(txt_theta.Text)
    Leff = Val(txt_span.Text)
    bcol = Val(txt_column.Text)
    
    'checking formula
    xbal = 0.45 * d
    max_shear = wu * (Leff / 2)
    ved = max_shear - (wu * bcol / 2000)
    vrd_max = 0.124 * b * d * (1 - (fck / 250)) * fck * 10 ^ -3
    d_ratio = d1 / d
    angle = (ved * 10 ^ 3) / (0.18 * b * d * fck * (1 - (fck / 250)))
    K = (m * 10 ^ 6) / (fck * b * d ^ 2)
    eps_sc = 0.0035 * (d - d1) / d
    
    'angle check
    If theta > 45 Then
        Call MsgBox("Nilai tidak boleh melebihi 45", vbCritical)
        txt_theta.SetFocus
        txt_theta.Text = ""
    Else
    'check for bending
            If K <= Kbal Then
            form_checking.lbl_display1.Caption = "K = " & Format(K, "0.00") & " <= Kbal = 0.167" _
            & vbNewLine & "Tetulang mampatan tidak diperlukan."
            data_k = K
        Else
            form_checking.lbl_display1.Caption = "K = " & Format(K, "0.00") & " > Kbal = 0.167" _
            & vbNewLine & "Tetulang mampatan diperlukan dan dimasukkan di dalam rekabentuk." & _
            vbNewLine
                If d_ratio <= 0.171 Then
                fsc = 0.87 * fyk
                form_checking.lbl_display2.Caption = "Tetulang mampatan mengalami alahan, " _
                & vbNewLine & "fsc = " & Format(fsc, "0.00") & " " & "N/mm2" & vbNewLine
                Else
                fsc = (200 * 10 ^ 3) * eps_sc
                form_checking.lbl_display2.Caption = "Tegasan di dalam tetulang mampatan harus dikira," _
                & vbNewLine & "fsc = " & Format(fsc, "0.00") & " " & "N/mm2" & vbNewLine
                End If
            data_k = K
    End If
    End If
    'check for shear
    If vrd_max >= ved Then
        form_checking.lbl_display3.Caption = "darjah kecondongan adalah sama seperti" & _
        " nilai anggapan yang diberikan." & vbNewLine & Format(vrd_max, "0.000") & _
        " >= " & Format(ved, "0.000")
    Else
        theta1 = 0.5 * ArcSin(angle) * 180 / 3.142
        If ArcSin(angle) = 0 Then
            form_checking.lbl_display3.Caption = "Sila ubah nilai Beban Muktamad " & _
            "dengan nilai yang lebih kecil"
            txt_load.SetFocus
        Else
            form_checking.lbl_display3.Caption = "darjah kecondongan perlu diubah dimana " & _
            "nilai yang lebih besar perlu disediakan." & vbNewLine & "sudut kecondongan = " _
            & Format(theta1, "00.0")
        End If
    End If
    
    'display form
        form_checking.Show
        form_input.Hide
        
    End Sub
    ' Inverse Sine
    Private Function ArcSin(ByVal x As Double) As Double
    
        If Abs(x) < 1 Then
            ArcSin = Atn(x / Sqr(1 - x * x))
        End If
    
    End Function
    form_bar
    Code:
    Option Explicit
    Dim As2 As Single, A_bar As Double, _
    d_bar As Single, No_bar As Single, d_bar2 As Single, spacing As Single, _
    bar_area As Single, As1 As Single, m As Single, _
    z As Single, A_req As Single, bar_area2 As Single, A_bar2 As Single, _
    No_bar2 As Single, fsc As Single, d1 As Single
    
    
    Private Sub cmd_next_Click()
    
    No_bar = Val(cbo_bar.Text)
    d_bar = Val(cbo_size.Text)
    No_bar2 = Val(cbo_bar2.Text)
    d_bar2 = Val(cbo_size.Text)
    spacing = Val(cbo_spacing.Text)
    d = Val(form_input.txt_d.Text)
    fck = Val(form_input.cbo_fck.Text)
    m = Val(form_input.txt_momendes.Text)
    
    'singly reinforcement
    A_bar = Pi * (d_bar ^ 2) / 4
    bar_area = A_bar * No_bar
    z = 0.82 * d
    A_req = m * (10 ^ 6) / (0.87 * fck * z)
    'double reinforcement
    A_bar2 = Pi * (d_bar2 ^ 2) / 4
    bar_area2 = A_bar2 * No_bar2
    As1 = ((K - Kbal) * fck * b * d ^ 2) / (fsc * (d - d1))
    As2 = (0.167 * fck * b * d ^ 2) / (0.87 * fyk * z) + As1
    
    If form_input.data_k <= Kbal Then
        If A_req > bar_area Then
        form_checkbar.lbl_display1.Caption = "Sila sediakan saiz tetulang yang lebih besar"
        Else
        form_checkbar.lbl_display1.Caption = "Sediakan " & Format(No_bar, "##") & " " & _
        "bar" & "H" & Format(d_bar, "##") & " ,luas =" & Format(bar_area, "000") & " " & "mm2"
        End If
    Else
        If form_input.d_ratio <= 0.171 Then
        fsc = 0.87 * fyk
        Else
        fsc = (200 * 10 ^ 3) * form_input.eps_sc
        End If
    'compression reinforcement
        If As1 > bar_area2 Then
        form_checkbar.lbl_display2.Caption = "Sila sediakan saiz tetulang yang lebih besar"
        Else
        form_checkbar.lbl_display2.Caption = "Sediakan " & Format(No_bar2, "##") & " " & _
        "bar" & "H" & Format(d_bar2, "##") & " ,luas =" & Format(bar_area2, "000") & " " & "mm2"
        End If
    'tension reinforcement
        If As2 > bar_area Then
        form_checkbar.lbl_display1.Caption = "Sila sediakan saiz tetulang yang lebih besar"
        Else
        form_checkbar.lbl_display1.Caption = "Sediakan " & Format(No_bar, "##") & " " & _
        "bar" & "H" & Format(d_bar, "##") & " ,luas =" & Format(bar_area, "000") & " " & "mm2"
        End If
    End If
        
    form_barsize.Hide
    form_checkbar.Show
    End Sub
    module
    Code:
    Option Explicit
    'declaration
    Public fck As Single
    Public fyk As Single
    Public d As Single
    Public b As Single
    Public m As Single
    Public data_k As Single
    Public data_fsc As Single
    Public eps_sc As Single
    Public K As Single
    
    Public Function Kbal()
    Kbal = 0.167
    End Function
    
    Public Function Pi()
    Pi = 3.14159
    End Function

  15. #15

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    Please solve the problem i stated above. i still cant find the solution

  16. #16

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    The problem i stated just now was solved because i'm using custom property now.

    from form_input:
    Code:
    Public Property Get K() As Single
         K = data_K
    End Property
    
    Public Property Let K(ByVal val_1 As Single)
        data_K = val_1
    End Property
    from form_bar:
    Code:
    If data_K <= Kbal Then
        If A_req > bar_area Then
        form_checkbar.lbl_display1.Caption = "Sila sediakan saiz tetulang yang lebih besar"
        Else
        form_checkbar.lbl_display1.Caption = "Sediakan " & Format(No_bar, "##") & " " & _
        "bar" & "H" & Format(d_bar, "##") & " ,luas =" & Format(bar_area, "000") & " " & "mm2"
        End If

  17. #17
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to use Module for functions/temp data?

    You were using data_k as if it was declared in Form_Input ("form_input.data_k"), since you declared it Public in a Module you have to refer to it by usingsolely "data_k"!!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  18. #18

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    Quote Originally Posted by opus View Post
    You were using data_k as if it was declared in Form_Input ("form_input.data_k"), since you declared it Public in a Module you have to refer to it by usingsolely "data_k"!!
    I dont understand what are you trying to say. Are you refering to the 1st problem i encounter using variable "data_k" as "form_input.data_k"?

    im still working on my project.. it is almost finish.. except the debugging handler part and the interface.

    Ill post questions if something arise.

  19. #19
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to use Module for functions/temp data?

    I'm refering to the code in your post#14 (not the solution with properties!)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  20. #20

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    lets say that i have a value from a combo box from form_input. do i have to make the function inside module or form_input and declare it public so that the value can be accessed from other form?

  21. #21
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to use Module for functions/temp data?

    You can refer to all items of a combobox from form_input in another form by calling it like: form_input.combobox1.list(number)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  22. #22

    Thread Starter
    New Member livedlooz's Avatar
    Join Date
    Mar 2009
    Location
    Miri, Sarawak, Malaysia
    Posts
    13

    Re: how to use Module for functions/temp data?

    ok.. thank you.. it seems that all code are working smoothly..

Tags for this Thread

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