<variable> = me.<nameoftextbox>.text
Sure this will be possible, I've had a search on the web, but as it's a bit difficult to explain I'm struggling to find an answer:
I'm attempting to make a small tool (to use on multiple sites), that basically automates the jobs we'd usually run batch files and vb scrips for at the click of a button.
Currently, I'm looking at adding the printers.
Basically, when the "Add" button is clicked in the first image, the code from "Set printers" in the second image is run, but I want "SERVERNAME" and "PRINTERNAME" to be replaced by what is typed by the user in the retrospective text fields above.
Is this possible, and if so how? I image its just a "ValueOfTextbox1\ValueOfTextbox2" type thing?
Thanks in advance for any help
edit - excuse the disgraceful design, this is just thrown together to show what I mean.
Last edited by gtg93; 25th June 2014 at 02:12 PM.
<variable> = me.<nameoftextbox>.text
Sorry to elaborate:
In this case I would do the following...
HTHCode:Dim SERVERNAME as string = me.textbox1.text Dim PRINTERNAME as string = me.textbox2.text .... objNetwork.AddWindowsPrinterConnection("\\" & SERVERNAME & "\" & PRINTERNAME & ")
Thanks! - I should have thought of that, I've done that recently but still quite new to it...
I'm now getting this error, but can't seem to find an issue with my code. Nothing is showing in the "Error List" - I've read the linked articles but can't seem to relate the issues to my project.
Move the DIMs in to the button click event code
That's done the job, thanks... I thought setting it at the top would make it available to the whole code for the remove and default option I'm also going to add.
Will the DIMs need adding to these buttons seperately too? Will they need a different name, for example:
Dim SERVERNAME as string = me.textbox1.text
Dim PRINTERNAME as string = me.textbox2.text
Dim SERVERNAME2 as string = me.textbox1.text
Dim PRINTERNAME2 as string = me.textbox2.text
Dim SERVERNAME3 as string = me.textbox1.text
Dim PRINTERNAME3 as string = me.textbox2.text
Sorry for the million questions, just trying to get my head around it.
Last edited by gtg93; 25th June 2014 at 03:35 PM.
Yes they will need to be added but no you won't need separate names as the variables are local to the handlers and are not seen outside them. The better - code reuse - way would be to have a subroutine that you run from the handlers. This would be passed a variable like add/remove/default then the one bit of code could use a case statement to pick which actions to perform from the variable
then PrinterAction(1) or whatever from the button clickCode:psudocode: private sub PrinterAction (Action as integer) Dim SERVERNAME as string = me.textbox1.text Dim PRINTERNAME as string = me.textbox2.text 'run checks on the two variables and Action to make sure they are not null or have invalid characters, maybe even ping the servername 'Dim objNetwork 'you'll need it whatever statement is run objNetwork = create... Select Case Action Case 1 objNetwork.add... msgbox Case 2 'delete printer objNetwork.del... msgbox Case 3 'default Case Else 'something has gone wrong End Select end sub
personally I'd pass the two textbox values directly in the routine to make it more reusable so Printeraction(1,TB1.value,TB2.value) with
private sub PrinterAction (Action as integer, PrinterName as String, ServerName as String)
and ditch the extra lines which are only a little useful for debugging.
But that's probably enough to make your head spin for now
Last edited by SYNACK; 25th June 2014 at 03:55 PM.
If you want to set it at the top you can but you need to change the code slightly
This will set those variables when the application is launched - you can then reference them in your functions later onCode:Private SERVERNAME as string = nothing Private PRINTERNAME as string = nothing
Once you have assigned a variable to the declaration you can reuse it so doing it on the add button may not be the best place if you intend using it (and add is not the first button called)Code:SERVERNAME = me.textbox1.text PRINTERNAME = me.textbox2.text 'do something
You may want to look at updating the variable on LostFocus (an event that will run when the control loses focus)
To try and eliminate user input error and as you will know what printers are on what servers etc - surely it would be better to use drop down boxes to select which printer they want to add and from there you could add the relevant printer ( should know which printer is on which server so they shouldn't need to type the server name etc ) ??
Drop down gets populated with all the printers in that department or all the possible printers they can add and they click on the add button which then adds the printer they had or have selected from said drop down menu ?
Last edited by mac_shinobi; 25th June 2014 at 03:58 PM.
I'm trying to put a GUI to a number of scripts I'd use regularly for my own use across sites... Still learning VB, so creating little things like this to pick up the basics.
Plus some staff might be working on their laptop somewhere else in school for a day (working in a high school mainly), so we give them the above GUI to add the closest printer whilst they are, then they can easily remove it. We monitor printing with PaperCut, so no ones bothered about sharing deparment printers with other staff.
Last edited by gtg93; 25th June 2014 at 04:04 PM.
mac_shinobi (25th June 2014)
gtg93 (26th June 2014)
There are currently 1 users browsing this thread. (0 members and 1 guests)