Page 1 of 1 1
Topic Options
#121068 - 2004-06-11 01:30 AM Using ReadValue
BNutz Offline
Fresh Scripter

Registered: 2001-04-19
Posts: 12
Loc: Washington D.C. USA
I think this is a simple question for someone. I am reading the default printer from my registry. I want to make a script that takes this value and turns it into an LPT1 printer. Don't ask, at work using an inhouse app that needs LPT1 mapped (poorly written app). My script is just two lines and will work, but the data in the string has too much info. I need to just grab data up to the comma. The lenghts of the data very so I can't count characters and chop.

Here is what the Default Printer data looks like in the registry: (I need whats in RED only, stopping at the first comma)

\\PrintServer\PrinterName,winspool,Ne01:

Code:
  
$defprinter = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device")

USE LPT1: \\$defprinter



Any ideas?

BNutz

Top
#121069 - 2004-06-11 01:47 AM Re: Using ReadValue
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Check out Split() in the manual. Just the thing you need.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#121070 - 2004-06-11 01:50 AM Re: Using ReadValue
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or just:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=117544&page=34&view=collapsed&sb=3&o=all&fpart=1
_________________________
!

download KiXnet

Top
#121071 - 2004-06-11 02:17 AM Re: Using ReadValue
BNutz Offline
Fresh Scripter

Registered: 2001-04-19
Posts: 12
Loc: Washington D.C. USA
What am I doing wrong? (using 4.21) This seems to just skip right over the "Function" and doesn't do anything. I was doing step by step in debug mode.

Code:

function GetDefaultPrinter()
$GetDefaultPrinter = join(split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction

? $GetDefaultPrinter

USE LPT1: \\$GetDefaultPrinter



BNutz

Top
#121072 - 2004-06-11 02:30 AM Re: Using ReadValue
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yup, Function-Endfunction is a keyword pare that define user defined function.
they work just like inbuild functions of kixtart but they are custom build.

so, to correct your code:
Code:

function GetDefaultPrinter()
$GetDefaultPrinter = join(split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction
? GetDefaultPrinter()
USE LPT1: GetDefaultPrinter()



in another words, it defines a function/keyword.
once you have added that code in your script, you can use it anywhere you like in your script and the same rules apply as for any other function that are in the manual.
_________________________
!

download KiXnet

Top
#121073 - 2004-06-11 02:38 AM Re: Using ReadValue
BNutz Offline
Fresh Scripter

Registered: 2001-04-19
Posts: 12
Loc: Washington D.C. USA
That works! Thanks a million. 'Function' can come in handy, I'll read up on it.

BNutz

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.114 seconds in which 0.079 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org