The title may be misleading but here is what I am trying to do in my app:
A menu item (from the menu editor) adds a form and other controls, then allows a variable to a set a value to be used throughout the application. However, I want the user to be able to change the value when needed without leaving the program. But if the user clicks the menu item again, it will try to add the form again and throws an error. I understand that and am hoping I can add code somewhere that will prevent it. I have tried to add a counter that would bypass the 'addform' command and simply show the form again containing the previous value but that isn't working. I can always add another menu item to only 'show the form' but that seems like poor programming. Just closing the form doesn't work. Here is the code:
I can do it without having a menu item but I would need to add textboxes on the forms being affected and the space is limited. Any solution would also apply to other items I am comtemplating. I suspect the answer is pretty easy but I have a tendency to overlook those. Thanks for any help and Happy New Year to all.
Jim Schuchert
A menu item (from the menu editor) adds a form and other controls, then allows a variable to a set a value to be used throughout the application. However, I want the user to be able to change the value when needed without leaving the program. But if the user clicks the menu item again, it will try to add the form again and throws an error. I understand that and am hoping I can add code somewhere that will prevent it. I have tried to add a counter that would bypass the 'addform' command and simply show the form again containing the previous value but that isn't working. I can always add another menu item to only 'show the form' but that seems like poor programming. Just closing the form doesn't work. Here is the code:
B4X:
Sub mnuDistMult_Click
If intcounter > 0 Then frmdistmult.show [color=red] 'global variable set to 0 when app opens'[/color]
AddForm("frmDistMult","Distance Multiplier")
frmdistmult.color=cSilver
frmdistmult.show
AddTextBox("frmdistmult","txtdm",40,20,50,20,"1")
AddLabel("frmdistmult","lbldm",40,45,50,20,"Dist Mult")
lbldm.color=cSilver
AddButton("frmdistmult","btnDM",125,20,50,20,"OK")
AddButton("frmdistmult","btnDMMenu",125,50,50,20,"Menu")
AddLabel("frmdistmult","lbldminfo",40,80,150,40,"")
lbldminfo.color=cSilver
intcounter=intcounter+1 [color=red] 'increments counter' [/color]
End Sub
Sub btndm_click
sngdm=txtdm.text [color=red] sets a value that should be able to be changed [/color]
lbldminfo.text="All entered distances will now be multiplied by " & sngdm
End Sub
Sub btndmmenu_click
frmdistmult.close
frmmenu.Show [color=red] 'this is the main menu...not from the menu editor[/color]
End Sub
I can do it without having a menu item but I would need to add textboxes on the forms being affected and the space is limited. Any solution would also apply to other items I am comtemplating. I suspect the answer is pretty easy but I have a tendency to overlook those. Thanks for any help and Happy New Year to all.
Jim Schuchert