Query Powerbuilder for some checkbox and input text/singelineedit for showig messagebox - powerbuilder

I have 3 checkboxes and 1 input text.
If I click a checkbox and I enter some text in input text, then I don't want the messagebox to appear.
If I don't click a checkbox but I input text then the messagebox should display.
My question is "How do I do that in Powerbuilder?"
Here is my code:
if Not IsNull(f_na) or Not IsNull(f_dep) or Not IsNull(f_krd) and IsNull (c_ao) then
messagebox ('Perhatian','Kode AO baru harus diisi')
return
end if

If any checkbox being checked will prevent the message from showing after entering text, then:
If it's a SingleLineEdit or MultiLineEdit control, then in the modified event handler of the text control (i.e., a SingleLineEdit control):
String ls_EditControlText
ls_EditControlText = this.Text
// If the text is not empty, and none of the checkboxes are checked, then
// show a message and clear the input
IF NOT IsNull(ls_EditControlText) AND (ls_EditControlText <> "") THEN
// f_na, f_dep, and f_krd are the Checkbox controls
IF NOT (f_na.Checked OR f_dep.Checked OR f_krd.Checked) THEN
MessageBox("Attention", "A new AO code must be filled in")
this.Text = "" // clear the input
END IF
END IF
RETURN
For an Edit or EditMask control on a DataWindow, you would the itemchanged event handler for the DataWindow control:
String ls_EditControlText
ls_EditControlText = data
// If the text is not empty, and none of the checkboxes are checked, then
// show a message and clear the input
IF NOT IsNull(ls_EditControlText) AND (ls_EditControlText <> "") THEN
// f_na, f_dep, and f_krd are the Checkbox controls
IF NOT (f_na.Checked OR f_dep.Checked OR f_krd.Checked) THEN
MessageBox("Attention", "A new AO code must be filled in")
RETURN 2 // Reject the text input data but allow focus to change
END IF
END IF
RETURN 0

Related

Edit Win32 combo box items

I have a combo box with a list of names that are editable through a text box on the same form. How would I go about editing the items that are sitting in the combo box when the user changes the name in the text box? There doesn't seem to be any message to update the strings sitting inside the combo box.
Thanks,
Edit: this is the code thats called when the text changes
void txtNameChange(HWND hDlg)
{
if(SelectedIndex != -1)
{
wchar_t Name[255];
GetDlgItemText(hDlg, txtName, Name, 255);
//need to set the item text of an item at a certain index here
}
}
You cannot rename an item in place. You need to delete the item you wish to modify with the CB_DELETESTRING message, and then insert the new value with the CB_INSERTSTRING message.

Quiz Game / Clicking a button to add text to label

