0 Replies - 281 Views - Last Post: 13 May 2014 - 06:55 AM Rate Topic: -----

#1 Oceanamie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-May 14

DDE .NET

Posted 13 May 2014 - 06:55 AM

Hi, all.

I'm stuck on something that I need help on. I'm writing a C# program in Visual Studio, and I want to connect to a DDE link (using WinWedge).

I am using: http://ndde.codeplex.com/

Though, I am having a bit of trouble understanding how to do it. I know how to do it in Visual Basic within an Excel macro (below):
Sub GetSWData()
Dim R As Long
Dim Chan As Long
Dim Feed, Feed_Units, Dilute, Dilute_Units, Concentrate, Concentrate_Units, DGallons, DGallons_Units, E1, E1_Units, F2, F2_Units, G3, G3_Units As Variant
Dim vDat As Variant
Dim sDat As String
 
' find the next empty row in Column A
R = ThisWorkbook.Sheets("Sheet1").Cells(65000, 1).End(xlUp).Row + 1

Chan = DDEInitiate("WinWedge", "Com5") ' Establish DDE link to WinWedge on Com1
' WinWedge can be configured to parse data into more than one data field. The following code demonstrates how to retrieve one or more data fields. If more than one field is specified, each field is placed in its own column.

Feed = DDERequest(Chan, "Field(3)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 3).Value = Feed(1)
Feed_Units = DDERequest(Chan, "Field(4)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 4).Value = Feed_Units(1)

EDDilute = DDERequest(Chan, "Field(9)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 5).Value = EDDilute(1)
EDDilute_Units = DDERequest(Chan, "Field(10)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 6).Value = EDDilute_Units(1)

EDConcentrate = DDERequest(Chan, "Field(15)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 7).Value = EDConcentrate(1)
EDConcentrate_Units = DDERequest(Chan, "Field(16)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 8).Value = EDConcentrate_Units(1)

EDIDilute = DDERequest(Chan, "Field(21)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 9).Value = EDIDilute(1)
EDIDilute_Units = DDERequest(Chan, "Field(22)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 10).Value = EDIDilute_Units(1)

FeedT = DDERequest(Chan, "Field(27)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 11).Value = FeedT(1)
FeedT_Units = DDERequest(Chan, "Field(28)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 12).Value = FeedT_Units(1)

EDDiluteT = DDERequest(Chan, "Field(33)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 13).Value = EDDiluteT(1)
EDDiluteT_Units = DDERequest(Chan, "Field(34)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 14).Value = EDDiluteT_Units(1)

EDConcT = DDERequest(Chan, "Field(39)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 15).Value = EDConcT(1)
EDConcT_Units = DDERequest(Chan, "Field(40)")
ThisWorkbook.Sheets("Sheet1").Cells(R, 16).Value = EDConcT_Units(1)

DDETerminate Chan ' Close the DDE channel

' Insert a date/time stamp in the sheet in the same row as the data
ThisWorkbook.Sheets("Sheet1").Cells(R, 1).Value = Now
ThisWorkbook.Sheets("Sheet1").Cells(R, 2).Value = Now

End Sub



Though I can't seem to manage how to do it in C#. Some help would be great!

I found the following example for getting a browser's URL, and I figured it's just as simple, but I don't understand how to do the function part of it.
//
// usage: GetBrowserURL("opera") or GetBrowserURL("firefox")
//

private string GetBrowserURL(string browser) {
    try {
        DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo");
        dde.Connect();
        string url = dde.Request("URL", int.MaxValue);
        string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
        dde.Disconnect();
        return text[0].Substring(1);
    } catch {
        return null;
    }
}



What would I do with the private function? I assume it would have to be a public function? I am not trying to get the string but a real number (from my data that's going through WinWedge).

Is This A Good Question/Topic? 0
  • +

Page 1 of 1