Click to See Complete Forum and Search --> : a problem involving between two forms


ariel_au
April 1st, 2001, 10:19 AM
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

d.paulson
April 1st, 2001, 10:54 AM
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

shree
April 1st, 2001, 10:57 AM
'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.

Iouri
April 2nd, 2001, 08:22 AM
'Make sure that frmCustom is loaded

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



Iouri Boutchkine
iouri@hotsheet.com

ariel_au
April 2nd, 2001, 10:48 AM
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.

ariel_au
April 2nd, 2001, 11:31 AM
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?

ariel_au
April 2nd, 2001, 11:57 AM
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.

shree
April 2nd, 2001, 12:20 PM
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.