Visual Basic question

Anything not relating to the X-Universe games (general tech talk, other games...) belongs here. Please read the rules before posting.

Moderator: Moderators for English X Forum

Post Reply
Ezarkal
Posts: 1610
Joined: Wed, 22. Apr 15, 02:27
x4

Visual Basic question

Post by Ezarkal » Thu, 22. Mar 18, 14:13

Hi there, you wonderful people. How are you today?
Are there any Visual Basics masters among you? If so, I’m in need of help with something.

I’m in Excel 2013, and I’m trying to write a macro that will switch to another program (a printer manager… let’s call it “printer” to keep things simple), whether this program is opened or not.
The thing is, while I’m already familiar with the “AppActivate” function and with the “Shell” function, I pretty much need a combination of both.

Code: Select all

AppActivate “printer” 
This will only switch to the program if it is already running. It will give me an error message if it is not.

Code: Select all

Program = "C:\directory\printer.exe"
TaskID = Shell(Program, 1) 
This one will open a new instance of the program, even if one is already running. I would like to avoid running multiple instances of the program.


So basically, I would like to have a macro that would switch the printer manager if it is already running, but that would open it if (and only if) it is not running, instead of giving me an error message…

… and this is pretty much where I’m stuck. Any help would be greatly appreciated.
Humans are deuterostomes, which means that when they develop in the womb the first opening they develop is the anus.
This means that at one point you were nothing but an asshole.

Some people never develop beyond this stage.

korio
Moderator (Español)
Moderator (Español)
Posts: 891
Joined: Sat, 29. Sep 07, 18:25
x4

Post by korio » Thu, 22. Mar 18, 14:39

Would it not be easier if you just catch the error and in case of error execute the open?

Or event better, you can check if the program is previously running and act in consecuence, check if this little function helps

Code: Select all

Function IsProcessRunning(process As String)
    Dim objList As Object

    Set objList = GetObject("winmgmts:") _
        .ExecQuery("select * from win32_process where name='" & process & "'")

    If objList.Count > 0 Then
        IsProcessRunning = True
    Else
        IsProcessRunning = False
    End If

End Function

Rug
Posts: 1791
Joined: Fri, 21. Nov 03, 14:14
x4

Post by Rug » Thu, 22. Mar 18, 14:43

I don't really know VB, but ... I used my google fu and found the following which I think is what you are after !

Linky to forum thread

Rug

Edit : Or what Korio said :)
I like to think everyone just wants to feel human.

(Antilogic)

Ezarkal
Posts: 1610
Joined: Wed, 22. Apr 15, 02:27
x4

Post by Ezarkal » Thu, 22. Mar 18, 15:15

Many thanks for the pointers and the google-fu (my own google-fu failed me on this topic).

I now have something to start with.

I'll try to decipher all of this later today when I have a moment, and try to make something out of it. I'll let you know how it goes. :thumb_up:
Humans are deuterostomes, which means that when they develop in the womb the first opening they develop is the anus.
This means that at one point you were nothing but an asshole.

Some people never develop beyond this stage.

korio
Moderator (Español)
Moderator (Español)
Posts: 891
Joined: Sat, 29. Sep 07, 18:25
x4

Post by korio » Thu, 22. Mar 18, 16:15

Ezarkal wrote:Many thanks for the pointers and the google-fu (my own google-fu failed me on this topic).

I now have something to start with.

I'll try to decipher all of this later today when I have a moment, and try to make something out of it. I'll let you know how it goes. :thumb_up:

A little advice, if you let me.

Run from anything programmed in the office apps, people like to use excel and access for everything and is a pain in the a**

I have to agree that is "friendly" and "easy" to do anything, but its a pain to upgrade, change and maintain it, and also there is the cost of licenses attached to it.

Where i work they where using access to print zebra labels (barcodes) from a couple computers, i did a little program to gather all the label types they use in the wharehouse, its ugly but effective, as simple as one click and a couple fields to input data, its on all computers of the wharehouse, no need for office licenses and it takes me 10 minutes to add a new label, compile it and distribute to all the warehouse computers.

