Announcement

Collapse
No announcement yet.

Visual Studio macros help?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Visual Studio macros help?

    I'm taking a shot in the dark here, but I figure maybe someone in this community has worked with VB macros in Visual Studio and can help me.

    I am working on a simple macro, but I've never worked with VB or the macro editor in any way besides the most basic changes to other people's macros.

    I have lots of long arrays in C++ code initialized like this
    a[0] = &blah1;
    a[1] = &blah7;
    a[2] = &blah13;
    ...
    a[49] = &blahblah985;

    And sometimes (like right now), I need to make a change to the list, where I insert or remove an element. When I do that, I need to renumber every element in the array after the point where I make the change. So I figured I would dig into the macro editing of VS and make a simple macro which would renumber my array.

    - select block of text
    - fire off renumber macro
    - hooray

    So... I need to find the identifier "a", then for every occurrence of a[n], I need to replace the existing n with the right value.

    Hm... I may have found my answer already, but if anyone here is a pro and wants to give me the easy solution, I'm listening. :D
    Peace through fear... since 1947!

  • #2
    Re: Visual Studio macros help?

    You could set up your array init to be like this:

    Code:
    a[] = {1,
    2,
    3,
    4,
    ...,
    n};

    - It's who you game with.

    Comment


    • #3
      Re: Visual Studio macros help?

      Originally posted by =Sarc= View Post
      You could set up your array init to be like this:
      True, if I weren't dealing with more than 10k lines of existing code. Many of the arrays are also overlapped because it makes the code easier to understand.

      Code:
      a[0] = &moo;
      a[1] = &bdefn;  //bdefn points to b[]
         b[0] = &tralala;
         b[1] = &omg;
         b[2] = NULL;
      a[2] = &fubar;
      a[3] = NULL;
      This is all really academic now (literally), since I am giving this job away to some lucky dude in China very soon. I just can't stop myself once I get it in my head that I want to solve a stupid little problem with a tool I don't know how to use. :)

      I have almost solved my problem except that my search for ^:b*{:i}\[:z\] isn't giving me the right results. (that's a line starting with 0 or more blanks, then an identifier, then [, then an integer, then ])

      gah... it's the weekend... I need to turn this off now...
      Peace through fear... since 1947!

      Comment


      • #4
        Re: Visual Studio macros help?

        I don't always try to do a search and replace with a single regex. I usually do several just because it's easier for me to understand and figure out. That might be easier instead of thinking of one regex to complete the entire job.

        - It's who you game with.

        Comment


        • #5
          Re: Visual Studio macros help?

          Originally posted by =Sarc= View Post
          I don't always try to do a search and replace with a single regex. I usually do several just because it's easier for me to understand and figure out. That might be easier instead of thinking of one regex to complete the entire job.
          Ya, but this is just one simple find. I just have problems because MS doesn't use the same regex syntax from one place to the next. I tested that string in the normal find/replace and it worked fine.
          Peace through fear... since 1947!

          Comment


          • #6
            Re: Visual Studio macros help?

            Can't help, but maybe you can find some help here

            Comment


            • #7
              Re: Visual Studio macros help?

              Originally posted by Iamthefallen View Post
              Can't help, but maybe you can find some help here
              Hey, that's cool! I wouldn't come to the TG forums for help if I was willing to HIRE someone though. When I find myself doing monkey work, I always take the opportunity to learn something new. So I'm trying to learn this crazy VB macro system in spite of the lousy documentation and lack of any real online expertise.

              I am very close. So close that I might break down and use some of my own time to get it. In a week, I might not be using Visual Studio anymore, but I will have that little bit of knowledge in my pocket to use next time.
              Peace through fear... since 1947!

              Comment


              • #8
                Re: Visual Studio macros help?

                Yeah I know the feeling, I spent most of my day trying to convince our DB server that CSV files really can have commas inside a quote-delimited field. There are lots of workarounds, but I wanted to make it work my way :-)

                VB macros is just one of those things I think goes against all that is right and good in the world.

                Comment


                • #9
                  Re: Visual Studio macros help?

                  If the regex system in Visual Studio is weird, you can always open the file in another editor that has regex that does make sense.

                  You could also try matching all characters up to an equal sign instead of specifically spaces, identifier, square brackets, etc.

                  - It's who you game with.

                  Comment


                  • #10
                    Re: Visual Studio macros help?

                    Use vi, heh. Recently read an article about it doing just what you need.

                    Comment


                    • #11
                      Re: Visual Studio macros help?

                      Ya, I figure it would take me about a few minutes to come up with a script in another language, but that's cheating. ;)

                      Cool vi stuff. I have used it for years but I still don't know half of the functionality. Too little room in my head.
                      Peace through fear... since 1947!

                      Comment


                      • #12
                        Re: Visual Studio macros help?

                        Originally posted by icky View Post
                        Ya, I figure it would take me about a few minutes to come up with a script in another language, but that's cheating. ;)

                        Cool vi stuff. I have used it for years but I still don't know half of the functionality. Too little room in my head.
                        If you can figure it out using another language or any other method, it's not cheating. It's getting the job done. Don't think you have to restrict yourself to certain tools just because you'll learn something. You'll learn something by using the right tools for the job.

                        - It's who you game with.

                        Comment


                        • #13
                          Re: Visual Studio macros help?

                          Originally posted by =Sarc= View Post
                          If you can figure it out using another language or any other method, it's not cheating. It's getting the job done. Don't think you have to restrict yourself to certain tools just because you'll learn something. You'll learn something by using the right tools for the job.
                          Nah, you aren't getting my way of thinking. If I let myself always use the easiest tool for ME, I wouldn't know half of what I know now. When the opportunity arises for me to expand my toolbox, I almost always do it.
                          Peace through fear... since 1947!

                          Comment


                          • #14
                            Re: Visual Studio macros help?

                            Originally posted by icky View Post
                            Nah, you aren't getting my way of thinking. If I let myself always use the easiest tool for ME, I wouldn't know half of what I know now. When the opportunity arises for me to expand my toolbox, I almost always do it.
                            Ah, you're also expanding your toolbox by learning how to identify the easiest tools for the task at hand. :p

                            Go for it with the vi editor. Unless... you've got too little room in your head right now. :D

                            - It's who you game with.

                            Comment


                            • #15
                              Re: Visual Studio macros help?

                              you could do something like
                              Code:
                              i=0;
                              a[i++] = &something;
                              a[i++] = &tra;
                               ib=0;
                               b[ib++] = &xxx
                               b[ib++] = null
                              etc.

                              Ideally you'd put the initialization data in an external config file.

                              Comment

                              Connect

                              Collapse

                              TeamSpeak 3 Server

                              Collapse

                              Advertisement

                              Collapse

                              Twitter Feed

                              Collapse

                              Working...
                              X