C# Help

C Scripting questions and answers
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

C# Help

Post by gburk »

Art
or anyone that wants to jump in..

Been a while art got sidetracked had to put in a new main hard-drive picked up a m2 SSD, it was good decision loads windows in a few seconds now as to 5 around minutes with the old drive..

But on to my question, i have been messing with visual studio as you know, and like usual i picked a problem that is over my head..
here go's  if you have a line of text in a string, and the text line contains char's say an FXXX space or maybe no space GXXX space or no space KXXX space or no space LXXX, and the XXX chars may not always be the same char's and my not be the same amount GXXX may only be GXX or LXXX may be LXX depending on the text file i load but the F G K L will always be the same..
How would i return a string with say GXXX to KXXX only or maybe less char's after the G or K. I can't really Indexof the G or K  because the length between G and K can change and the may be or may not be a space between them... the XXX i'm using for example could be any char or any combination of char's ..

Most likely not making  things clear, but if you get the drift of things Have any thoughts as to a fairly not super complicated way to do this..
I'm using a class i added, and have the function i'm calling in the class calling it from a button press in a windows form.

Gary   
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4586
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: C# Help

Post by ArtF »

Hi Gary:

  Im mainly a C++ programmer so C# isnt in my skillset..though I can read and translate it.
One of the largest differences between the two though is string handling. I use CStrings
primarily. SO in there I can do a case statement for such parsing.. assuming that
you always start with FGK or L..

int index = 0;
char hold[4];
int hind = 0;
while( index < MyText.GetLength();&nbsp; )
{
&nbsp; switch( Mytext[index] )
&nbsp; {
&nbsp; &nbsp; case( "F" ):&nbsp; &nbsp; if( hind > 0) ProcessLastString( hold, hind );
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hold[ hind = 0 ] = "F"; break;
&nbsp; &nbsp; case( "G" ):&nbsp; if( hind > 0) ProcessLastString( hold, hind );
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hold[ hind = 0 ] = "G"; break;
&nbsp; &nbsp; case( "K" ):&nbsp; &nbsp; if( hind > 0) ProcessLastString( hold, hind );
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hold[ hind = 0 ] = "K"; break;
&nbsp; &nbsp; case( "L" ):&nbsp; &nbsp; if( hind > 0) ProcessLastString( hold, hind );
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hold[ hind = 0 ] = "L"; break;
&nbsp; &nbsp; default:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hold[ ++hind ] = Mytext[index];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; }
}

&nbsp; Thats off of top of head, and would call a&nbsp; routine called ProcessLastString with the
last string sensed, and the number of letters in it.


}

User avatar
Mooselake
Old Timer
Posts: 522
Joined: Sun Dec 26, 2010 12:21 pm
Location: Mooselake Manor

Re: C# Help

Post by Mooselake »

I've only used C and C++ but for c# a little searching came up with string.split to pick off individual words and then parse them like Art's example

Did I read somewhere that c sharp is on it's way out, or did I just imagine that?

Kirk
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4586
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: C# Help

Post by ArtF »

Kirk:

&nbsp; Well, C++ is now only 6% of programmers from what I read.. all versions
of c are falling in % of use. Python I think is now number 1, or javascript depending on source..


Art
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: C# Help

Post by gburk »

Art

I have to say i said c# but i think it should have been fazed c c++ here is a sample of code i have written..

&nbsp; &nbsp; &nbsp; public class SearchGcode
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; Form1 Search_Gcode;
&nbsp; &nbsp; &nbsp; &nbsp; public SearchGcode(Form1 form1)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Search_Gcode = form1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; public int FindString( List<string> Gcode, string Findstr, int LineCnt, long cnt)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // int LineCnt = 0;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox.Show("Count = in compair "+LineCnt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( LineCnt < cnt )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string line = GlobalVar.GcodeList[LineCnt];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox.Show(" List =" + line);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bool found = line.Contains(Findstr);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( found == true )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox.Show("Fount the line");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LineCnt;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LineCnt++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Search_Gcode.GcodeBox2.AppendText(GlobalVar.GcodeList[LineCnt]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Search_Gcode.GcodeBox2.AppendText(Environment.NewLine);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; public string Testg98()
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return null;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }

the text file loaded is stored in Global.GcodeList..
and is searching for a string,
and if found i am adding the lines to the my second richtexbox

sorry about c# had it stuck in my mind..

Gary
User avatar
Mooselake
Old Timer
Posts: 522
Joined: Sun Dec 26, 2010 12:21 pm
Location: Mooselake Manor

Re: C# Help

Post by Mooselake »

ArtF wrote:C++ is now only 6% of programmers from what I read
But it's the better 6% :) , and probably bigger if you lump Apple's Objective C since the fruity people always have to be different.

I wonder how many assembler programmers are still out there?&nbsp; I've heard that javas*t is on the way out and html5 is the latest wonder, but try not to pay too much attention to that stuff any more.

Isn't Cobol still where the big money is?&nbsp; Hard to find enough super fast typists to fix all that old stuff from the 60s and 70s

Kirk

BillM
Old Timer
Posts: 191
Joined: Wed Jan 06, 2016 10:12 am
Location: Mystic CT

