GearHeads Corner
February 21, 2020, 01:09:48 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: C# Help  (Read 754 times)
0 Members and 1 Guest are viewing this topic.
gburk
Sr. Member
****
Posts: 314


View Profile
« on: January 17, 2020, 06:42:01 PM »

Art
or anyone that wants to jump in..

Been a while art got sidetrack ed 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 combinati on 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 complicat ed 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   
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5585



View Profile
« Reply #1 on: January 18, 2020, 11:03:51 AM »

Hi Gary:

  Im mainly a C++ programme r so C# isnt in my skillset. .though I can read and translate it.
One of the largest differenc es 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.Ge tLength();  )
{
   switch( Mytext[index] )
  {
    case( "F" ):    if( hind > 0) ProcessLa stString( hold, hind );
                        hold[ hind = 0 ] = "F"; break;
    case( "G" ):   if( hind > 0) ProcessLa stString( hold, hind );
                        hold[ hind = 0 ] = "G"; break;
    case( "K" ):    if( hind > 0) ProcessLa stString( hold, hind );
                        hold[ hind = 0 ] = "K"; break;
    case( "L" ):    if( hind > 0) ProcessLa stString( hold, hind );
                        hold[ hind = 0 ] = "L"; break;
    default:
              hold[ ++hind ] = Mytext[index];
               
   }
}

   Thats off of top of head, and would call a  routine called ProcessLa stString with the
last string sensed, and the number of letters in it.


}

Logged
Mooselake
Hero Member
*****
Posts: 625



View Profile
« Reply #2 on: January 19, 2020, 06:12:28 PM »

I've only used C and C++ but for c# a little searching came up with string.sp lit to pick off individua l 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
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5585



View Profile
« Reply #3 on: January 19, 2020, 08:22:34 PM »

Kirk:

  Well, C++ is now only 6% of programme rs from what I read.. all versions
of c are falling in % of use. Python I think is now number 1, or javascrip t depending on source..


Art
Logged
gburk
Sr. Member
****
Posts: 314


View Profile
« Reply #4 on: January 20, 2020, 10:02:04 AM »

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..

       public class SearchGco de
    {
        Form1 Search_Gc ode;
        public SearchGco de(Form1 form1)
        {
            Search_Gc ode = form1;
        }
        public int FindStrin g( List<string> Gcode, string Findstr, int LineCnt, long cnt)
        {
           // int LineCnt = 0;
            MessageBo x.Show("Count = in compair "+LineCnt);
            while ( LineCnt < cnt )
            {
                string line = GlobalVar .GcodeLis t[LineCnt];
                MessageBo x.Show(" List =" + line);
                bool found = line.Cont ains(Findstr);
                if ( found == true )
                {
                    MessageBo x.Show("Fount the line");
                    return LineCnt;
                }
                LineCnt++;
                Search_Gc ode.Gcode Box2.Appe ndText(GlobalVar .GcodeLis t[LineCnt]);
                Search_Gc ode.Gcode Box2.Appe ndText(Environme nt.NewLin e);
            }
                return -1;
        }
        public string Testg98()
        {
            return null;
        }
    }

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

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

Gary
Logged
Mooselake
Hero Member
*****
Posts: 625



View Profile
« Reply #5 on: January 20, 2020, 10:42:32 AM »

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

I wonder how many assembler programme rs are still out there?  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?  Hard to find enough super fast typists to fix all that old stuff from the 60s and 70s

Kirk

Logged
BillM
Full Member
***
Posts: 120


View Profile
« Reply #6 on: January 20, 2020, 11:07:12 AM »

Kirk

Cobol ?   That goes way back.  At one time there was talk about resurrect ing a version to make an object oriented Cobol.

Remember Algol?  The old Data General minicompu ter's operating system was written in Algol.  Another language that fizzled was the governmen t's attempt to standardi ze programmi ng for defense systems with a new language Ada.

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

Bill Michael
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5585



View Profile
« Reply #7 on: January 20, 2020, 11:25:00 AM »



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

while( !Rested ) sheep++;

Art
Logged
Mooselake
Hero Member
*****
Posts: 625



View Profile
« Reply #8 on: January 20, 2020, 12:22:49 PM »

Cobol may have been the only language where you needed a forklift to carry all the boxes of cards Smiley  Back in the early 70s I wrote a large fortran program (still have a listing in the attic)  to convert an interpret ed 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.  Being the smart assed kid I mentioned it to the cobol programme rs, being much more tactful adults they just smiled.  That was the same company where I was in the same departmen t as the APT post processor programme rs, and a concrete block wall away from the CNC machines they wouldn't let me near.  Also the same place where I worked with the later founder of Autodesk, one of the best programme rs 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 programmi ng language after Fortran.  Had a class project to design a simple compiler (with a compiler generator tool, forget the name) in PL/1.  Never quite finished it but still got credit for the course.

Kirk
Logged
gburk
Sr. Member
****
Posts: 314


View Profile
« Reply #9 on: January 20, 2020, 12:45:07 PM »

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     
Logged
gburk
Sr. Member
****
Posts: 314


View Profile
« Reply #10 on: January 22, 2020, 07:36:24 PM »

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 
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5585



View Profile
« Reply #11 on: January 22, 2020, 08:16:37 PM »

Gary:

 Its a long learning experienc e. 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. . Smiley

Art
 
Logged
tweakie
Full Member
***
Posts: 175


Super Kitty


View Profile WWW
« Reply #12 on: January 23, 2020, 07:29:45 AM »


while( !Rested ) sheep++;


 Grin Grin Grin

Tweakie.
Logged
gburk
Sr. Member
****
Posts: 314


View Profile
« Reply #13 on: January 23, 2020, 06:42:26 PM »

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.cp p.

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
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5585



View Profile
« Reply #14 on: January 24, 2020, 08:06:42 AM »

Gary:

  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  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 declarati on of the class itself..

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

class CMyForm : public CDialog
{
   int myvariabl e;
   bool mybool;
   void  MyButtonW asPressed ();
}

  So form.h can be thought of as a declarati on 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 MyButonWa sPressed()
{
  //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
{
   class1 MyClass1;
   int myvariabl e;
   bool mybool;
   void  MyButtonW asPressed ();
}

  And finally , change the form.cpp function to ..

void MyButonWa sPressed()
{
   MyClass1. NameofFun tionHere();
}

  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 programme r, so most of my education was gleaned from
taking apart others code and climbing on their shoulders . Its a frustrati ng,
maddening, dishearte ning and addictive process to go through, but the
most enjoyable skill in the world to have.

Art
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!