Converting VB to C# and updating outside table

Thanks everyone for the help. Â Doing the new layer was perfect, because I had no C# code on this form and I wanted to keep all the rest of my customization.


In addition, the code to get access to the txtKeyField worked perfectly. Â

I'm up and running, thanks again!





On Thu, Aug 14, 2014 at 12:05 PM, 'Tom J. Christie' tchristie@… [vantage] <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p>I never really understood the valve of that button. When I first got into Epicor I thought it would allow me to segregate code (somewhat like classes). Now I have forms with 2000+ lines of code. So much fun to work with in Epicor’s fancy notepad-lite scripting tool…


Tom Christie | Information Technology Manager | AGM Container Controls, Inc.<http://www.agmcontainer.com/> | tchristie@...<mailto:tchristie@...> | t: 520.881.2130 ext 2176

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com]
Sent: Thursday, August 14, 2014 10:22 AM
To: Vantage
Subject: Re: [Vantage] Converting VB to C# and updating outside table




The new code layer button does not retain your previous code. It's a completely new code base with the same controls
On Aug 14, 2014 12:45 PM, "kirianno@...<mailto:kirianno@...> [vantage]" <vantage@yahoogroups.com<mailto:vantage@yahoogroups.com>> wrote:


Have you tried the "New Code Layer" button in the Script Editor? It allows C# code to be added while VB exists and vice verse


[Non-text portions of this message have been removed]

</div>
 


<div style="color:#fff;min-height:0;"></div>

We've got code to generate the next available number for a couple of forms from a long time ago. Â I'm trying to do something similar for 2 new forms we've made, but the new forms are in C# and the old are in VB.

Historically I've gotten away with just using an online converter. Â Unfortunately that's not working today. Â When I use it, I get this error:

I'm hoping someone knows the right code to update the company.number04 field from C# or they can review the code below to identify the issues. Â I'm getting the errors within the "if (found)" section.