You cant imagine how many headaches i have caused by Excel and 7+ years old programmed macros and such.

User avatar
Antilogic
Posts: 7526
Joined: Wed, 6. Apr 05, 20:33
x3tc

Post by Antilogic » Thu, 22. Mar 18, 16:30

korio wrote:
A little advice, if you let me.

Run from anything programmed in the office apps, people like to use excel and access for everything and is a pain in the a**

I have to agree that is "friendly" and "easy" to do anything, but its a pain to upgrade, change and maintain it, and also there is the cost of licenses attached to it.

Where i work they where using access to print zebra labels (barcodes) from a couple computers, i did a little program to gather all the label types they use in the wharehouse, its ugly but effective, as simple as one click and a couple fields to input data, its on all computers of the wharehouse, no need for office licenses and it takes me 10 minutes to add a new label, compile it and distribute to all the warehouse computers.

You cant imagine how many headaches i have caused by Excel and 7+ years old programmed macros and such.
Dear god yes all of this.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Post by Morkonan » Thu, 22. Mar 18, 20:01

Antilogic wrote:Dear god yes all of this.
Bbbut... it makes us non-programmers feel POWERFUL!

"Look what I built in Access! I can gather all these databases together and then update them and make changes on the fly with drop-down commands and can print over here whenever I want and import new items here and..."

"WHO TEH @$^% JUST OVERWROTE THE ENTIRE INVENTORY DATABASE?"

"Uh... "

As a non-programmer, Acess/Excel, Office in general, helped me do things that I simply couldn't have done, otherwise. Sure, a programmer could have written code to do those things, but having the power to do them myself was critical in a lot of situations. In some offices, there just aren't any coders... Yes, I know, unimaginable, right? :)

PS - We used to use an inventory management program that would print out any barcade base we wanted using built-in features. It saved a bunch of work. Of course, that was juse for internal stuffs or when a customer called for it for tracking purposes or labeling requirements.

User avatar
Antilogic
Posts: 7526
Joined: Wed, 6. Apr 05, 20:33
x3tc

Post by Antilogic » Thu, 22. Mar 18, 20:13

As a non-programmer, Acess/Excel, Office in general, helped me do things that I simply couldn't have done, otherwise. Sure, a programmer could have written code to do those things, but having the power to do them myself was critical in a lot of situations. In some offices, there just aren't any coders... Yes, I know, unimaginable, right? Smile
That's fair. It's when that small office gets a bit bigger and hires sysadmins who write powershell and also have to comply with security relegation's that then have to untangle the 300 mini-excel macros that have been written over the last 15 years....

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Post by Morkonan » Thu, 22. Mar 18, 20:33

Antilogic wrote:That's fair. It's when that small office gets a bit bigger and hires sysadmins who write powershell and also have to comply with security relegation's that then have to untangle the 300 mini-excel macros that have been written over the last 15 years....
Lol! Yes, there is that - Legacy apps are much-beloved in offices all over the world, likely to many an IT pro's constant annoyance. That's a common complaint in practical IT environments.

Back in the "Wild West" days of teh interwebz, most regulatory requirements that we had to deal with centered around personal information concerning customer information and transactions, largely a matter of any credit-card processing and the like we had to do. (Government purchasing used special credit cards, back then.) Most of this originated with the big card companies, protecting their own label. (MasterCard, Visa, AmEx, Discover, etc.)

After 9/11 and the formation of the Department of Homeland Security, we came under "Critical Infrastructure" guidelines. This brought a whole new level of compliance crap that reached deep into the Operations environment, not just "what's connected to the internetz." Thankfully, we were able to escape most of those, but we still had to report, stay current, stay on the list, blah, blah, blah. Most of our other compliance issues came from other agency requirements that were already in place.

I guess the point is that these tools, though universally complained about by "real IT professionals" give a level of functionality to their users that can't be met, otherwise, in their current environments. As a business/office grows and can afford to hire such professionals, those poor IT guys have to figure out how to integrate those things or, worse, how to weed them out. :)

I guess part of the reason for my participation in this thread is that, as a non-IT'er, I really enjoyed the functionality and power that Office brought to me in a functioning, complex, work environment that often forced me to come up with "innovative" solutions around problems that would have otherwise been handled by an IT department, which we didn't have. I don't know of any non-IT professional who, forced by necessity, was not personally proud of their ability to create their own creative, working, solution to a problem using the tools that Office provided.

Even back in the day, before some of my friends became IT professionals, they were proud of what they managed to build using the Office environment. It was, and I imagine it still is, a topic of conversation from time to time.

It's like an Acolyte entering the inner mysteries of the Holy Sanctum, though. The mere Acolyte is awed by the revelation and newfound knowledge, but it pisses off the true Priests. :)

User avatar
Tamina
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 4543
Joined: Sun, 26. Jan 14, 09:56

Post by Tamina » Fri, 23. Mar 18, 09:36

It would be so much better if Microsoft just supported Python or even their own language C#.

Code: Select all

Und wenn ein Forenbösewicht, was Ungezogenes spricht, dann hol' ich meinen Kaktus und der sticht sticht sticht.
  /l、 
゙(゚、 。 7 
 l、゙ ~ヽ   / 
 じしf_, )ノ 

CBJ
EGOSOFT
EGOSOFT
Posts: 51740
Joined: Tue, 29. Apr 03, 00:56
x4

Post by CBJ » Fri, 23. Mar 18, 10:16

No, no it wouldn't. That would just mean more, and more powerful, code hidden away in spreadsheets for people to untangle. VB is actually about the right tool for writing little tools in Excel. It's just that Excel is not always the right toolbox for those little tools to live in when they get bigger.

korio
Moderator (Español)
Moderator (Español)
Posts: 891
Joined: Sat, 29. Sep 07, 18:25
x4

Post by korio » Fri, 23. Mar 18, 10:56

CBJ wrote:No, no it wouldn't. That would just mean more, and more powerful, code hidden away in spreadsheets for people to untangle. VB is actually about the right tool for writing little tools in Excel. It's just that Excel is not always the right toolbox for those little tools to live in when they get bigger.
That exactly, a user with no knowledge of programming, or very little, that crafts by itself a little tool or macro to help in his daily work, its totally fine.

The problem is when you reach a level that everything is done in excel-access, here all reports of sell-in, sell-out, stocks, kpis, everything you can imagine a retail company works with, its done in excel, it has been this way for 10+ years, and only the person who did it, knows how to manipulate it, and believe me, i have seen the code, and its totally impossible to understand it without spending a couple months for each excel workbook.

Imagine how big the pile of crap is, that this person is like 7 years away from retiring, and i just hope i can found a better job so im not here when this person leave the company and that pile of crap goes over my shoulders.

User avatar
Tamina
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 4543
Joined: Sun, 26. Jan 14, 09:56

Post by Tamina » Fri, 23. Mar 18, 11:16

I don't understand the argument. Using a faster to develop, execute and more readable language is bad because that would tempt people to write bigger applications, which is bad?

Due to the protectionism policy of Microsoft, it is difficult to use Office products outside of Microsofts environment. Therefore it seems natural to bind data-processors into this environment as well, and VBA is a horrible language for... anything.
Using another language would be one of the bigger out of many necessary steps to improve that.

Code: Select all

Und wenn ein Forenbösewicht, was Ungezogenes spricht, dann hol' ich meinen Kaktus und der sticht sticht sticht.
  /l、 
゙(゚、 。 7 
 l、゙ ~ヽ   / 
 じしf_, )ノ 

User avatar
Antilogic
Posts: 7526
Joined: Wed, 6. Apr 05, 20:33
x3tc

Post by Antilogic » Fri, 23. Mar 18, 11:28

The idea is that if you need to write bigger applications, you just straight up stop building it into Excel.

CBJ
EGOSOFT
EGOSOFT
Posts: 51740
Joined: Tue, 29. Apr 03, 00:56
x4

Post by CBJ » Fri, 23. Mar 18, 12:11

Tamina wrote:Using another language would be one of the bigger out of many necessary steps to improve that.
No. The language isn't the problem. The problem is the environment. Single-user documents and local databases are not the place for important business processes.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Post by Morkonan » Fri, 23. Mar 18, 16:25

Another observation from a mind uninitiated in some things "I.T."

"I want it to do x. Make it do!"

From IT friends, I hear this phrase a lot when it comes down to trying to service their customer/department/organization. They have a sit-down with the person and look at their request. Inevitably, the person or group or board say's "Make it do."

Sometimes, I bet some non-IT people with access to critical data that they want to "make it do" end up trying to "make it do" themselves... And, when the IT department says "It can't do that" they point at their lovingly crafted, but an offense to nature, Excel or Access sheet, grunt, and nudge the screen with the backs of their hairy hands, saying "Ook! I MAKE DO! YOU MAKE DO!"

Then, the IT guys are forced to try to make them understand that they're not supposed to do that... That, in some real universe, what they have done is a mortal sin. That, somewhere, there is a Natural Law that says "Thou Shall Not Make Do What Thou Hast Done!"

Yet, still, the brow furrows, the lips purse, and out comes "Make do."

korio
Moderator (Español)
Moderator (Español)
Posts: 891
Joined: Sat, 29. Sep 07, 18:25
x4

Post by korio » Sat, 24. Mar 18, 11:53

It's pretty common.

What people sometimes dont understand is that there is a whole world behind what they are doing, and most of the times, when IT says it cant be done, its more, it cant be done safely, or it cant be done because its not worth to develop what is requested with the estimated time it takes to do it.

When you have been working on this for a little time, you start to understand that its better for you and for everyone to not explain why it cant be done, it cant be done, period. This way you avoid a lot of problems trying to explain to someone that most of the times is totally ignorant to computer stuff behind what he does at his home why you dont want to do it and why.

As my boss says, people want answers, not explanations.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Post by Morkonan » Sat, 24. Mar 18, 18:38

korio wrote:...When you have been working on this for a little time, you start to understand that its better for you and for everyone to not explain why it cant be done, it cant be done, period. ...As my boss says, people want answers, not explanations.
^--- This.

Some people have just enough knowledge to know that something can be done, but they don't have enough knowledge to understand why it shouldn't be done.

It's better just to say "No."

User avatar
Tamina
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 4543
Joined: Sun, 26. Jan 14, 09:56

Post by Tamina » Sat, 24. Mar 18, 20:12

CBJ wrote:
Tamina wrote:Using another language would be one of the bigger out of many necessary steps to improve that.
No. The language isn't the problem. The problem is the environment. Single-user documents and local databases are not the place for important business processes.
We obviously see this problem from two different perspectives. You are a developer at a small company, I am an engineer at a world market leader.

Most companies don't allow access to programming tools or getting them is a monthly long bureaucracy act - speaking from lots of experience here. From an (elitist) IT standpoint, people are idiots and must be protected from themselfes by limitting them as much as possible. Something you never experience as a developer at a small dev-company.

Without a proper devkit, people then start using Macros to automate data-processing as their only option and eventually expand on that. Instead of limiting or removing that option it should be made better with a proper language; proper APIs; and an office-integrated, excel-independent development environment and programs.
Or in other words: Together with office, a (i.e. Python) IDE with official Office APIs should be delivered.

No matter how horrible you make Macros to use. If people can automate processing thousands of entries rather than doing by hand, they will.

Code: Select all

Und wenn ein Forenbösewicht, was Ungezogenes spricht, dann hol' ich meinen Kaktus und der sticht sticht sticht.
  /l、 
゙(゚、 。 7 
 l、゙ ~ヽ   / 
 じしf_, )ノ 

Post Reply

Return to “Off Topic English”