Newbie has rough time with ready to use code

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

35 Replies - 1388 Views - Last Post: 25 October 2017 - 12:45 PM Rate Topic: -----

#31 Archangelos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 17

Re: Newbie has rough time with ready to use code

Posted 24 October 2017 - 10:38 AM

View Postandrewsw, on 23 October 2017 - 10:09 PM, said:

Is there a question?
Well, there is one question that applies always even if I do not ask it. How do you like my code?

View Postandrewsw, on 23 October 2017 - 10:09 PM, said:

Which tutorial is encouraging the use of goto? (Most decent tutorials will tuck it to the side or an appendix.)
Speaking of C# tutorials, none of them has done so. i had this in mind (the goto strategy), so far it worked ... but ... according to your comments I'd better abolish it. I have started working on that.

View Postandrewsw, on 23 October 2017 - 10:09 PM, said:

Ugh, please don't name variables stuff like int32Var?!!
Ahahaha ... I suppose nobody would appreciate names like strVar1, strVar2, strVar3 instead of FirstName, LastName, Address.
I have no intention of using names such as int32Var. It was the begining, I needed a general purpose int32 variable therefore int32Var did the job.
Was This Post Helpful? 0
  • +
  • -

#32 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6383
  • View blog
  • Posts: 25,781
  • Joined: 12-December 12

Re: Newbie has rough time with ready to use code

Posted 24 October 2017 - 11:39 AM

Quote

I have no intention of using names such as int32Var. It was the begining, I needed a general purpose int32 variable therefore int32Var did the job.

I would have removed ALL meaning and called it x or foo.

But there is rarely a reason to do this except for the tiniest snippet of code. I cannot really tell but it seems to be a frequency?! So I would have called it frequency.

(Rhetorical question: if no tutorials have mentioned goto then how did you materialise it.)

(I shall give up on the Ip, IP revelation ;) )
Was This Post Helpful? 0
  • +
  • -

#33 Archangelos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 17

Re: Newbie has rough time with ready to use code

Posted 24 October 2017 - 12:10 PM

View Postandrewsw, on 24 October 2017 - 09:39 PM, said:

Quote

I have no intention of using names such as int32Var. It was the begining, I needed a general purpose int32 variable therefore int32Var did the job.

I would have removed ALL meaning and called it x or foo.

But there is rarely a reason to do this except for the tiniest snippet of code. I cannot really tell but it seems to be a frequency?! So I would have called it frequency.
I changed it, the int32Var to another name.

View Postandrewsw, on 24 October 2017 - 09:39 PM, said:

(Rhetorical question: if no tutorials have mentioned goto then how did you materialise it.)
I had the goto thing in my mind, I knew that such a concept existed, I googled it and I found out that goto exists also in C#. After being commented, I changed the code and abolished the goto.

View Postandrewsw, on 24 October 2017 - 09:39 PM, said:

(I shall give up on the Ip, IP revelation ;)/>/>/> )
You mean to split the single statement to two. I will do it.




