|
It has nothing to do with your problem. See the answer of David below.
|
|
|
|
|
Member 14575556 wrote: MedicineDlg MedicineObj;
MedicineObj.ResetListControl();
MedicineObj.DatabaseReload(); This will not work as it is not the same instance of MedicineDlg that was created in OnBnClickedSelectButton() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Please give some direction how to solves this problem.
Thank you.
|
|
|
|
|
You should redesign your project architecture to not directly access one dialog controls from another one.
|
|
|
|
|
I would be inclined to change how the data was presented. What you have:
List of data
+---Details of an item in the list
+---Editable view of that item seems a bit convoluted. I just see too many places for errors, and possibly maintainability.
At a minimum, I would combine the last two items. That would go a long way toward solving your immediate problem.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi
I have a Data Type of BYTE defined as
typedef unsigned char BYTE; when I want to define 2 bytes I do BYTE itshort[2];
if I want a switch value to compare for 2 bytes I do switch ((short) itshort[0]) seems like it will only do the compare for the first byte any way to make it two bytes
Thanks
|
|
|
|
|
The switch argument needs to be a "simple" type, so you should glue your two bytes together into a 16-bit value. You'll need to do something similar with your case values too.
Something like
unsigned short testval = itshort[0] | (itshort[1] << 8);
switch (testval)
{
case value1[0] | (value1[1] << 8):
....
It might be easier to just use unsigned short all round.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
You could use a union To get the 16 bit value.
union _bands
{
BYTE bValues[2];
SHORT sValue;
};
You can then use sValue to refer to the 16 bit number.
|
|
|
|
|
|
(short) is just a type cast. All it does is tell the compiler to interpret the value as a different type. The value in this case is just the single character itshort[0]. What you intended to do was something dofferent: you wanted the computer to reinterpret the memory starting at itshort[0]. But there is no way for the compiler to understand that is what you want.
As others pointed out, there are ways to achieve this. However, why don't you simple use short or unsigned short?
typedef short itshort; If you don't trust the compiler to use 16 bit values for short, you can also use size-specific types. E. g. Microsoft offers __int8, __int16, etc. for these purposes. See __int8, __int16, __int32, __int64 | Microsoft Docs[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I thought casting it to a short would force the compiler to do a 2 byte compare
thanks
|
|
|
|
|
The C standard fixed size integer units is called stdint.h to use it is as simple as
#include <stdint.h>
<stdint.h>[^]
Doesn't matter what platform you write your code on your signed and unsigned ints are the right size and it is the industry standard way to deal with it rather than your own macros of typedefs.
In vino veritas
|
|
|
|
|
The code I write here on Windows I am hoping to execute on Z/OS as well using XL C\C++ compiler I have ensure that int, short, and long sizes are consistent I will regardless have a number #ifdef zos and #ifdef MSVC for the I/O reads etc besides that I have to do memory moves in big endian as its a z/os mainframe file I am processing
Thanks
|
|
|
|
|
Again you are reinventing the wheel the traditional way to deal with Endian is via the standard ints and you simply do eandian aware reads from files. The output from the reads being big_int16_t or big_uint16_t which are big endian versions.
In vino veritas
|
|
|
|
|
Hello every one please i have a problem when i try to assign the contain of struct array to another as in the code
bool delet(){
Int f=0;
Cout<<"enter name:";
char del[20];
Con.getline(del,20);
for(int i=0; i<=index; ++i){
If(phone[i].name==del){
for(int j=i; j<=index; ++j){
Phone[j].num=Phone[j+1].num;
Phone[j].TphoneN=phone[j+1].TphoneN;
Phone[j].name=Phone[j+1].name;
}
f=1;
}
}
}
<\pre>
|
|
|
|
|
You cannot use the == operator to compare arrays. You need to use strcmp or similar. You
modified 19-Sep-19 2:48am.
|
|
|
|
|
okay i take note thanks.
i still have an error message "invalid array assignment"
|
|
|
|
|
That is because you are assigning arrays to arrays, and that is invalid code in C/C++:
phone[j].num=phone[j+1].num;
phone[j].TphoneN=phone[j+1].TphoneN;
phone[j].name=phone[j+1].name;
You can use the appropriate functions for C strings, e. g. strcpy. But it would be much better if you just used std::string instead of C strings!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
It is a pseudo-code?
Could you instead post a compilable and properly formatted code snippet?
Or, at least, explain what errors or other problems you have with this code?
|
|
|
|
|
 no it is not a pseudo code am trying to write a program that can register a contact, delete or update the contact. so when i compile the is an error message "invalid array assignment" within the the delete function which is the code i posted before. the complete code is
<pre>#include<iostream>
#include<conio.h>
#include<string.h>
#include<fstream>
using namespace std;
enum type{ home,work,fax,mobile,other };
struct contact{
char num[15];
char name[20];
char TphoneN[6];
}phone[5];
const int max=5;
int index=0;
bool reading(){
char v;
if(index<=5){
cout<<"please enter phone number: ";
gets(phone[index].num);
cout<<"please enter the name: ";
gets(phone[index].name);
cout<<"the type of number( fax, mobile, home, work, other): ";
gets(phone[index].TphoneN);
index++;
return true;
}
else
return false;
}
bool delet(){
int flag=0;
cout<<"please enter the name of the person u wanna delete: ";
char del[20];
cin.getline(del,20);
for(int i=0; i<=index; ++i){
if(phone[i].name==del){
for(int j=i; j<=index; ++j){
phone[j].num=phone[j+1].num;
phone[j].TphoneN=phone[j+1].TphoneN;
phone[j].name=phone[j+1].name;
}
flag=1;
}
}
if(!flag){
return false;
}
else{
index--;
return true;
}
}
void all(){
for(int i=0; i<=index; ++i){
cout<<phone[i].name<<"\t"<<phone[i].num<<"\t"<<phone[i].TphoneN<<endl;
cout<<"\n";
}
}
int main(){
int x;
while(!0){
cout<<"****"<<index<<"contact entries **** \n";
cout<<"0 end \n1 new contact \n2 delete contact \n3 all contact \n4 empty contact memory";
cin>>x;
switch(x){
case 1:
bool y=reading();
if(y==true){
cout<<"contact successfuly saved";
}
else
cout<<"an error accure could not save your contact";
break;
case 2:
bool y=delet();
if(y==true){
cout<<"contact successfuly deleted";
}
else
cout<<"sorry your name does not exist";
break;
case 3:
all();
break;
case 4:
cout<<"still searching";
break;
default:
cout<<"sorry invalid key";
break;
}
}
}
|
|
|
|
|
If you are using C++ then a std::string is better option than an array of characters.
|
|
|
|
|
Hello Everyone, I have some doubt regarding below code snippet.
MyDlg::MyDlg(CWnd* pParent )
: CDialogEx(IDD_DLG, pParent)
, m_Name(_T(""))
, m_Status(_T(""))
, m_Comments(_T(""))
{
}
Please explain why m_Name(_T("")),m_Status(_T("")),m_Comments(_T("")) is there.
Thank you.
I'm new to MFC VC++.
|
|
|
|
|
What you see here is a member initialization list
It is (almost) equivalent to initialization within a ctor like:
MyDlg::MyDlg(CWnd* pParent /=NULL/)
: CDialogEx(IDD_DLG, pParent)
{
m_Name = _T("");
m_Status = _T("");
m_Comments = _T("");
}
|
|
|
|