CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2001
    Posts
    44

    a problem involving between two forms

    i created 2 forms named "frmMain" and "frmCustom". my problem is i can't get the values from "frmCustom" to be in "frmMain"
    e.g my frmCustom have 2 textboxes and i wanted the values in the two textboxes goes to frmMain.
    well, my code is in below:

    'this is my frmMain.

    option Explicit
    private TotalCols as Integer
    private TotalRows as Integer
    '--------------------------------------------
    private Sub Form_Load()

    TotalCols = frmCustom.CWidth 'here is the problem, as i wanted the values from
    TotalRows = frmCustom.CHeight 'frmCustom to be here...

    Call LoadImagesOnForm

    End Sub
    '-----------------------------------------------------
    private Sub LoadImagesOnForm()
    Dim ImgCount as Integer
    Dim RowCount as Integer
    Dim ColCount as Integer
    Dim FrmScalHghtDiff as Integer
    Dim FrmScalWdthDiff as Integer

    FrmScalHghtDiff = me.Height - me.ScaleHeight
    FrmScalWdthDiff = me.Width - me.ScaleWidth

    me.Height = (imgControl(0).Height * TotalRows) + FrmScalHghtDiff
    me.Width = (imgControl(0).Width * TotalCols) + FrmScalWdthDiff

    for RowCount = 1 to TotalRows
    for ColCount = 1 to TotalCols
    ImgCount = ImgCount + 1

    Load imgControl(ImgCount)


    imgControl(ImgCount).Move (ColCount - 1) * imgControl(0).Width, _
    (RowCount - 1) * imgControl(0).Height

    imgControl(ImgCount).Visible = true

    next
    next
    End Sub




    below is my frmCustom:
    'this is my frmCustom
    'in this form there is 2 textbox named "txtHeight" and "txtWidth"
    'there is also a command button named "cmdOK"

    private Sub cmdOk_Click()
    Dim CHeight as Integer, CWidth as Integer

    CHeight = Val(txtHeight.Text) 'here is the value taken from textbox
    CWidth = Val(txtWidth.Text)
    frmMain.TotalCols = CWidth 'here is the problem area...
    frmMain.TotalRows = CHeight

    If (CHeight * CWidth) Mod 2 <> 0 then
    MsgBox " the values generate an odd number of image;" & vbCrLf & _
    "change Width and/or Height so that their product" & _
    "return an even number.", vbExclamation

    ElseIf (CHeight * CWidth) > 50 then
    MsgBox "Sorry, their product is too big;" & vbCrLf & _
    "change Width and/or Height so that their product" & vbCrLf & _
    "is lower than " & totalImg & ", or change the img Folder on" & vbCrLf & _
    "the main window.", vbExclamation

    End If

    Unload me


    End Sub






  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: a problem involving between two forms

    Here is your problem. In your frmCustom you declare the CHeight and CWidth within the Sub CmdOK. These variables will only be assessable within the sub only. If you declare them as public in the general declarations area, it should work.

    Options Explicit
    Public CHeight as Integer
    Public CWidth as Integer

    Don't forget to remove the declaration of these variable in the cmdOK sub.


    David Paulson

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: a problem involving between two forms


    'this should be your frmMain.

    option Explicit
    public TotalCols as Integer '<--- Changes made here
    public TotalRows as Integer '<--- Changes made here
    '--------------------------------------------
    private Sub Form_Load()

    ' TotalCols = frmCustom.CWidth 'here is the problem, as i wanted the values from
    ' TotalRows = frmCustom.CHeight 'frmCustom to be here...
    '^--You do not need this
    frmCustom.Show vbModal '<--- Add this line
    Call LoadImagesOnForm

    End Sub
    '-----------------------------------------------------
    private Sub LoadImagesOnForm()
    Dim ImgCount as Integer
    Dim RowCount as Integer
    Dim ColCount as Integer
    Dim FrmScalHghtDiff as Integer
    Dim FrmScalWdthDiff as Integer

    FrmScalHghtDiff = me.Height - me.ScaleHeight
    FrmScalWdthDiff = me.Width - me.ScaleWidth

    me.Height = (imgControl(0).Height * TotalRows) + FrmScalHghtDiff
    me.Width = (imgControl(0).Width * TotalCols) + FrmScalWdthDiff

    for RowCount = 1 to TotalRows
    for ColCount = 1 to TotalCols
    ImgCount = ImgCount + 1

    Load imgControl(ImgCount)


    imgControl(ImgCount).Move (ColCount - 1) * imgControl(0).Width, _
    (RowCount - 1) * imgControl(0).Height

    imgControl(ImgCount).Visible = true

    next
    next
    End Sub


    'this is your frmCustom
    'in this form there is 2 textbox named "txtHeight" and "txtWidth"
    'there is also a command button named "cmdOK"

    private Sub cmdOk_Click()
    Dim CHeight as Integer, CWidth as Integer

    CHeight = Val(txtHeight.Text) 'here is the value taken from textbox
    CWidth = Val(txtWidth.Text)
    frmMain.TotalCols = CWidth 'here is the problem area...
    frmMain.TotalRows = CHeight

    If (CHeight * CWidth) Mod 2 <> 0 then
    MsgBox " the values generate an odd number of image;" & vbCrLf & _
    "change Width and/or Height so that their product" & _
    "return an even number.", vbExclamation

    ElseIf (CHeight * CWidth) > 50 then
    MsgBox "Sorry, their product is too big;" & vbCrLf & _
    "change Width and/or Height so that their product" & vbCrLf & _
    "is lower than " & totalImg & ", or change the img Folder on" & vbCrLf & _
    "the main window.", vbExclamation

    End If


    Unload me


    End Sub






    You should add logic that prevents the frmmain from drawing the pictureboxes if the conditions that you check at the end are true.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: a problem involving between two forms

    'Make sure that frmCustom is loaded

    TotalCols = Val(frmCustom.txtWidth.Text)
    from TotalRows = Val(frmCustom.txtHeight.Text)



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Mar 2001
    Posts
    44

    Re: a problem involving between two forms

    thank you.
    well, now it works. but during run time when i input the txtHeight and txtWidth again in frmCustom, the frmMain does not "refresh" the new input values.


  6. #6
    Join Date
    Mar 2001
    Posts
    44

    Re: a problem involving between two forms

    thank you. i agree that i must do a check if the product is greater or small than a certain value.
    but the problem is the value from textbox input will be immediately go to frmMain even b4 i can able to do a check. how shall i prevent this?



  7. #7
    Join Date
    Mar 2001
    Posts
    44

    Re: a problem involving between two forms

    thank you.
    well, now it works. but during run time when i input the txtHeight and txtWidth again in frmCustom, the frmMain does not "refresh" the new input values.






  8. #8
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: a problem involving between two forms

    Do this only after you check the values

    frmMain.TotalCols = CWidth
    frmMain.TotalRows = CHeight

    If these values shouldn't be passed, ask for them again, (You can do this by not unloading the modal form unless the value is correct) or return some default value.


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

Featured