Thanks Richard, It would not be possible for ABC to exist in Person1 and Person2 in the same row, but its no harm using the syntax you describe to circumvent it in case it were to happen.
KeithF
Posts
-
Select Statement in SQL Server -
Select Statement in SQL ServerThanks GuyThiebaut, that is cleaner code.
-
Select Statement in SQL ServerNevermind figured it out, was missing brackets in the SQL statement
KeithF wrote:
Select * From MyTable Where (Person1 = 'ABC' OR Person1 = 'DEF) AND (Person2 = 'ABC' OR Person2 = 'DEF')
-
Select Statement in SQL ServerHi Folks, I have a quick question in relation to how i select data from a table, as seen in the table below i want to get rows where Person1 & Person2 are both on the same row, so in the table below i would just want Rows 1 & 2. Table: ID | Person1 | Person2 | . . . 1 | ABC | DEF | . . . 2 | DEF | ABC | . . . 3 | ABC | GHI | . . . . . . I have tried the following:
Select * From MyTable Where Person1 = 'ABC' OR Person1 = 'DEF AND Person2 = 'ABC' OR Person2 = 'DEF'
This does not have the desired effect however. Where am i going wrong here?
-
OO DesignYeah i suppose it make the code more flexible going forward but does add a level of complexity that may make it harder for a newbie to just jump in to the code base.
-
OO DesignFolks I had asked this question a couple of days ago and based on the response i have attempted to implement it, I posted a reply in the thread but it did not bump the topic so i'm just bumping here to see what the opinion of the experts here are: Here is a link to the codeproject post: http://www.codeproject.com/Messages/4625183/Re-OO-Design-for-Specifc-Problem.aspx[^] TIA
-
OO Design for Specifc ProblemFolks, Question about my design so far, I am wondering if i am going about this the right way? I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application. Mainly using:
MarshalAs(UnmanagedType.LPStr)]
So with that in my i have added a C# project to the solution to test this code, see test method below:
static void Main(string[] args)
{
ICOMReq iReq = new CCOMReq();
ICOMRsp iRsp = new CCOMRsp();
Link l = new Link();iReq.Date\_Time = DateTime.UtcNow; iReq.Var2 = "1023758145865"; l.DoMethod1(iReq, out iRsp); //Handle COM Response here }
The link class looks like so at the moment be but will have all the methods created once the design is correct:
public class Link
{
public bool DoMethod1(ICOMReq _COMReq, out ICOMRsp COMRsp)
{
Method1 WebServiceMethod = new Method1(new Method1Request(), new Method1Response(), (CCOMReq)_COMReq, new CCOMRsp());
WebServiceMethod.Process();//Just test code at the moment COMRsp = null; return true; } }
Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called. Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:
public class Method1 : WebServiceInterfaceBridge { public Method1(Method1Request WEB\_Req, Method1Response WEB\_Rsp, CCOMReq COM\_Req, ICOMRsp COM\_Rsp) : base(WEB\_Req, WEB\_Rsp, CBE\_Req, CBE\_Rsp) { WEB\_Req.SOME\_DATE\_TIME = COM\_Req.Date\_Time; } public new void Process() { base.Process(); } public override void LOG() { Console.WriteLine(this.WebMethod\_Request.MEMBER\_VAR\_HERE);
-
OO Design for Specifc ProblemFrom reading about the OO patterns, it would appear the one i need to use is http://en.wikipedia.org/wiki/Abstract_factory_pattern[^] Am i correct in saying this?
-
OO Design for Specifc ProblemHi Folks, I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook. EG.
RequestObject req = new RequestObject("SomeVal");
ResponseObject rsp = new ResponseObject();rsp = WebServiceHook.Method1(RequestObject); //Returns ResponseObject
Each Method takes a different request object and returns a different type of response object. As it stands i have a class for each of these methods, Each class has a public method Process() that does the interaction. I am trying to determine the best way to group all this code together using OO techniques without sacrificing functionality. I would like just one ProcessMethod in one class that will handle the interaction with the webservice for all the different web methods. So i would only call one ProcessMethod passing a switch of sorts that would define the relevant types and uniques strings that method requires. Some Sample code below:
\[ComVisible(false)\] private static InfoRequest infoReq = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD \[ComVisible(false)\] private static InfoResponse infoRsp = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD //PARAM TYPES WILL DIFFER IN EACH PROCESS METHOD public static bool Process(INTERFACEREQUEST COMReq, out INTERFACERESPONSE COMRsp) { bool blnReturnVal = false; //Always the same CInfoRsp InfoRsp = new CInfoRsp(); //TYPES WILL DIFFER IN EACH PROCESS METHOD CInfoReq InfoReq = (CInfoReq)COMReq; //TYPES WILL DIFFER IN EACH PROCESS METHOD Globals.dtStart = DateTime.Now; //Always the same Globals.Log(Logger.LogLevel.Minimum, Logger.LogType.APIMethodEntryPoint, "SOME TEXT HERE", "AND HERE", InfoReq.SalePointID);//Always the same - Except for the Piece of Text try { Globals.TheService.Url = Settings.URL; //Always the same infoReq = new InfoRequest(); //TYPES WILL DIFFER IN EACH PROCESS METHOD infoRsp = new InfoResponse(); //TYPES WILL DIFFER IN EACH PROCESS METHOD SetRequest(InfoReq); //Set the PHS Request Object = to Our Values Passed from the COM Component CallWEBServiceMethod(); //Call the Web Service passing the appropriate arguments
-
Sort a Custom Class Collection in VB6Hi Folks, I am having difficulty sorting a custom class based collection on two fields and am wondering if anyone can assist me. I have a class that looks like so:
Class myClass
private ID as String
private Name as String
private TK as String
private Di as String
private M as StringEnd Class
Using this class i add to a Collection a number of items, e.g.
Private colClass As Collection
Private clsTheClass As myClassSet colClass = New Collection
Set clsTheClass = New myClass clsTheClass.Name = "A" clsTheClass.TKs = "100" clsTheClass.Di = "5" clsTheClass.ID = "1" clsTheClass.M = "9" colClass.Add clsTheClass
What i end up with it is a collection that looks like so after adding all the items:
ID |Name |TK |Di |M
1 A 100 5 9
2 B 100 3 9
3 C 10 5 9
4 D 10 7 9
5 E 10 1 9
6 F 400 9 5
7 F 400 4 5I need to sort the collection On TK, and then DI. That should make the collection look like this:
ID |Name |TK |Di |M
6 F 400 9 5
7 F 400 4 5
1 A 100 5 9
2 B 100 3 9
4 D 10 7 9
3 C 10 5 9
5 E 10 1 9I am currently using this method to sort on TK, but i cannot get it to work how i need the output:
Public Sub SortCollection(ColVar As Collection)
Dim oCol As Collection
Dim i As Integer
Dim i2 As Integer
Dim iBefore As IntegerIf Not (ColVar Is Nothing) Then If ColVar.Count > 0 Then Set oCol = New Collection For i = 1 To ColVar.Count If oCol.Count = 0 Then oCol.Add ColVar(i) Else iBefore = 0 For i2 = oCol.Count To 1 Step -1 If CLng(ColVar(i).TK) < CLng(oCol(i2).TK) Then iBefore = i2 Else Exit For End If Next If iBefore = 0 Then oCol.Add ColVar(i) Else oCol.Add ColVar(i), , iBefore End If
-
Printing BSTHi Folks, I Need to print a Binary TREE like so: 10 / \ 5 15 / / \ 2 14 17 I have the code to add to the tree and that all works ok and i have a method to print out the full tree starting at the root, then all the left nodes then the right nodes:
public void ShowTree(Node T)
{
if (T != null)
{
Console.Write(T.DATA+ "\n");
ShowTree(T.LEFT);
ShowTree(T.RIGHT);
}}
I have tried something like this:
private static void ShowTree(Node tp, int spaces)
{
int i = 0;if (tp != null) { ShowTree(tp.left, spaces + 3); for (i = 0; i < spaces; i++) { Console.Write(" "); } Console.WriteLine(tp.data); ShowTree(tp.right, spaces + 3); } }
And a few other approaches but i cannot get it to do as i want. Any suggestions on how i can do this?
-
CreateInstance(__uuidof(MYClass));Anybody?
-
CreateInstance(__uuidof(MYClass));Folks Quick Question: I have a dll developed in c#, which does some interactions with a web service, this all seems to be fine. I have made the dll visible to COM. I then register the dll using regasm passing it a /codebase /tlb argument. Again all this works fine. I now get a tlb file. From here i reference the tlb in my VC6 project like so:
// Import the type library.
#import "C:\\epos\\MyInterface.tlb" raw_interfaces_only
using namespace MyInterface;Once i compile the VC++ project i get a tlh file generated, which has the following contents (edited there is much more in this file just showing what is needed here): .tlh File generated by VC6
#pragma once
#pragma pack(push, 8)#include <comdef.h>
namespace MyInterface {
struct __declspec(uuid("2172ffe3-3177-3e81-ac7a-9d27e11be389"))
/* dual interface */ IMyLink;
struct /* coclass */ CMyLink;_COM_SMARTPTR_TYPEDEF(IMyLink, __uuidof(IMyLink));
I create COM earlier in the program so i have not included it in the code below. Then i Create an instance of the c# class, to call the methods i need. Now this all works fine and i can call these methods and they work correctly. Code in my Main.c file
IMyLinkPtr iPtrMyLink; //Global Variable
IChVRspPtr iPtrCheckVRsp; //Create the Interface to The CheckVoucher Responsevoid main()
{
short blnRetVal = 0; //Set to False Initially, return value from dllIChVReqPtr iPtrCheckV(\_\_uuidof(CChVReq)); //Create the Interface to The Method1 Class. This is another class in the dll HRESULT hrRetval= E\_FAIL; hrRetval = iPtrMyLink.CreateInstance(\_\_uuidof(CMyLink)); //This is the main class in the dll, a wrapper to call methods from.
// Pass to the method the request class, a reference to the response class and a reference to the return value.
iPtrMyLink->CallMethod1(iPtrCheckV, &iPtrCheckVRsp, &blnRetVal);
}The problem i am having is that my program crashes after some time where the memory has grown to 32mb, which to me is quite low. The crash occurs on a CreateInstance line, not necessarily the one above but some other method i have to another .net dll. My main question is about memory, before calling this line:
hrRetval = iPtrMyLink.CreateInstance(__uuidof(CMyLink));
The memory in the VC6 app is 12mb, once this line is called the memory jumps to 24mb. Is this down to loading the .net Fra
-
Class for Serail Port CommsHi Luc, Quick question, I have created a class for the message protocol using States I think, i'm just wondering if this is the correct approach:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;namespace TEST
{
public class clsTEST
{
public enum CurrentCommsState
{
Idle,
SentENQ,
RecvdENQ,
SentACK0,
RecvdACK0,
SentACK1,
RecvdACK1,
SentMessage,
RecvdMessage,
SentEOT,
RecvdEOT
}
private enum MessageDirection
{
In,
Out
}public CurrentCommsState TheState = new CurrentCommsState(); private MessageDirection TheDirection = new MessageDirection(); private SerialPort spTest= null; private byte\[\] btRecvdMsg = new byte\[200\]; public clsOpenShift(SerialPort spTheSP) { spTEST= spTheSP; TheState = CurrentCommsState.Idle; TheDirection = MessageDirection.Out; } public void SendAndRecv(out byte\[\] TheBufferRecvd) { TheBufferRecvd = new Byte\[200\]; if (SendMsg()) { if (RecvMsg(ref btRecvdMsg, 1)) { Array.Copy(btRecvdMsg, TheBufferRecvd, 200); } } else if (RecvMsg(ref btRecvdMsg, 1)) { if (SendMsg()) { } } } private bool RecvMsg(ref byte\[\] btOutRecvd, int iBytesToRecv) { bool blnRetVal = false; try { while (spOpenShiftSP.BytesToRead == 0) { System.Threading.Thread.Sleep(100); } byte\[\] theBuffer = new byte\[iBytesToRecv\]; spTEST.Read(theBuffer, 0, iBytesToRecv); ChangeState(theBuffer); Array.Copy(theBuffer, btOutRecvd, theBuffer.Length); blnRetVal = true; } catch (Exception e) { blnRetVal = false; } return blnRetVal; } private bool SendMsg() { bool blnRetVal = false; try {
-
Class for Serail Port CommsThanks Luc. Is the If / Else block in my code not already doing what you talk about with the State Machine pattern?
-
Class for Serail Port CommsHi Guys, Just a quick question I have c# code working for communicating with a Serial device using the SerialPort Class (see code below):
private void SendEnq(bool blnIncStep)
{
if (blnIncStep)
{
iStep++;
}byte\[\] c = new byte\[\] { 0x05, }; spBPDione.Write(c, 0, c.Length); Console.WriteLine("OUT: " + ByteToHex(c)); } private void DataRecvEvent() { int bytes = spBPDione.BytesToRead; byte\[\] comBuffer = new byte\[bytes\]; spBPDione.Read(comBuffer, 0, bytes); Console.WriteLine("IN: " + ByteToHex(comBuffer)); Console.WriteLine("STEP:" + iStep); if (ByteToHex(comBuffer).Trim() == "06") { if (iStep >= 2) { //All good to here } else { byte\[\] c = new byte\[\] { 0x02, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x03, 0x02 /\*LRC\*/ }; spBPDione.Write(c, 0, c.Length); Console.WriteLine("OUT: " + ByteToHex(c)); iStep++; } } else if (ByteToHex(comBuffer).Trim() == "07") { byte\[\] c = new byte\[\] { 0x04, }; spBPDione.Write(c, 0, c.Length); Console.WriteLine("OUT: " + ByteToHex(c)); iStep++; } else if (ByteToHex(comBuffer).Trim() == "05") { if (iStep >= 2) { byte\[\] c = new byte\[\] { 0x06, }; //spBPDione.ReceivedBytesThreshold = 29; spBPDione.Write(c, 0, c.Length); Console.W
-
Pointer MathsFolks, Quick question in relation to the Pointer Maths in this program below, The Output is as follows: 1, 2, 3 . . . . . . . . . 245026, 245027, 245028 246017, 246018, 246019 247010, 247011, 247012 248005, 248006, 248007 249002, 249003, 249004 The Last Record is : 245028 Using the MoveBack function I expected the output to be 248007, the record before the current record, however it seems we move back 12 blocks of memory to 245028 and not the 12bytes I expected. Can someone explain to me whats going on here and how I can modify the code to get 248007 from the function? Thanks In Advance
#include "stdafx.h"
#include <conio.h>typedef struct MyStruct{
int i;
int j;
int k;
} TheStruct;int MoveBack(int *iPos);
int main(int argc, char* argv[])
{
TheStruct ts[500];
int i = 0;for(i = 0; i < 500; i++) { ts\[i\].i = i \* i + 1; ts\[i\].j = i \* i + 2; ts\[i\].k = i \* i + 3; } for(i = 0; i < 500; i++) { printf("%ld, %ld, %ld \\r\\n" ,ts\[i\].i ,ts\[i\].j, ts\[i\].k); if(i == 499) { //Pointer - Move back to last record printf("The Last Record is : %ld" , MoveBack(&ts\[i\].k)); } } while(!getch()); return 0;
}
int MoveBack(int *iPos)
{
int *i = iPos - sizeof(TheStruct);
return *i;
} -
Char* in C++ 6 to C# .Net [modified]Hi Luc, Thanks that works perfectly, you learn something new every day ;)
-
Char* in C++ 6 to C# .Net [modified]Hi Luc, I tried what you said as well but I only get see the first character in the C++ method, here is the code:
[DllImport("MyDll.dll", CharSet = CharSet.Unicode)]
public static extern int MyMethod(
string strA,
string strB,
string strC);I took out the
[param: MarshalAs(UnmanagedType.LPStr)]
but it seems that this is needed
-
Char* in C++ 6 to C# .Net [modified]Hi Richard, Thanks for all the help. After playing around with a few other things i found that this works
[DllImport("MyDll.dll", CharSet = CharSet.Unicode)]
public static extern int MyMethod(
[param: MarshalAs(UnmanagedType.LPStr)]
StringBuilder strA,
[param: MarshalAs(UnmanagedType.LPStr)]
StringBuilder strB,
[param: MarshalAs(UnmanagedType.LPStr)]
StringBuilder strC);changeg need were to remove the ref keyword, changes string to stringbuilder and the unmanaged type to LPStr