|
I want the following code(it's a part from a long one) search or check a required qau., is it avaliable in the array,I did it by the if statement ,and it runs,but I want it to be done by another select or conditional one,for example by(switch or )(if /else )or another one.
Please answer it, because I did my try with( switch/case) but I failed to run it .
cout<<"\nEnter the Required_Qauntity:\n";<br />
cin>>Required_Quantity;<br />
if(Required_Quantity > x[index][1] || Required_Quantity <=0) <br />
{cout<<"\nThe avaliable Quantity in the store is "<<x[index][1]<<" part(s). Please ,enter a suitable quantity.\n";<br />
Goto f;<br />
}<br />
else <br />
cout<<"\nThe Required_Quantity is available in the store.\n";
|
|
|
|
|
use if(...) for validating multiple conditions,
There is no such thing as select in c++ , yeah there is switch statement.
-Prakash
|
|
|
|
|
Thanks, TOXCCT , Maximilien Lincourt, Prakash, VuNic, codito ergo sum ,for your considerable replays, what I mean is ,if I’ve a c++ program to search for a required quantity in a store I did it by if /else statement:
cout<<"\nEnter the Required_Qauntity:\n";
cin>>Required_Quantity;
if(Required_Quantity > x[index][1] || Required_Quantity <=0)
{cout<<"\nThe avaliable Quantity in the store is "<
|
|
|
|
|
you mean this? for multiple condtions, switch case is best.
it gives more readability.
VuNic
|
|
|
|
|
but you have to take not that the switch() works only for integer types...
never do this :
char* pszString = "Hello...";
switch (pszString) {
case "Hello":
break;
case "World":
break;
default:
}
this is bad !!!!!!
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
yeaa tox , that's really bad about it
VuNic
|
|
|
|
|
you can use strings in a switch
when the text is limited to 4 char
thats how the ftp, telnet and email server work,
they all use 4 letter commands to work
char szCmd[80];
unsigned long* pulCmd = &szCmd;
switch(*pulCmd)
{
case 0x706c6568:
Help();
break;
case 0x74697571:
Quit();
break;
case 0x6e65706f:
Open();
break;
}
codito ergo sum
|
|
|
|
|
good 'new's.
VuNic
|
|
|
|
|
Hi
The scenario here: Have a static member function defined in a base class which is being overridden in the derived class. This overloaded static member function needs to use a non static member variable.
So, as of now, trying not to change the signature of the static member function since it is part of the WTL - CDialogResize<t>.
As of now, workaround:
Since I am unable to pass the non static member as an parameter to the function without changing the signature of the function in the derived class as well as the base class, created a static member that stores the non static member value which I then use during the execution of the static function.
The problem here is that the value becomes static. So, even for a different instance of the same class, this values gets updated. This is not a preferred behavior in this case. Any tips would be appreciated.
Regards
Aruna
|
|
|
|
|
arunaas wrote: This overloaded static member function needs to use a non static member variable.
By definition, a static method cannot do that. It sounds like you're trying to work around a design problem by making more design problems, honestly.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi Mike
You are right. It is a design problem. I am trying to use the CDialogResize<t> WTL class as a base class. The static member function which I am trying to overload is GetDlgResizeMap() (Macro implemented)
I am deriving from CDialogResize<t> since I need to be able to make certain controls visible and some not visible at run time. Also, this was need to force paint on certain controls. The product was built using WTL. So, trying to use what is available and not trying to use new MFC or other classes.
If I just include the control as part of the macro map even though some of them are not visible(that actually implements the GetDlgresizeMap() function) CDialogResize does not understand that these controls are not visible and it starts trying to resize these which screws up the UI view. So, I need to manually either map these controls or not map them based on their visibility constraints.
So, I overloaded the #Define macro maps for BEGIN_DLGRESIZE_MAP and others to be able to map based on visibility constraints.
So, what else can I do? Please advise. Maybe , I can implement a new version of CDialogresize<t> from scratch....Do let me know your thoughts or comments...
By the way: Mike, your code snippets on the usage of CDialogResize<t> and other WTL classes were very helpful! Thanks for the same!
Regards
Aruna
|
|
|
|
|
such as:
UINT u=which_function_can_convert("FF00FF");
thx
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
Use strtoul() .
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
UINT u = strtoul("0xFF00FF", NULL, 16);
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
In a puzzle game, I dont know the size of the puzzle, how do I know the index number of the target element for swapping, at this moment I just know the index number of h is (hrow, hcol).
Am I wrong if I think this way?
e.g.
C | B
A | h
Assume the location of h at the keyboard is always on 5, then I hit 4 to swap h with A, hit 8 to swap B with h, and hit 7 to swap C with h.
For swapping A
tar_row = hrow;
tar_col = --hcol;
For swapping B
tar_row = --hrow;
tar_col = hcol;
For swapping C
tar_row = --hrow;
tar_col = --hcol;
Am I wrong?
|
|
|
|
|
eivanlo wrote: Am I wrong?
Maybe. However, to be completely sure, I would not rely on the operator -- precedence in an assignment, (such as tar_row = --hrow; ), but take two steps to do it (tar_row = hrow; hrow--; )
~RaGE();
|
|
|
|
|
Hi to all,
I made a deep search in this and other sites about serial communications management in Win32 (Win9X,2000,XP)
All the results leads to using ReadFile and the other file-style functions
But is any way to use interrupts (int of received char) on Windows?Must I create a device drivers?
Thanks to all
Cristian
|
|
|
|
|
misturas wrote: ReadFile
Mmmh .. .really ? What are you trying to achieve exactely ?
~RaGE();
|
|
|
|
|
Yes, sure. What is the problem with that ? Reading and writing data on the serial port is done with ReadFile and WriteFile.
|
|
|
|
|
Hi Cedric,
I was doubting the fact that ReadFile and WriteFile was the _only_ method provided to read/write data under Windows. Not that it does not work.
~RaGE();
|
|
|
|
|
|
I use Visual C++ 6.0 and I studied the article "Serial Communications in Win32" of msdn
My question is a question my boss made me I know it's not very easy to interact with hardware at low level on Windows and all the articles I found uses overlapped operation and ReadFile/WriteFile to read/write COM ports
Now in Italy is 6 p.m., so I have to leave office
Sorry if I don't reply immediately
Thanks in advance
|
|
|
|
|
misturas wrote: Now in Italy is 6 p.m
Really ? I am sitting in Germany, and it is still 5 p.m. Did not know that Germany had a different time than Italy.
As for serial communication, there are lots of wrappers that consider the serial port as a file with read/write operation. This is very handy for serial communication, but not for your purposes. I think what you are looking for is a way to get the hand when a serial interrupt is called (as we used to do under DOS or on microcontrollers). I think this should be feasible with the API I have provided you with, in this case you must get a Windows message as soon as something lands on the serial buffer.
~RaGE();
|
|
|
|
|
Maybe it would help a lot if you describe exactly what you want to achieve. In general, reading and writing to a serial port can be done by several ways (specifically for reading). You can use a loop with timeouts (in a separate thread for example), ...
But if you want to really respond when there is an interuption, then you'll need to go for a device driver (and I suppose it must be tricky to do).
Anyway, even inside your driver, you will still have the problems of the real-time behavior, which is that Windows is not a real time operating system, so everything you want to achieve under the resolution of 10 msec (it can vary) is unfeasible.
|
|
|
|
|
If you want to be notified on receipt of a char, you can use overlapped I/O with your read. That way an Event will be signalled any time you receive a character.
You could put a receive loop in a separate thread, anf then post each characted received with a resgistered window message.
The choices may not be endless, but they are several!
Iain.
|
|
|
|