NO GOTO ALLOWED
I took your comments under consideration. In the begining I thought that I would need one goto statement. Finally, I managed to do it with no goto at all.

        static void Main(string[] args)
        {
            Console.Title = "MRD4400 remote control via SNMP";
            Console.ForegroundColor = ConsoleColor.Green;

            //Declare variables
            Char CommandSelection;
            Char[] caQuit = { 'Q', 'q'};//Char array containing Quit characters
            Char[] caLNB = { 'L', 'l' };//Char array containing LNB frequency characters
            Char[] caSat = { 'S', 's' };//Char array containing Sat frequency characters
            bool TimeToLeave = false;

            //Initialise SNMP
            UdpTarget MRD4400IP = new UdpTarget((IPAddress)new IpAddress("192.168.192.21"));
            Pdu pduMRD4400 = new Pdu(PduType.Set);
            // So far not neede in Main SnmpV2Packet response;
            AgentParameters MRD4400param = new AgentParameters(SnmpVersion.Ver2, new OctetString("private"));


            //Here starts the application
            while (TimeToLeave == false)
            {
                Console.Clear();
                Console.WriteLine("Choose CommandSelection.");
                Console.WriteLine("Press L for LNB frequency");
                Console.WriteLine("Press S for Satellite frequency");
                Console.WriteLine("Press Q to exit");
                Console.WriteLine("");
                CommandSelection = Console.ReadKey(true).KeyChar;

                if (Array.IndexOf(caQuit, CommandSelection)>-1)//If pressed key is either 'Q' or 'q'
                {
                    TimeToLeave = true;//then it's time to leave so the TimeToLeave flag has to change to true
                }

                if (Array.IndexOf(caLNB, CommandSelection) > -1)//If pressed key is either 'L' or 'l'
                {
                    Program.SetFrequency("LNB", ".1.3.6.1.4.1.9986.3.19.1.2.27.1.4.1.8.2.1", pduMRD4400, MRD4400param, MRD4400IP);//then we should set the LNB frequency
                }

                if (Array.IndexOf(caSat, CommandSelection) > -1)//If pressed key is either 'S' or 's'
                {
                    Program.SetFrequency("Satellite", ".1.3.6.1.4.1.9986.3.19.1.2.27.1.3.1.8.2.1", pduMRD4400, MRD4400param, MRD4400IP);//then we should set the Satellite frequency
                }

            }

        }

        public static void SetFrequency(string FreqParam, string FreqOID, Pdu pduThing, AgentParameters AgentParametersThing, UdpTarget UdpTargetThing)
        {
            string ConsoleInput;
            Int32 int32Frequency;
            bool InputIsInt32;
            SnmpV2Packet SnmpV2PacketThing;

            do
            {
                Console.WriteLine("");
                Console.WriteLine("Give {0} frequency in MHz (just numbers, no comma or dot).", FreqParam);
                ConsoleInput = Console.ReadLine();
                InputIsInt32 = int.TryParse(ConsoleInput, out int32Frequency);
            } while (InputIsInt32 == false);
            int32Frequency = Convert.ToInt32(ConsoleInput);
            Console.WriteLine("The {1} frequency is: ,{0} MHz", int32Frequency, FreqParam);
            pduThing.Reset();
            pduThing.VbList.Add(new Oid(FreqOID), new Integer32(int32Frequency * 1000));
            SnmpV2PacketThing  = UdpTargetThing.Request(pduThing, AgentParametersThing) as SnmpV2Packet;
            Console.WriteLine("Press any key to continue ...");
            Console.ReadKey(true);

        }








Your comments please.
Was This Post Helpful? 0
  • +
  • -

#34 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6383
  • View blog
  • Posts: 25,781
  • Joined: 12-December 12

Re: Newbie has rough time with ready to use code

Posted 24 October 2017 - 12:23 PM

Quote

You mean to split the single statement to two. I will do it.

No. I only split the declaration of a variable and its assignment to two statements temporarily to explain what was going on. Never mind ;)

int32Frequency??!! Whence did you discover this extended form of Hungarian notation.
Was This Post Helpful? 0
  • +
  • -

#35 Archangelos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 17

Re: Newbie has rough time with ready to use code

Posted 25 October 2017 - 07:14 AM

View Postandrewsw, on 24 October 2017 - 10:23 PM, said:

int32Frequency??!! Whence did you discover this extended form of Hungarian notation.
Well, I took the habit from a tutorial (I cant't recall which) that spoke of forms (VB, Access, I can't recall) where the forms had a name of the form frmXXXX, the buttons had a name of the form btXXXX etc.
In case of int32Frequency the name itself contain the data type information.

However, is this the only comment you had about my code?

Regarding the last code I uploaded, I created an extra method (line #50) named SetFrequency. The SetFrequency method could not access the variables of the main method (lines #14, #15, #17) and the only solution I found (after a short google search) was to pass them as input to SetFrequnecy method.
Is any way to let the SetFrequency method access the variables of main?
Was This Post Helpful? 0
  • +
  • -

#36 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: Newbie has rough time with ready to use code

Posted 25 October 2017 - 12:45 PM

VB was having aspirations of being like the cool Windows C/C++ guys, so it also adopted the Hungarian notation that the C/C++ guys were using. Of course, it is more or less pointless in VB because of its type system.

Anyway, modern C#'s naming convention recommends not using Hungarian.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3