C#:
 private void epiButtonGenNCRNum_Click(object sender, System.EventArgs args) { // ** Place Event Handling Code Here ** txtKeyField.Text = GetNextKey(); }Â

private string GetNextKey()
{
////Use the company Adapter to Store our sequence number Number01
string nextKey = string.Empty;
CompanyAdapter companyAdapter = new CompanyAdapter(UD08Form);

companyAdapter.BOConnect();

string company = UD08Form.Session.CompanyID;

bool found = companyAdapter.GetByID(company);


if ((found)) {

nextKey = companyAdapter.CompanyData.Company.Rows(0)(“Number04”).toString();

companyAdapter.CompanyData.Company.Rows(0).BeginEdit();
companyAdapter.CompanyData.Company.Rows(0)("Number04") += 1;

companyAdapter.CompanyData.Company.Rows(0).EndEdit();

companyAdapter.Update();
companyAdapter.Dispose();
}
return nextKey;
}


VB:
  Private Sub btnGenerRep_Click(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles btnGenerRep.Click
    '// ** Place Event Handling Code Here **Â
  Â
txtKeyField.Text = GetNextKey()
  Â
  End Sub


Private Function GetNextKey() As String
'//Use the company Adapter to Store our sequence number Number01

Dim nextKey As String = String.Empty
Dim companyAdapter As CompanyAdapter = New CompanyAdapter(SalesOrderForm)

companyAdapter.BOConnect()

Dim company As String = SalesOrderForm.Session.CompanyID
Dim found As Boolean = companyAdapter.GetByID(company)

if (found) then
nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number01").toString()
companyAdapter.CompanyData.Company.Rows(0).BeginEdit()
companyAdapter.CompanyData.Company.Rows(0)("Number01") += 1
companyAdapter.CompanyData.Company.Rows(0).EndEdit()
companyAdapter.Update()
companyAdapter.Dispose()
end if
return nextKey
End Function

Ken Williams

Vice President, Administrative Services

Intermountain Electronics - Power, Automation, and Process Systems

Office:Â 435-613-4817Â |Â Â Mobile:Â 801-918-7318
kwilliams@…www.ie-corp.com

C# uses square brackets for indexing rather than parenthesis.
This:
nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number04").toString();
companyAdapter.CompanyData.Company.Rows(0).BeginEdit();
companyAdapter.CompanyData.Company.Rows(0)("Number04") += 1;
companyAdapter.CompanyData.Company.Rows(0).EndEdit();

should look like:

nextKey = companyAdapter.CompanyData.Company.Rows[0]["Number04"].toString();
companyAdapter.CompanyData.Company.Rows[0].BeginEdit();

companyAdapter.CompanyData.Company.Rows[0]["Number04"] += 1;
companyAdapter.CompanyData.Company.Rows[0].EndEdit();


On Wed, Aug 13, 2014 at 4:23 PM, Ken Williams kwilliams@... [vantage] <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p></p><div dir="ltr"><div style="font-family:arial, sans-serif;font-size:13px;">We&#39;ve got code to generate the next available number for a couple of forms from a long time ago. Â I&#39;m trying to do something similar for 2 new forms we&#39;ve made, but the new forms are in C# and the old are in VB.</div>

Historically I've gotten away with just using an online converter. Â Unfortunately that's not working today. Â When I use it, I get this error:

I'm hoping someone knows the right code to update the company.number04 field from C# or they can review the code below to identify the issues. Â I'm getting the errors within the "if (found)" section.

C#:
 private void epiButtonGenNCRNum_Click(object sender, System.EventArgs args) { // ** Place Event Handling Code Here ** txtKeyField.Text = GetNextKey(); }Â

private string GetNextKey()
{
////Use the company Adapter to Store our sequence number Number01
string nextKey = string.Empty;
CompanyAdapter companyAdapter = new CompanyAdapter(UD08Form);

companyAdapter.BOConnect();

string company = UD08Form.Session.CompanyID;

bool found = companyAdapter.GetByID(company);


if ((found)) {

nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number04").toString();

companyAdapter.CompanyData.Company.Rows(0).BeginEdit();

companyAdapter.CompanyData.Company.Rows(0)("Number04") += 1;

companyAdapter.CompanyData.Company.Rows(0).EndEdit();

companyAdapter.Update();

companyAdapter.Dispose();
}
return nextKey;
}


VB:
  Private Sub btnGenerRep_Click(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles btnGenerRep.Click
    '// ** Place Event Handling Code Here **Â
  Â
txtKeyField.Text = GetNextKey()
  Â
  End Sub


Private Function GetNextKey() As String
'//Use the company Adapter to Store our sequence number Number01

Dim nextKey As String = String.Empty
Dim companyAdapter As CompanyAdapter = New CompanyAdapter(SalesOrderForm)

companyAdapter.BOConnect()

Dim company As String = SalesOrderForm.Session.CompanyID
Dim found As Boolean = companyAdapter.GetByID(company)

if (found) then
nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number01").toString()
companyAdapter.CompanyData.Company.Rows(0).BeginEdit()
companyAdapter.CompanyData.Company.Rows(0)("Number01") += 1
companyAdapter.CompanyData.Company.Rows(0).EndEdit()
companyAdapter.Update()
companyAdapter.Dispose()
end if
return nextKey
End Function

Ken Williams

Vice President, Administrative Services

Intermountain Electronics - Power, Automation, and Process Systems

Office:Â 435-613-4817Â |Â Â Mobile:Â 801-918-7318
kwilliams@…www.ie-corp.com

</div>
 


<div style="color:#fff;min-height:0;"></div>

John thanks for the reply, that got me much further. Â I now have the following issues, I hope someone can help narrow these last few issues down?

 Error: CS0103 - line 57 (2178) - The name 'txtKeyField' does not exist in the current context
 Error: CS0117 - line 69 (2190) - 'object' does not contain a definition for 'CompanyID'
 Error: CS0149 - line 73 (2194) - Method name expected
 Error: CS0149 - line 75 (2196) - Method name expected

Line 57:txtKeyField.Text = GetNextKey(); Â Â Â ---- This field does exist, don't know why it says it doesn't exist in current context?

Line 69:string company = UD08Form.Session.CompanyID; Â Â Â Â Â ----- I can force this but then it won't work for multi-company (not a big deal as we're single, but I can see us perhaps moving to multi in the semi-near future)

Line 73:nextKey = companyAdapter.CompanyData.Company.Rows[0]("Number04").toString();
Line 75:companyAdapter.CompanyData.Company.Rows[0]("Number04") += 1;

Lines 73 & 75 are the most important, they're what makes everything work.

I appreciate the help!



On Thu, Aug 14, 2014 at 7:32 AM, John Driggers waffqle@... [vantage] <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p></p><div dir="ltr">C# uses square brackets for indexing rather than parenthesis.<div>This:</div><div><div><div style="font-family:arial, sans-serif;font-size:13px;">nextKey = companyAdapter.CompanyData.Company.Rows(0)(&quot;Number04&quot;).toString();</div>
companyAdapter.CompanyData.Company.Rows(0).BeginEdit();

companyAdapter.CompanyData.Company.Rows(0)("Number04") += 1;

companyAdapter.CompanyData.Company.Rows(0).EndEdit();

should look like:

nextKey = companyAdapter.CompanyData.Company.Rows[0]["Number04"].toString();
companyAdapter.CompanyData.Company.Rows[0].BeginEdit();

companyAdapter.CompanyData.Company.Rows[0]["Number04"] += 1;
companyAdapter.CompanyData.Company.Rows[0].EndEdit();


On Wed, Aug 13, 2014 at 4:23 PM, Ken Williams kwilliams@... [vantage] <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p></p><div dir="ltr"><div style="font-family:arial, sans-serif;font-size:13px;">We&#39;ve got code to generate the next available number for a couple of forms from a long time ago. Â I&#39;m trying to do something similar for 2 new forms we&#39;ve made, but the new forms are in C# and the old are in VB.</div>

Historically I've gotten away with just using an online converter. Â Unfortunately that's not working today. Â When I use it, I get this error:

I'm hoping someone knows the right code to update the company.number04 field from C# or they can review the code below to identify the issues. Â I'm getting the errors within the "if (found)" section.

C#:
 private void epiButtonGenNCRNum_Click(object sender, System.EventArgs args) { // ** Place Event Handling Code Here ** txtKeyField.Text = GetNextKey(); }Â

private string GetNextKey()
{
////Use the company Adapter to Store our sequence number Number01
string nextKey = string.Empty;
CompanyAdapter companyAdapter = new CompanyAdapter(UD08Form);

companyAdapter.BOConnect();

string company = UD08Form.Session.CompanyID;

bool found = companyAdapter.GetByID(company);


if ((found)) {

nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number04").toString();

companyAdapter.CompanyData.Company.Rows(0).BeginEdit();

companyAdapter.CompanyData.Company.Rows(0)("Number04") += 1;

companyAdapter.CompanyData.Company.Rows(0).EndEdit();

companyAdapter.Update();

companyAdapter.Dispose();
}
return nextKey;
}


VB:
  Private Sub btnGenerRep_Click(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles btnGenerRep.Click
    '// ** Place Event Handling Code Here **Â
  Â
txtKeyField.Text = GetNextKey()
  Â
  End Sub


Private Function GetNextKey() As String
'//Use the company Adapter to Store our sequence number Number01

Dim nextKey As String = String.Empty
Dim companyAdapter As CompanyAdapter = New CompanyAdapter(SalesOrderForm)

companyAdapter.BOConnect()

Dim company As String = SalesOrderForm.Session.CompanyID
Dim found As Boolean = companyAdapter.GetByID(company)

if (found) then
nextKey = companyAdapter.CompanyData.Company.Rows(0)("Number01").toString()
companyAdapter.CompanyData.Company.Rows(0).BeginEdit()
companyAdapter.CompanyData.Company.Rows(0)("Number01") += 1
companyAdapter.CompanyData.Company.Rows(0).EndEdit()
companyAdapter.Update()
companyAdapter.Dispose()
end if
return nextKey
End Function

Ken Williams

Vice President, Administrative Services

Intermountain Electronics - Power, Automation, and Process Systems

Office:Â 435-613-4817Â |Â Â Mobile:Â 801-918-7318
kwilliams@…www.ie-corp.com

</div>
 


<div style="color:#fff;min-height:0;"></div>

</div>
 


<div style="color:#fff;min-height:0;"></div>

Have you tried the "New Code Layer" button in the Script Editor? It allows C# code to be added while VB exists and vice verse        

The new code layer button does not retain your previous code. It's a completely new code base with the same controls

On Aug 14, 2014 12:45 PM, "kirianno@... [vantage]" <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p>Have you tried the &quot;New Code Layer&quot; button in the Script Editor? It allows C# code to be added while VB exists and vice verse<span>Â Â Â Â </span><span><span>Â Â Â Â </span></span></p>

</div>
 


<div style="color:#fff;min-height:0;"></div>

For the "txtKey does not exist", you could use GetNativeControlReference to declare it before you use it, just grab the EpiGuid from the field's properties and put it in (it will look something like this "f1260502-8d42-47fd-a148-0f66da3846fe"

Exampe:

Dim tbxJobNum as EpiTextBox = CType(csm.GetNativeControlReference("f1260502-8d42-47fd-a148-0f66da3846fe"), EpiTextBox)

So yours would be

Dim txtMyRedeclaredKeyField as EpiTextBox = CType(csm.GetNativeControlReference("[your fields epiguid]"), EpiTextBox)

txtMyRedeclaredKeyField.text = GetNewKey();

I never really understood the valve of that button. When I first got into Epicor I thought it would allow me to segregate code (somewhat like classes). Now I have forms with 2000+ lines of code. So much fun to work with in Epicor’s fancy notepad-lite scripting tool…

Tom Christie | Information Technology Manager | AGM Container Controls, Inc.<http://www.agmcontainer.com/> | tchristie@...<mailto:tchristie@...> | t: 520.881.2130 ext 2176

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com]
Sent: Thursday, August 14, 2014 10:22 AM
To: Vantage
Subject: Re: [Vantage] Converting VB to C# and updating outside table



The new code layer button does not retain your previous code. It's a completely new code base with the same controls
On Aug 14, 2014 12:45 PM, "kirianno@...<mailto:kirianno@...> [vantage]" <vantage@yahoogroups.com<mailto:vantage@yahoogroups.com>> wrote:


Have you tried the "New Code Layer" button in the Script Editor? It allows C# code to be added while VB exists and vice verse



[Non-text portions of this message have been removed]