Re: C# Help

Post by BillM »

Kirk

Cobol ?&nbsp; That goes way back.&nbsp; At one time there was talk about resurrecting a version to make an object oriented Cobol.

Remember Algol?&nbsp; The old Data General minicomputer's operating system was written in Algol.&nbsp; Another language that fizzled was the government's attempt to standardize programming for defense systems with a new language Ada.

C and C++ are still winners in my mind for high level compiled programming languages.

Bill Michael
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4586
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: C# Help

Post by ArtF »



&nbsp; Been at C++ for so long I think I dream in code.

while( !Rested ) sheep++;

Art
User avatar
Mooselake
Old Timer
Posts: 522
Joined: Sun Dec 26, 2010 12:21 pm
Location: Mooselake Manor

Re: C# Help

Post by Mooselake »

Cobol may have been the only language where you needed a forklift to carry all the boxes of cards :)&nbsp; Back in the early 70s I wrote a large fortran program (still have a listing in the attic)&nbsp; to convert an interpreted report language to cobol that turned 12 hours of CPU time into 10 minutes on a Univac 1108, how fast the operators could change tapes became the limiting factor.&nbsp; Being the smart assed kid I mentioned it to the cobol programmers, being much more tactful adults they just smiled.&nbsp; That was the same company where I was in the same department as the APT post processor programmers, and a concrete block wall away from the CNC machines they wouldn't let me near.&nbsp; Also the same place where I worked with the later founder of Autodesk, one of the best programmers I've ever met.

I wanted to find a Burroughs machine to play with algol on, but that wasn't to be.

Missed Ada except in articles, although PL/1 was around my second programming language after Fortran.&nbsp; Had a class project to design a simple compiler (with a compiler generator tool, forget the name) in PL/1.&nbsp; Never quite finished it but still got credit for the course.

Kirk
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: C# Help

Post by gburk »

The only time i did any coding was way back, can't even remember the years the old 6800 processor on the mac and Atari, i had the Atari TT, did all the work in assembly. was a a lot younger in those days and thing came easier.. wrote my own bulletin board, of course that was before internet and we all had dial ups modems. it was fun though.

Now just messing with it again mostly to kill some time..

Gary&nbsp; &nbsp;
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: C# Help

Post by gburk »

Art

Don't know if it was worth it but i figured out how to create forms in visual studio C++
and use the form designer with C++..

so i assume i will have to modify my search code function, and all the strings now, but haven't got that far yet..

Gary&nbsp;
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4586
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: C# Help

Post by ArtF »

Gary:

Its a long learning experience. Ive been using Visual Studio since it was released,
theres a lot to know about it, but youve started that path. Takes the first step to
get anywhere.. :)

Art
User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: C# Help

Post by tweakie »

ArtF wrote:
while( !Rested ) sheep++;
;D ;D ;D

Tweakie.
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: C# Help

Post by gburk »

Art

run into my first major brick wall..

Seems classes and function are handled a lot different in c++.

I have a form.h and form.cpp, so i created another class, called class1 it also has a class1.h and a class1.cpp.

my problem is i can't seem to figure out how to call the function in class1 form a button click in the form.h button click event. anything i have tried doesn't work..
looks like a whole new ball game form i have it my forms created in c .

any thoughts, or pointers as where to lookup the info.

Gary
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4586
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: C# Help

Post by ArtF »

Gary:

&nbsp; It does sound like your using C# you know, in the raw C++ settings, you have to design a dialog to use, not a form.
In C# use, you usually design a&nbsp; form and attach events and such to it. I suspect that's where you are.

So you have a form.h and a form.cpp , together they all simply called a class.
Inside form.h you likely have some declaration of the class itself..

in C++ ( C# may differ in some syntax), youd have something like..

class CMyForm : public CDialog
{
&nbsp; int myvariable;
&nbsp; bool mybool;
&nbsp; void&nbsp; MyButtonWasPressed();
}

&nbsp; So form.h can be thought of as a declaration file, it tells the system what functions or variables
the class form contains. The Form.cpp contains the actual use of those items and the code itself
for the functions. So in it we find..

void MyButonWasPressed()
{
&nbsp; //you want to acces your other class here, right?
}

So to have you button press call your other class you need to have
your form own one of those classes.. So you change form.h to this..

#include "class1.h"

class CMyForm : public CDialog
{
&nbsp; class1 MyClass1;
&nbsp; int myvariable;
&nbsp; bool mybool;
&nbsp; void&nbsp; MyButtonWasPressed();
}

&nbsp; And finally , change the form.cpp function to ..

void MyButonWasPressed()
{
&nbsp; MyClass1.NameofFuntionHere();
}

&nbsp; Now, thats how you do it ( in one way anyway ) in C++. I dont use C#
enough to remember the syntax, the system fills in most of it as you go.
So the above has to be done in the way C# does it. So you may want to explore
some googled example code , theres quite a bit out there of every sort. Im
self taught as a programmer, so most of my education was gleaned from
taking apart others code and climbing on their shoulders. Its a frustrating,
maddening, disheartening and addictive process to go through, but the
most enjoyable skill in the world to have.

Art
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests