• 0

VB Noob - Curious About Commands


Question

I am an absolute noob to VB. I'm kind of crashing myself into it because of my situation. I fell in on a network that was already in place. The guys here before me wrote some scripts in VB that automatically map network printers, shared folders, etc. The only problem is that they've been around for about 5 years and gone through two or three groups and have become quite bloated, and buggy. One thing they do is redirect everyone's home directory to our server. So, seeing as I don't know enough about VB to modify the ones in existence (comfortably anyway) I'm writing a brand new one. I've never written VB before, so I'd like you to look over the code I've written so far and tell me if it would work. I've written it only to do the two tasks I want it to do, map network drives and printers.

Also I was wondering what the "Dim" before variables does? I've seen it in example scripts that I googled, and the scripts that are in existence.

Attached is a .txt version of what I've got written so far.

mapresources.txt

Link to comment
https://www.neowin.net/forum/topic/704818-vb-noob-curious-about-commands/
Share on other sites

11 answers to this question

Recommended Posts

  • 0
... I was wondering what the "Dim" before variables does? .

It declares the name of the variable, ie it says "I';m going to use the name "Network" for my variable - without it the compiler wouldn't know if you mis-typed the name later, it would just have to assume it was a new variable. In most other languages there is something equivalent, but it usually defines what sort of variable it is (number, string etc) as well.

  • 0

Without "Dim" I don't even think the compiler would realise it is a variable would it? It would just give an error I think? It's been a whole year since I last did VB, but I can tell you that "Dim" before a variable name just declares that it is a variable (like JamesCherrill said) :)

  • 0

Ah, blessed VB syntax, well, VBScript syntax anyway.

I'm not gonna rehash what others have said, I'd simple say the script looks fine, but I would include some error checking if operations fail.

I've always been confused over the origin of Dim. I believe its short for Dimension (as in allocating a dimension of memory for the object). Others have said it means "Declared-in-Memory". Confuzzles me!

  • 0
I've always been confused over the origin of Dim. I believe its short for Dimension (as in allocating a dimension of memory for the object). Others have said it means "Declared-in-Memory". Confuzzles me!

"Dimension" is what one of the examples in the QuickBASIC 4.5 help file says. In one of the examples that the help file gives, it has a comment that says "Dimension an array to hold the values." That's why I've always thought it meant "Dimension". "Declared-In-Memory" is a new one to me. ^_^

No, I don't use it anymore. I think I just keep it around for nostalgia. The days of a blue screen that didn't mean something was wrong with your computer were nice. :D

  • 0

I think it's "Dimension" based on the original usage which was to specify the dimensions of an array, eg

dim months(12), chessboard(8,8)

some of the early Basics I've used didn't need variables to be Dim'ed unless they were arrays, which led to horrendous debugging problems when you mis-spelled a variable name.

  • 0
I think it's "Dimension" based on the original usage which was to specify the dimensions of an array, eg

dim months(12), chessboard(8,8)

It is "Dimension". Even if it wasn't an array, it still used an array of bytes for storage...

some of the early Basics I've used didn't need variables to be Dim'ed unless they were arrays, which led to horrendous debugging problems when you mis-spelled a variable name.

Urgh. Nasty version of BASIC you had there. All the ones I've used (since 1979) have required Dim to declare variables, even the quite horrible Sharp BASIC running on a MZ-80K. One notable exception ISTR is ZX81 BASIC which had Let as well. I can't remember if BBC BASIC had that as well. I wouldn't be surprised...

  • 0

Alright, the script is operational, however something is wrong with some of the computers and when trying to connect to the shared printers they fail 9 times out of 10, and I have to manually restart the "Print Spooler" service. I want to add a line to the end of the script to tell it to start that service just in case this happens. What commands could I use in VBScript to do this? Can I insert normal CLI commands into a VBScript?

P.S. What are some good VBScript tutorials that I could use? I'm looking for free online books, online tutorials, etc.. Something along the lines of VBScript for dummies that could take someone who doesn't know anything about it and make them somewhat comfortable.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft fixes one of Excel Copilot's most frustrating limitations by Usama Jawad Microsoft began integrating Copilot into Excel a couple of years ago and has been upgrading it with new functionalities since then. While some changes have been controversial, Microsoft is hoping to win over users by allowing them to be more productive via Copilot. To that end, it has now announced a Copilot improvement that may actually be appreciated by people who use it regularly. Excel customers often use the Copilot prompt box to issue instructions to format and customize their data, but it can become quite tiring to keep repeating the same instructions again and again. Microsoft now allows you to define Copilot personalization rules for formatting, naming conventions, formulas, and report styles. These can be accessed via Settings > Personalization, where you can explain your rules in natural language like "Always format currency in USD with no decimals", and just let Copilot take care of the rest. Microsoft is going a step further in this direction by allowing you to set workbook rules too. These rules are stored as a .Rules sheet, and are preserved while the workbook is shared. This fosters collaboration while making sure that standard rules govern the Copilot editing experience across the organization. Other advantages of this capability include pointing it to specific examples, defining dynamic formulas, and referencing an entire sheet and asking Copilot to infer rules based on that. You can leverage this feature by opening Copilot in Excel, clicking on "+", and selecting Create workbook rules. If you have an existing .Rules sheet, you can simply start listing the rules in column A as well. Personalization features are available to all Copilot in Excel users across the web, Mac, and Windows. Meanwhile, workbook rules are currently being previewed for Windows and Mac customers on the Insiders channel. General availability is scheduled after a few weeks, but a concrete date is currently unknown. Overall, the Excel capability is quite similar to ChatGPT's memory features, which allow you to permanently store items in the AI model's context window.
    • Imagine you still haven't discovered Total Commander that is doing all those things for three decades already...
    • This sounds like underneath the nice marketing spin, either someone at Adobe got tired of their lazy devs and asked Microsoft to help them sort at least some of Adobe's ancestral spaghetti code to make it go faster, or Microsoft wanted Adobe's crap to run better on Windows to make it look better when compared to Apple, so they offered to intervene. Either way, GOOD.
    • My favorite file manager for Windows 11 finally gets a long-requested feature by Taras Buria Files is among the best File Explorer alternatives for Windows 10 and 11. This free app is packed with all sorts of features and conveniences, but there is one crucial feature that is still missing—Tree View. Fortunately, the latest update in the Preview channel finally delivers it. With version 4.1.4, which is now available for download in the Preview channel, developers implemented Tree View, a new mode that displays folders in an expandable hierarchy. Windows 11's stock File Explorer always had this feature, but it was nowhere to be found in Files until now. Starting with the latest preview update, you can expand each drive and its nested folders without leaving the current location and then open the folder you need in the main view. To try Tree View in Files, update the app to the latest preview version, then click the small arrow next to a drive to expand its content. The developers say they are rolling out Tree View in Preview first to gather feedback from users and improve the feature before bringing it to all in the stable channel. In addition to Tree View, Files 4.1.14 improves the Windows Fonts folder. You can now preview each font directly in Files with no need to open the built-in font viewer. For now, these two features are only available in the Preview channel. For those using the stable release, developers recently released version 4.1.3, with improvements for the built-in tag system, on-demand folder size calculation, and plenty of various fixes. You can check out the full release notes here. You can download Files from the Microsoft Store (paid version) or its official website (free).
    • Who is paying for this 30x scale-up? Its sounds expensive.
  • Recent Achievements

    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
    • Week One Done
      Prasann earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      519
    2. 2
      +Edouard
      174
    3. 3
      PsYcHoKiLLa
      90
    4. 4
      Steven P.
      81
    5. 5
      ATLien_0
      68
  • Tell a friend

    Love Neowin? Tell a friend!