Im making a quiz. And it works like this, When you are answearing a question, you have to click some buttons with text on them to answear.
Example () = button
(G) (L) (O) (R) (I) (O) (U) (S)
And they have to spell glorious in that label correctly. And when they click the answear button, if the label says Glorious, they go to the next level. And if it says something else like Gloirous a message saying wrong answear will come up.
The problem :
The problem is that when i click a button, it adds text to the label.
But when i click another button the previous text dissapears and the new comes in.
I hope you guys understand what i want here! My english is not the best but if you want me to post some code i can do that !;)
You need to save previous text, and append new text to previous.
label.setText(label.text() + newText)
Try this:
[yourLabel setText:[yourLabel.text stringByAppendingString:#"%#", yourButton.text]];
Don't save the text to a label. Display the text in a label, but store it somewhere else.
Create an instance variable "answerString". Append each letter to the answer string, and then display the answer string to your label:
NSString *answerString;
Also, don't write a different IBAction method for each button. Put numeric tags on each button, attach them to the same method, and use the tag number to figure out which button was pressed. Something like this:
typedef NS_ENUM(NSInteger, buttonTags)
{
aButton = 100,
bButton = 101,
cButton = 102
//and so on for the entire alphabet, or for the letters you need
}
- (IBAction) buttonAction: (UIButton *) sender;
{
int button_id = sender.tag;
switch (button_id)
{
case aButton:
answerString = [answerString stringByAppendingString: #"a"];
break;
case bButton:
answerString = [answerString stringByAppendingString: #"b"];
break;
}
answerLabel.text = answerString
}
If you have buttons for all 26 letters it probably makes more sense to do some math on the tag numbers to get the unicode value of each character rather than having a switch statement with 26 cases, but you get the idea.

Message is highlighted in blue in Modal box in VC++

We are using below code to populate the messages in a dialog box, when the message appears the message is highlighted in blue - it's like we selected the message using the mouse. i want it the messages not to select when it appears. Anybody can help me on this issue.
CDialog::OnInitDialog();
CFont *m_pFont = new CFont();
LOGFONT lf;
memset(&lf, 0,sizeof(LOGFONT));
lf.lfHeight = 16;
lf.lfWeight = FW_BOLD;
strncpy_s(lf.lfFaceName,"Arial",6);
m_pFont->CreateFontIndirectA(&lf);
GetDlgItem(IDC_EDIT1)->SetFont(m_pFont,TRUE);
m_message.SetWindowTextA((LPCTSTR)Message);
return TRUE;
The selection will be set to all the text whenever the edit box becomes the selected item. If the edit box is the first in the tab order, or if you tab to it or click on it, all the characters are selected. You can override this behavior by capturing the EN_SETFOCUS event and resetting the selection yourself:
void CMyDlg::OnEnSetfocusEdit1()
{
m_edit1.SetSel(0, 0); // or (-1, -1) to set the selection at the end
}

CMFCPropertyGridProperty with multi line edit box

How to create a multi line property with edit box? I need one more property that will show text in multi line box.
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Appearance"));
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), (_variant_t) _T(""), _T("Specifies the text that will be displayed in the property")));
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Comments"), (_variant_t) _T(""), _T("Specifies the text that will be associated with the property")));
m_wndPropList.AddProperty(pGroup1);
It seems that multi-line properties are not implemented in MFC Property Grid. You can create a custom property with a button and show your own dialog with multi-line edit control when user click this button.
You can do it like in old style editors (replacing "\n","\n" so user can divide lines by "\n"):
Initialization:
CString s = m_initial_params.m_info;
s.Replace("\n","\\n");
CMFCPropertyGridProperty* pProp = new
CMFCPropertyGridProperty(misc_get_str_my(IDS_INFO),
(_variant_t) s, misc_get_str_my(IDS_INFO));
pProp->SetData(E_PROPERTY_DATA::OBJ_INFO);
pPropCtrl->AddProperty(pProp);
Reading Value:
int nProperty = pProperty->GetData();
if(E_PROPERTY_DATA::OBJ_INFO == nProperty)
{
m_initial_params.m_info = pProperty->GetValue().bstrVal;
m_initial_params.m_info.Replace("\\n","\n");
}

Form input validation, multiple focus issues

I am having an issue trying to validate some input in QT4.
I have a form with 2 textEdit fields. When one field loses focus, I want it to check if the field is empty, and if so, alert the user.
Here is my code:
void newconsole::on_nameEdit_lostFocus()
{
if (this->ui->nameEdit->text().size() < 1)
{
QMessageBox b;
b.setText("Name must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
void newconsole::on_fileextensionEdit_lostFocus()
{
if (this->ui->fileextensionEdit->text().size() < 1)
{
QMessageBox b;
b.setText("File extension must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
My issue is that when I run the form and lose focus on the first textEdit (nameEdit) I get a MessageBox from BOTH signals. Any suggestions?
my guess would be:
your edit boxes are positioned close to each other on the form or/and next to each other in the tab order;
both edit boxes are empty by default;
when you're moving focus from the empty nameEdit to the next widget which is fileextensionEdit, first message box pops up;
this message box causes fileextensionEdit also to lose focus and since it's empty a second message box gets displayed.
hope this helps, regards

Resources